blockcore-indexer icon indicating copy to clipboard operation
blockcore-indexer copied to clipboard

Add support for OP_SPEND and OP_INTERNALCONTRACTTRANSFER

Open dangershony opened this issue 3 years ago • 2 comments

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 avatar Jan 25 '22 13:01 dangershony

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

dangershony avatar Feb 23 '22 20:02 dangershony

An example of the given opcodes can be found here https://explorer.blockcore.net/crs/explorer/transaction/5e1e2d4caacf979f88683de9776aabac5354a470faec19ecc4db5d73682b68d2 https://crs.indexer.blockcore.net/api/query/transaction/5e1e2d4caacf979f88683de9776aabac5354a470faec19ecc4db5d73682b68d2

dangershony avatar Mar 29 '22 14:03 dangershony