You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have very nice JSON structs for legibility, and they have been designed to be the public API for the contracts, used by eg. JS devs. However, some structs, especially those we store, are not part of the public API and we do not need to worry about legibility. Many of those have very long names in the keys. Let's try using #[serde(rename)] to make that smaller.
I'd suggest trying it on 1 or 2 contracts and see if this gives reduced gas usage and/or wasm size (testing gas usage with wasmd - so we charge for bytes in storage). If it seems to have a nice impact, we can recommend using it. The public API needs to be legible, the internal structs, just usable by this contract.
For an example, we could modify the cw20-escrow state to be something like:
#[derive(Serialize,Deserialize,Clone,PartialEq,JsonSchema,Debug)]pubstructEscrow{/// arbiter can decide to approve or refund the escrow#[serde(rename="a")]pubarbiter:Addr,/// if approved, funds go to the recipient#[serde(rename="r")]pubrecipient:Addr,/// if refunded, funds go to the source#[serde(rename="s")]pubsource:Addr,/// When end height set and block height exceeds this value, the escrow is expired./// Once an escrow is expired, it can be returned to the original funder (via "refund").#[serde(rename="h")]pubend_height:Option<u64>,/// When end time (in seconds since epoch 00:00:00 UTC on 1 January 1970) is set and/// block time exceeds this value, the escrow is expired./// Once an escrow is expired, it can be returned to the original funder (via "refund").#[serde(rename="t")]pubend_time:Option<u64>,/// Balance in Native and Cw20 tokens#[serde(rename="b")]pubbalance:GenericBalance,/// All possible contracts that we accept tokens from#[serde(rename="w")]pubcw20_whitelist:Vec<Addr>,}
We could even look at GenericBalance and compress that / make storage-friendly versions of Coin that can be converted to-from the normal Coin API (ideally same layout so zero cost into) but store as smaller, simpler JSON.
The text was updated successfully, but these errors were encountered:
We have very nice JSON structs for legibility, and they have been designed to be the public API for the contracts, used by eg. JS devs. However, some structs, especially those we store, are not part of the public API and we do not need to worry about legibility. Many of those have very long names in the keys. Let's try using
#[serde(rename)]
to make that smaller.I'd suggest trying it on 1 or 2 contracts and see if this gives reduced gas usage and/or wasm size (testing gas usage with wasmd - so we charge for bytes in storage). If it seems to have a nice impact, we can recommend using it. The public API needs to be legible, the internal structs, just usable by this contract.
For an example, we could modify the cw20-escrow state to be something like:
We could even look at GenericBalance and compress that / make storage-friendly versions of Coin that can be converted to-from the normal Coin API (ideally same layout so zero cost into) but store as smaller, simpler JSON.
The text was updated successfully, but these errors were encountered: