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

Wrapping all types in structs #1475

Open
Tracked by #1470
Braqzen opened this issue Nov 22, 2023 · 1 comment
Open
Tracked by #1470

Wrapping all types in structs #1475

Braqzen opened this issue Nov 22, 2023 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation sway

Comments

@Braqzen
Copy link
Contributor

Braqzen commented Nov 22, 2023

It has been brought to my attention that the indexer can only capture an event if it has an ID associated with it, potentially in the form of a struct.

I may have misunderstood.

If it is not currently possible to capture events such as

log(5u64)

and instead we must do

log(SomeStruct { field: 5u64 })

then that is an unintuitive UX limitation.
I expect to be able to log any type and capture it in the indexer rather than be limited to wrapping it into a struct.

@ra0x3
Copy link
Contributor

ra0x3 commented Nov 29, 2023

@Braqzen

  • I think I see what you're referring to
  • I will tag this as "documentation" since I think we need to explain this clearly in the docs (maybe in the "What can I index" section)
    • Open to ideas on where in the docs this should go
  • When you log(5) you're logging a reference type, whereas when you log log(SomeStruct) you're logging a complex type
    • Complex types are made available via the LogData receipt's data field
      • We decode this data field from a byte array back into it's original SomeStruct form
      • Then you can access the SomeStruct via your indexer handler such as: fn do_a_thing(s: SomeStruct)
    • However, for reference types, these come via the Log receipt
      • Since these are reference types, there's no decoding to be done for them
      • If you want to use this log(5), you'd have to add the Log to your handler such as: fn do_a_thing(s: Log)
        • From here you can access your 5 value via the Log's ra field assert_eq!(s.ra, 5)
  • Again, I think this is a documentation issue, but open to ideas on where to document this

@ra0x3 ra0x3 added documentation Improvements or additions to documentation sway labels Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation sway
Projects
None yet
Development

No branches or pull requests

2 participants