accountinfo.sol 584 B

123456789101112131415161718192021222324
  1. import {AccountInfo} from "solana";
  2. contract SplToken {
  3. function get_token_account(address token)
  4. internal
  5. view
  6. returns (AccountInfo)
  7. {
  8. for (uint64 i = 0; i < tx.accounts.length; i++) {
  9. AccountInfo ai = tx.accounts[i];
  10. if (ai.key == token) {
  11. return ai;
  12. }
  13. }
  14. revert("token not found");
  15. }
  16. function total_supply(address token) public view returns (uint64) {
  17. AccountInfo account = get_token_account(token);
  18. return account.data.readUint64LE(33);
  19. }
  20. }