-
Notifications
You must be signed in to change notification settings - Fork 2
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
Poc query balance #21
Conversation
poc/runtime/src/xcq.rs
Outdated
// variant 0 means free balance | ||
// variant 1 means reserved balance | ||
// variant 2 means free+reserved | ||
let mut sum = 0u64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the sum logic should happen in guest program. the host only does the query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking making host call:
query_balances(variant, account_ids_ptr, bytes_len)
(which make host decodeVec<AccountId>
's length) and return slices of balance (write to guest as return values)- or let guest has the type information to decode bytes, then do
query_balance(variant, account_id)
I think the latter will be more general and make the host call api simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the prefixed compact-encoded length in SCALE encoding with Vec<T>
just for size hint to preallocate appropriate memory? We still need to specify the encoded bytes length when doing decoding, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
host function should be minimal
it should be query one account id at a time so and we know the size of AccountId and can just hardcode it here
458ccd3
to
ee158cc
Compare
poc-guest-query-balance is working, close #2
Bugs:
The previous way of returning value via guest's stack is not working. Specifically, PR #17 has bug, which produce 40 instead of 42 for variant 1. In addition, return RO value is ok for variant 0.
I roughly looked over the assembly code, and it does seem a bit off. I need to take a closer look later.
For now, I use return value via heap instead, it works.