stellar / stellar-docs

Documentation for Stellar
https://developers.stellar.org
Apache License 2.0
54 stars 123 forks source link

Option type missing from docs #485

Open tamirms opened 1 year ago

tamirms commented 1 year ago

It is not clear how to represent a Rust Option type in XDR. The custom-types documentation does not include any information about Option types.

Also, it would be helpful to have more tooling or at least a link to a reference implementation which converts Soroban types into their corresponding XDR structures. Otherwise, you are left guessing at how values should be encoded as SCVals.

Julian-dev28 commented 1 year ago

@tamirms @paulbellamy

How is the status on this Issue? We have had some updates since it was opened and I'm thinking that things may have changed or it this issue has been resolved.

I would appreciate an update when you get a chance

Thanks!

paulbellamy commented 1 year ago

https://github.com/stellar/stellar-xdr/pull/70 completely overhauled the scval system since this issue was written. There are two ways Option is represented in xdr.

In the ContractSpec (what you get if you do a soroban contract inspect), there is an ScSpecTypeOption type, which acts like rust's Option<T>

In the actual invocation xdr, there is no explicit Option type. Instead there is an ScVoid value, which you can pass for any value that should be None. This roughly means that in the arguments every argument is implicitly optional. But if you make the wrong one optional the transaction will be rejected.

We should probably think of a good way to explain this to people.

Good luck 🤷

janewang commented 4 months ago

Add to this page https://developers.stellar.org/docs/smart-contracts/example-contracts/custom-types

leighmcculloch commented 3 months ago

Should add to this page too: https://developers.stellar.org/docs/tools/sdks/build-your-own