如何获取 anchor solana 中给定代币地址的数量?

how to get the the amount of the given token address in anchor solana?

我在我的 solana 程序中得到两个令牌地址作为函数的输入。如何获取两个令牌的余额。在 solana webjs 中使用 getTokenSupply 我可以在 javascript 中获取它我如何在 rust 中获取它。

 const data = await Connection.getTokenSupply(from_pairs);
 const data2 = await Connection.getTokenSupply(to_pairs);
 console.log(data, data2)

锚锈的类似方法是什么?

如果您使用的是 Anchor,那可能意味着您在链上。要获得链上代币铸币厂的供应,您需要将其传递给您的程序,将帐户中的数据反序列化为代币铸币厂,然后读取供应字段。

这是一个测试示例:https://github.com/solana-labs/solana-program-library/blob/756696ee8e7b8dbe640113079ba11447ba3524c1/token/program/src/processor.rs#L4234-L4235