-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Add read_address_balance API
#24692
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
base: main
Are you sure you want to change the base?
Add read_address_balance API
#24692
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| /// Read the balance of an address as of the beginning of the current consensus commit. | ||
| /// Can read either address-owned or object-owned balances. | ||
| public fun read_address_balance<T>( | ||
| root: &sui::accumulator::AccumulatorRoot, | ||
| address: address, | ||
| ): u64 { | ||
| if (!root.u128_exists<Balance<T>>(address)) { | ||
| return 0 | ||
| }; | ||
| let val: u128 = root.u128_read<Balance<T>>(address); | ||
| let val = std::u128::min(std::u64::max_value!() as u128, val); | ||
| val as u64 | ||
| } | ||
|
|
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 will take a deeper look in a bit, but my initial reaction is that this should belong in funds_accumulator.
It can do something like
/// Where `U` is the underlying integer type of `T`
/// This avoids needing 6 different APIs for each type--each of which would need
/// to assert the underlying integer type anyway
public fun read_funds_balance<T, U>(
root: &sui::accumulator::AccumulatorRoot,
_: internal::Permit<T>,
owner: address,
): U;
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.
can you get the max for an integer type parametrically? if not I'm not sure how much this will save.
|
|
||
| /// Read the balance of an address as of the beginning of the current consensus commit. | ||
| /// Can read either address-owned or object-owned balances. | ||
| public fun read_address_balance<T>( |
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.
This should probably be something like
| public fun read_address_balance<T>( | |
| public fun initial_funds_balance<T>( |
initial might not be the right word but we need 4 distinct concepts
- At the start of the transaction
- deposits
- withdrawals
- current/net (initial + withdrawals - deposits)
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.
how about read_settled_address_balance?
3729ce7 to
2b290e8
Compare
2b290e8 to
c94cbd3
Compare
No description provided.