如何将uint256变量转换为Solana Rust?
我应该使用u64和9小数位数在索拉纳锈蚀而不是18小数点在虚空?
据索拉纳的医生说,兰波特的价值为0.000000001索尔。这是9个小数点。
因此,在Solana中,9小数点似乎是标准的,而在Ethereum中则是18小数位数。
u64的最大值为18,446,744,073,709,551,615。
锈蚀中的u128最大值为2^128-1。
不知何故,索拉纳没有u256!奇怪
如果我在所有的计算中使用9个小数,那么我应该确保18,446,744,073对于我的Solana锈菌u64变量的最大值来说足够大,对吗?这是正确的策略吗?谢谢!
发布于 2021-12-13 03:47:02
我认为我们不需要像uint256这样的额外库,因为Solana程序库(它们的令牌库)正在使用u64来传输https://github.com/solana-labs/solana-program-library/blob/master/token/program/src/processor.rs#L203
此外,anchor_spl使用u64读取令牌余额( https://docs.rs/anchor-spl/0.19.0/anchor_spl/token/accessor/fn.amount.html )。
Function anchor_spl::token::accessor::amount
pub fn amount(account: &AccountInfo<'_>) -> Result<u64, ProgramError>锈蚀中的uint128实际上足够大。
340,282,366,920,938,463,463,374,607,431,768,211,455的范围为0到2^128-1,即0~ uint128。
有9个小数点,uint128就足够大了。
https://stackoverflow.com/questions/70082314
复制相似问题