ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
320 stars 46 forks source link

Support strings in events by calling .clone() #65

Closed mcintyre94 closed 1 year ago

mcintyre94 commented 1 year ago

Since strings in Rust don't implement Copy, we need to call .clone() when we read these fields of an event. This PR adds logic to add .clone() for only strings.

I've also added an event example which shows various different field types in events. I found that lists and arrays also don't work, but will also need further work, so I've opened a separate issue for them: #64

Closes #61

ameliatastic commented 1 year ago

Definitely a symptom of a deeper problem with strings. I started using strings in init seeds pretty recklessly (essentially letting string literals turn into Rust string literals because it was easier). I'll look pretty closely at this, maybe even adding some unrelated extra fixes if that's okay with you.

ameliatastic commented 1 year ago

Here's an optional second way of doing things, which uses the original type information instead of intuiting based on the generated type's name. Might make things easier in the future, thoughts?

mcintyre94 commented 1 year ago

Awesome this LGTM now! TY for the improvement!

ameliatastic commented 1 year ago

Cool! I'll just merge it, I was looking to see if there was any extra problems with strings that could be solved here but it ended up being a totally separate issue.