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

Reduce the amount of roundtrips for built-in token contract #515

Merged
merged 4 commits into from
Oct 4, 2022

Conversation

dmkozh
Copy link
Contributor

@dmkozh dmkozh commented Oct 3, 2022

What

  • AccountId is decoded from RawVal straight into XDR, as AccountId XDR is a host object type now
  • AccountId is passed around in internal host fns instead of Object
  • Removed ClassicMetadata as it became an internal-only structure. Instead, just pass the encoded asset to the contract asset initializer

Why

This came up during merging the tests with the recently changed code; the recent changes made it pretty hard to understand and use the built-in token due to existence of several 'wrapper' types on the host side. This also addresses #503 partially.

Known limitations

N/A

- `AccountId` is decoded straight into XDR, as `AccountId` XDR is a host object type now
- `AccountId` is passed around in internal host fns instead of `Object`
- Removed `ClassicMetadata` as it became an internal-only structure. Instead, just pass the encoded asset to the contract asset initializer
Copy link
Contributor

@sisuresh sisuresh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for cleaning this up!

pub(crate) fn deserialize_asset(&self, asset: Object) -> Result<Asset, HostError> {
self.visit_obj(asset, |hv: &Vec<u8>| {
self.charge_budget(CostType::ValDeser, hv.len() as u64)?;
Asset::from_xdr(&mut hv.as_slice())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nice, I've also added an Object helper to avoid visit_obj boilerplate in callers.

@sisuresh sisuresh merged commit 71130a0 into stellar:main Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants