gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
875 stars 355 forks source link

[tm2/gnovm] Identify each msg's event #2031

Closed r3v4s closed 2 months ago

r3v4s commented 4 months ago

Description

While fixing #2028 in #2030, I found out that all of events in single transactions are just being append into single object.

For example if we execute multi-msg tx

await adena.DoContract({
    messages: [{
        "type": "/vm.m_call",
        "value": {
          "caller": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
          "send": "",
          "pkg_path": "gno.land/r/demo/event",
          "func": "Hello",
          "args": []
        }
      },{
        "type": "/vm.m_call",
        "value": {
          "caller": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
          "send": "",
          "pkg_path": "gno.land/r/demo/event",
          "func": "Other",
          "args": []
        }
      }],
    gasFee: 1, 
    gasWanted: 2000000
  });

Event gets like this

"Events": [
    {
      "@type": "/tm.gnoEvent",
      "pkg_path": "gno.land/r/demo/event2",
      "type": "t",
      "func": "inner",
      "attrs": [
        {
          "key": "k",
          "value": "v"
        }
      ]
    },
    {
      "@type": "/tm.gnoEvent",
      "pkg_path": "gno.land/r/demo/event2",
      "type": "t",
      "func": "Hello",
      "attrs": [
        {
          "key": "k",
          "value": "v"
        }
      ]
    },
    {
      "@type": "/tm.gnoEvent",
      "pkg_path": "gno.land/r/demo/event",
      "type": "t",
      "func": "inner",
      "attrs": [
        {
          "key": "k",
          "value": "v"
        }
      ]
    },
    {
      "@type": "/tm.gnoEvent",
      "pkg_path": "gno.land/r/demo/event",
      "type": "t",
      "func": "Hello",
      "attrs": [
        {
          "key": "k",
          "value": "v"
        }
      ]
    },
    {
      "@type": "/tm.gnoEvent",
      "pkg_path": "gno.land/r/demo/event",
      "type": "other",
      "func": "Other",
      "attrs": [
        {
          "key": "k",
          "value": "v"
        }
      ]
    }
  ],

With current event struct, as you can see we don't know which call made which event(s). IMHO, we need identify (or divide) each function's event

  1. first group of event

    {
    "@type": "/tm.gnoEvent",
    "pkg_path": "gno.land/r/demo/event2",
    "type": "t",
    "func": "inner",
    "attrs": [
    {
      "key": "k",
      "value": "v"
    }
    ]
    },
    {
    "@type": "/tm.gnoEvent",
    "pkg_path": "gno.land/r/demo/event2",
    "type": "t",
    "func": "Hello",
    "attrs": [
    {
      "key": "k",
      "value": "v"
    }
    ]
    },
    {
    "@type": "/tm.gnoEvent",
    "pkg_path": "gno.land/r/demo/event",
    "type": "t",
    "func": "inner",
    "attrs": [
    {
      "key": "k",
      "value": "v"
    }
    ]
    },
    {
    "@type": "/tm.gnoEvent",
    "pkg_path": "gno.land/r/demo/event",
    "type": "t",
    "func": "Hello",
    "attrs": [
    {
      "key": "k",
      "value": "v"
    }
    ]
    },
  2. second group of event

    {
    "@type": "/tm.gnoEvent",
    "pkg_path": "gno.land/r/demo/event",
    "type": "other",
    "func": "Other",
    "attrs": [
    {
      "key": "k",
      "value": "v"
    }
    ]
    }
zivkovicmilos commented 2 months ago

Closed as part of #2061