sui icon indicating copy to clipboard operation
sui copied to clipboard

Event logging logic refactoring and new CoinBalanceChange and MutateObject events

Open patrickkuo opened this issue 3 years ago • 4 comments

Event logging refactoring

Changes

  • Moved all object level events logging into temporary_store, currently MoveEvent is the only non-object level event, it will continue to use the log_event method.
  • We are passing a SingleTXContext object when we write to the temporary_store, the context contain the call site info (package id, module, sender) and is being used to create object level events.
  • Added CoinBalanceChange event, this event is emitted for every coin balance changes (Gas, Pay, Receive)
  • Added MutateObject, this event is emitted if there are changes to the object's data
  • Explorer - added CoinBalanceChange and MutateObject view.
  • Rosetta - simplified coin balance change extraction logic

Examples

Pay transaction event response

        "events": [
                {
                    "coinBalanceChange": {
                        "package_id": "0x0000000000000000000000000000000000000002",
                        "transaction_module": "gas",
                        "sender": "0xd6fa49643e34b29308199a60994ca405da6dd668",
                        "change_type": "Gas",
                        "owner": {
                            "AddressOwner": "0xd6fa49643e34b29308199a60994ca405da6dd668"
                        },
                        "coin_type": "0x2::sui::SUI",
                        "coin_object_id": "0x5fe15b906a089e2a5efdc733b09ce26589ae9054",
                        "version": 0,
                        "amount": -96
                    }
                },
                {
                    "coinBalanceChange": {
                        "package_id": "0x0000000000000000000000000000000000000002",
                        "transaction_module": "pay",
                        "sender": "0xd6fa49643e34b29308199a60994ca405da6dd668",
                        "change_type": "Pay",
                        "owner": {
                            "AddressOwner": "0xd6fa49643e34b29308199a60994ca405da6dd668"
                        },
                        "coin_type": "0x2::sui::SUI",
                        "coin_object_id": "0x3e65c1ff84f1ae81b9d794b4eb743dbd835b9880",
                        "version": 0,
                        "amount": -1000
                    }
                },
                {
                    "coinBalanceChange": {
                        "package_id": "0x0000000000000000000000000000000000000002",
                        "transaction_module": "pay",
                        "sender": "0xd6fa49643e34b29308199a60994ca405da6dd668",
                        "change_type": "Receive",
                        "owner": {
                            "AddressOwner": "0x97a7832722f63758620637cf948f5fe40cd33e83"
                        },
                        "coin_type": "0x2::sui::SUI",
                        "coin_object_id": "0x3e85e0e5c274cefce3db9986d433f5a7fe44bf7e",
                        "version": 1,
                        "amount": 1000
                    }
                }
            ]

Create NFT 's events

        "events": [
                {
                    "coinBalanceChange": {
                        "packageId": "0x0000000000000000000000000000000000000002",
                        "transactionModule": "gas",
                        "sender": "0xf5294ac4355fc20274ad71234f4249b91c281d3a",
                        "changeType": "Gas",
                        "owner": {
                            "AddressOwner": "0xf5294ac4355fc20274ad71234f4249b91c281d3a"
                        },
                        "coinType": "0x2::sui::SUI",
                        "coinObjectId": "0x3fd238b1bc785d5195fa337ab77701f5c15168ff",
                        "version": 0,
                        "amount": -1046
                    }
                },
                {
                    "newObject": {
                        "packageId": "0x0000000000000000000000000000000000000002",
                        "transactionModule": "devnet_nft",
                        "sender": "0xf5294ac4355fc20274ad71234f4249b91c281d3a",
                        "recipient": {
                            "AddressOwner": "0xf5294ac4355fc20274ad71234f4249b91c281d3a"
                        },
                        "objectType": "0x2::devnet_nft::DevNetNFT",
                        "objectId": "0x66b2df746863a39df5e621f8d65e53caf78d8eb2"
                    }
                },
                {
                    "moveEvent": {
                        "packageId": "0x0000000000000000000000000000000000000002",
                        "transactionModule": "devnet_nft",
                        "sender": "0xf5294ac4355fc20274ad71234f4249b91c281d3a",
                        "type": "0x2::devnet_nft::MintNFTEvent",
                        "fields": {
                            "creator": "0xf5294ac4355fc20274ad71234f4249b91c281d3a",
                            "name": "Example NFT",
                            "object_id": "0x66b2df746863a39df5e621f8d65e53caf78d8eb2"
                        },
                        "bcs": "ZrLfdGhjo5315iH41l5TyveNjrL1KUrENV/CAnStcSNPQkm5HCgdOgtFeGFtcGxlIE5GVA=="
                    }
                }
            ]

Explorer event view

image

patrickkuo avatar Oct 17 '22 10:10 patrickkuo

@patrickkuo @longbowlu wondering do we want to log events on the txn level or on the object level, or both?

both

longbowlu avatar Oct 17 '22 21:10 longbowlu

⚠️ 🦋 Changesets Warning: This PR has changes to public npm packages, but does not contain a changeset. You can create a changeset easily by running pnpm changeset, and following the prompts. If your change does not need a changeset (e.g. a documentation-only change), you can ignore this message. This warning will be removed when a changeset is added to this pull request.

Learn more about Changesets.

github-actions[bot] avatar Oct 23 '22 10:10 github-actions[bot]

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3339537035#artifacts

github-actions[bot] avatar Oct 23 '22 10:10 github-actions[bot]

Ok, to properly address the missing Pay transaction event issue, I ended up refactored the log event logic and moved log event into temporary_store (except for MoveEvent)

This PR added new CoinBalanceChange and MutateObject events, which are useful for tracking user's coin balance changes and object changes.

(I apologise for the huge PR)

patrickkuo avatar Oct 23 '22 17:10 patrickkuo

This PR is ready for more review/ re-review, thanks!!

patrickkuo avatar Oct 26 '22 12:10 patrickkuo

Can I get a thumbs up from @Jordan-Mysten / @Andrew47 / @666lcz for the typescript / explorer changes?

patrickkuo avatar Oct 27 '22 17:10 patrickkuo