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

Publish tx data #231

Merged
merged 1 commit into from
Apr 3, 2024
Merged

Publish tx data #231

merged 1 commit into from
Apr 3, 2024

Conversation

Thomasvdam
Copy link
Member

Explanation of Changes

The main thing I'm unsure about is how we pass the codec around, is this idiomatic Golang or is there a cleaner way to do this?

Made a small improvement in the ListenFinalizeBlock handler by preallocating the slice since we should know up front how long it is going to be.

Testing

You can 'just' set up the plugin, queue emulator, and start a local node. Once it's running submit a transaction (for the example I used a bank transfer, but I have tried a bunch of different ones). You should start see a "tx" message getting added to the queue:

{"level":"info","msg":"2024-03-27 17:23:39: Queue: local-updates.fifo, Message: {\"type\":\"tx\",\"data\":{\"hash\":\"1D3D58C0F82BCDFC1B4A2FDC43CD73C9DC6EC5C48AB78265072736A21B9A2392\",\"time\":\"2024-03-27T17:23:31.469443Z\",\"tx\":{\"body\":{\"messages\":[{\"@type\":\"/cosmos.bank.v1beta1.MsgSend\",\"from_address\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"to_address\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"amount\":[{\"denom\":\"aseda\",\"amount\":\"10000000000000000000\"}]}],\"memo\":\"\",\"timeout_height\":\"0\",\"extension_options\":[],\"non_critical_extension_options\":[]},\"auth_info\":{\"signer_infos\":[{\"public_key\":{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"AyR0Wa9Qq1PJAzxCI75KAQQQYTpBDXGGWBkjy14QVDxM\"},\"mode_info\":{\"single\":{\"mode\":\"SIGN_MODE_DIRECT\"}},\"sequence\":\"17\"}],\"fee\":{\"amount\":[],\"gas_limit\":\"200000\",\"payer\":\"\",\"granter\":\"\"},\"tip\":null},\"signatures\":[\"PstBgoDh52267uZMmMzUYot+UpWNuhlkCd+Jj0Dnhd5km5A29Mjd3KwRLLeegK84W3C6hGfNmG28bSzniknnmw==\"]},\"result\":{\"code\":0,\"data\":\"EiYKJC9jb3Ntb3MuYmFuay52MWJldGExLk1zZ1NlbmRSZXNwb25zZQ==\",\"log\":\"\",\"info\":\"\",\"gas_wanted\":\"200000\",\"gas_used\":\"54728\",\"events\":[{\"type\":\"tx\",\"attributes\":[{\"key\":\"fee\",\"value\":\"\",\"index\":true},{\"key\":\"fee_payer\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true}]},{\"type\":\"tx\",\"attributes\":[{\"key\":\"acc_seq\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah/17\",\"index\":true}]},{\"type\":\"tx\",\"attributes\":[{\"key\":\"signature\",\"value\":\"PstBgoDh52267uZMmMzUYot+UpWNuhlkCd+Jj0Dnhd5km5A29Mjd3KwRLLeegK84W3C6hGfNmG28bSzniknnmw==\",\"index\":true}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/cosmos.bank.v1beta1.MsgSend\",\"index\":true},{\"key\":\"sender\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true},{\"key\":\"module\",\"value\":\"bank\",\"index\":true},{\"key\":\"msg_index\",\"value\":\"0\",\"index\":true}]},{\"type\":\"coin_spent\",\"attributes\":[{\"key\":\"spender\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true},{\"key\":\"amount\",\"value\":\"10000000000000000000aseda\",\"index\":true},{\"key\":\"msg_index\",\"value\":\"0\",\"index\":true}]},{\"type\":\"coin_received\",\"attributes\":[{\"key\":\"receiver\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true},{\"key\":\"amount\",\"value\":\"10000000000000000000aseda\",\"index\":true},{\"key\":\"msg_index\",\"value\":\"0\",\"index\":true}]},{\"type\":\"transfer\",\"attributes\":[{\"key\":\"recipient\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true},{\"key\":\"sender\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true},{\"key\":\"amount\",\"value\":\"10000000000000000000aseda\",\"index\":true},{\"key\":\"msg_index\",\"value\":\"0\",\"index\":true}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"sender\",\"value\":\"seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah\",\"index\":true},{\"key\":\"msg_index\",\"value\":\"0\",\"index\":true}]}],\"codespace\":\"\"}}}\n","time":"2024-03-27T17:23:39Z"}

Just the message:

