Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OP_SPEND and OP_INTERNALCONTRACTTRANSFER #72

Open
dangershony opened this issue Jan 25, 2022 · 2 comments
Open

Add support for OP_SPEND and OP_INTERNALCONTRACTTRANSFER #72

dangershony opened this issue Jan 25, 2022 · 2 comments
Assignees

Comments

@dangershony
Copy link
Member

ah interesting, I could fetch the gas cost but I need to know where to look for it
In the deserialized create/call transaction params you can get the gas price and gas limit

Funds transferred to contract
It's the amount of the output with the OP_CREATE or OP_CALL opcode in the scriptpubkey

balance of the contract
The account state keeps track of current contract balances. There's an API call on the smart contracts controller that you can look at for an example. Each contract with a balance has a single unspent output stored in the account state. When a contract spends funds it uses a special opcode in the input scriptpubkey OP_SPEND.

Funds transferred from a contract
Contracts spending funds use an input with the scriptpubkey beginning with OP_SPEND (important to note: so do gas refunds)

Gas refunds
Input's scriptpubkey begins with OP_SPEND and they are all in the last transaction in the block (condensing transaction)

Funds transferred between contracts
Output's scriptpubkey begins with OP_INTERNALCONTRACTTRANSFER + the contract address who can spend the output.

@dangershony dangershony self-assigned this Jan 25, 2022
@dangershony
Copy link
Member Author

dangershony commented Feb 23, 2022

I will use this issue to dump valuable info on logs:

Quick rundown on logs:

  • A log contains 3 things, the address of the contract, the "topics" and the data. The receipts in a block are put into a merkle tree and its root forms part of consensus in the block header as the "receipt root"
  • All logs have fields, some are indexed and some are not.
  • The whole serialized log is the "data" field.
  • The fields marked with [Index] are "topics". Topics have their bytes added to a bloom filter, which is included in the block header as the "logs bloom". The first topic is always the contract address. The reason for having [Index] and using the bloom filter is that it is very fast to search through blocks for specific topics

how would I fetch this values form the State? For example the StandardToken constructor has no logs but I would like to get the values of params sent to it

To get the values of the params sent to the constructor, you'd need to look at the transaction that created the contract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant