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

Update TranscationReceipt to include decoding of events #141

Merged
merged 6 commits into from
Jun 14, 2024

Conversation

peterbroadhurst
Copy link
Contributor

@peterbroadhurst peterbroadhurst commented Jun 10, 2024

See hyperledger/firefly-transaction-manager#123

Example usage to extract (only) ERC-20 / ERC-721 events from a transaction:

Example FFTM POST on /

Note the example here includes both ABI definitions, which actually have the same signature, but are incompatible due to one being indexed on the value and one not (great quirk of ERC-20/ERC-721 ABI event definitions 🫠 ). The code tries both, and finds the one that works.

{
    "headers": {
        "type": "TransactionReceipt"
    },
    "transactionHash": "0xba7cbb474a1c2c1c392ef612b20c8eff79d876f5b66a0d1a27178eb3ae262f84",
    "eventFilters": [
        {
            "event": {
                "anonymous": false,
                "inputs": [
                    {
                        "indexed": true,
                        "name": "from",
                        "type": "address"
                    },
                    {
                        "indexed": true,
                        "name": "to",
                        "type": "address"
                    },
                    {
                        "indexed": false,
                        "name": "value",
                        "type": "uint256"
                    }
                ],
                "name": "Transfer",
                "type": "event"
            }
        },
        {
            "event": {
                "anonymous": false,
                "inputs": [
                    {
                        "indexed": true,
                        "internalType": "address",
                        "name": "from",
                        "type": "address"
                    },
                    {
                        "indexed": true,
                        "internalType": "address",
                        "name": "to",
                        "type": "address"
                    },
                    {
                        "indexed": true,
                        "internalType": "uint256",
                        "name": "tokenId",
                        "type": "uint256"
                    }
                ],
                "name": "Transfer",
                "type": "event"
            }
        }
    ]
}

Example Response

{
    "blockNumber": "27",
    "transactionIndex": "0",
    "blockHash": "0x474497495a4657f2bb3bd998e7e0e22bc4e08e9d8f3da3405cd2be4ab9d66fa6",
    "success": true,
    "protocolId": "000000000027/000000",
    "extraInfo": {
        "contractAddress": null,
        "cumulativeGasUsed": "87154",
        "from": "0x4817ff50820c4f21cef657a00ac75033686b02c3",
        "to": "0x590a0fc9da219c67ff0818268c2e2d0d43a53637",
        "gasUsed": "87154",
        "status": "1",
        "errorMessage": null
    },
    "events": [
        {
            "address": "0x590a0fc9da219c67ff0818268c2e2d0d43a53637",
            "blockHash": "0x474497495a4657f2bb3bd998e7e0e22bc4e08e9d8f3da3405cd2be4ab9d66fa6",
            "blockNumber": "27",
            "data": {
                "from": "0x0000000000000000000000000000000000000000",
                "to": "0x4817ff50820c4f21cef657a00ac75033686b02c3",
                "tokenId": "22"
            },
            "inputSigner": "0x4817ff50820c4f21cef657a00ac75033686b02c3",
            "logIndex": "0",
            "removed": false,
            "signature": "Transfer(address,address,uint256)",
            "timestamp": "2024-06-11T14:23:06Z",
            "topics": [
                "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                "0x0000000000000000000000000000000000000000000000000000000000000000",
                "0x0000000000000000000000004817ff50820c4f21cef657a00ac75033686b02c3",
                "0x0000000000000000000000000000000000000000000000000000000000000016"
            ],
            "transactionHash": "0xba7cbb474a1c2c1c392ef612b20c8eff79d876f5b66a0d1a27178eb3ae262f84",
            "transactionIndex": "0"
        }
    ]
}

@peterbroadhurst peterbroadhurst marked this pull request as ready for review June 11, 2024 14:43
@peterbroadhurst peterbroadhurst requested a review from a team as a code owner June 11, 2024 14:43
@@ -86,7 +86,7 @@ func (c *ethConnector) getBlockInfoByNumber(ctx context.Context, blockNumber int

func (c *ethConnector) BlockInfoByNumber(ctx context.Context, req *ffcapi.BlockInfoByNumberRequest) (*ffcapi.BlockInfoByNumberResponse, ffcapi.ErrorReason, error) {

blockInfo, reason, err := c.getBlockInfoByNumber(ctx, req.BlockNumber.Int64(), true, req.ExpectedParentHash)
blockInfo, reason, err := c.getBlockInfoByNumber(ctx, req.BlockNumber.Int64(), req.AllowCache, req.ExpectedParentHash)
Copy link
Contributor Author

@peterbroadhurst peterbroadhurst Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFTM can now be explicit about this

@peterbroadhurst
Copy link
Contributor Author

Will hold of merging until I can refer to FFTM using a release

@Chengxuan Chengxuan merged commit 655c326 into main Jun 14, 2024
3 checks passed
@Chengxuan Chengxuan deleted the receipt-query branch June 14, 2024 16:42
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

Successfully merging this pull request may close these issues.

2 participants