{
  "type": "tx",
  "data": {
    "hash": "1D3D58C0F82BCDFC1B4A2FDC43CD73C9DC6EC5C48AB78265072736A21B9A2392",
    "time": "2024-03-27T17:23:31.469443Z",
    "tx": {
      "body": {
        "messages": [
          {
            "@type": "/cosmos.bank.v1beta1.MsgSend",
            "from_address": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
            "to_address": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
            "amount": [{ "denom": "aseda", "amount": "10000000000000000000" }]
          }
        ],
        "memo": "",
        "timeout_height": "0",
        "extension_options": [],
        "non_critical_extension_options": []
      },
      "auth_info": {
        "signer_infos": [
          {
            "public_key": {
              "@type": "/cosmos.crypto.secp256k1.PubKey",
              "key": "AyR0Wa9Qq1PJAzxCI75KAQQQYTpBDXGGWBkjy14QVDxM"
            },
            "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } },
            "sequence": "17"
          }
        ],
        "fee": {
          "amount": [],
          "gas_limit": "200000",
          "payer": "",
          "granter": ""
        },
        "tip": null
      },
      "signatures": [
        "PstBgoDh52267uZMmMzUYot+UpWNuhlkCd+Jj0Dnhd5km5A29Mjd3KwRLLeegK84W3C6hGfNmG28bSzniknnmw=="
      ]
    },
    "result": {
      "code": 0,
      "data": "EiYKJC9jb3Ntb3MuYmFuay52MWJldGExLk1zZ1NlbmRSZXNwb25zZQ==",
      "log": "",
      "info": "",
      "gas_wanted": "200000",
      "gas_used": "54728",
      "events": [
        {
          "type": "tx",
          "attributes": [
            { "key": "fee", "value": "", "index": true },
            {
              "key": "fee_payer",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            }
          ]
        },
        {
          "type": "tx",
          "attributes": [
            {
              "key": "acc_seq",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah/17",
              "index": true
            }
          ]
        },
        {
          "type": "tx",
          "attributes": [
            {
              "key": "signature",
              "value": "PstBgoDh52267uZMmMzUYot+UpWNuhlkCd+Jj0Dnhd5km5A29Mjd3KwRLLeegK84W3C6hGfNmG28bSzniknnmw==",
              "index": true
            }
          ]
        },
        {
          "type": "message",
          "attributes": [
            {
              "key": "action",
              "value": "/cosmos.bank.v1beta1.MsgSend",
              "index": true
            },
            {
              "key": "sender",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            },
            { "key": "module", "value": "bank", "index": true },
            { "key": "msg_index", "value": "0", "index": true }
          ]
        },
        {
          "type": "coin_spent",
          "attributes": [
            {
              "key": "spender",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            },
            {
              "key": "amount",
              "value": "10000000000000000000aseda",
              "index": true
            },
            { "key": "msg_index", "value": "0", "index": true }
          ]
        },
        {
          "type": "coin_received",
          "attributes": [
            {
              "key": "receiver",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            },
            {
              "key": "amount",
              "value": "10000000000000000000aseda",
              "index": true
            },
            { "key": "msg_index", "value": "0", "index": true }
          ]
        },
        {
          "type": "transfer",
          "attributes": [
            {
              "key": "recipient",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            },
            {
              "key": "sender",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            },
            {
              "key": "amount",
              "value": "10000000000000000000aseda",
              "index": true
            },
            { "key": "msg_index", "value": "0", "index": true }
          ]
        },
        {
          "type": "message",
          "attributes": [
            {
              "key": "sender",
              "value": "seda12rype4zl8wxcgqwl237fll6hvufkgcj8kwnuah",
              "index": true
            },
            { "key": "msg_index", "value": "0", "index": true }
          ]
        }
      ],
      "codespace": ""
    }
  }
}

Related PRs and Issues

Closes: #223

@Thomasvdam Thomasvdam requested a review from a team March 27, 2024 17:33
@Thomasvdam Thomasvdam force-pushed the feat/publish-block-data branch from fe9e587 to d18ee12 Compare March 28, 2024 09:45
@Thomasvdam Thomasvdam force-pushed the feat/publish-tx-data branch from f9aabb4 to 6dcf127 Compare March 28, 2024 09:45
Copy link
Contributor

@gluax gluax left a comment

Choose a reason for hiding this comment

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

P sure how you are dealing with the codec right now is idiomatic go, at least afaik.

Copy link
Member

@hacheigriega hacheigriega left a comment

Choose a reason for hiding this comment

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

I think Golang idiomatic way is to shorten local variables whenever possible. So like msg instead of msgs. (I double-checked with geth repo 😀)

@Thomasvdam Thomasvdam force-pushed the feat/publish-block-data branch from d18ee12 to b10f694 Compare April 3, 2024 08:58
@Thomasvdam Thomasvdam force-pushed the feat/publish-tx-data branch from 6dcf127 to 5afb323 Compare April 3, 2024 08:59
Base automatically changed from feat/publish-block-data to main April 3, 2024 09:02
@Thomasvdam Thomasvdam merged commit 5afb323 into main Apr 3, 2024
16 of 17 checks passed
@Thomasvdam Thomasvdam deleted the feat/publish-tx-data branch April 3, 2024 09:02
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.

3 participants