use_authority.sol 783 B

123456789101112131415161718192021222324252627282930313233343536
  1. import 'solana';
  2. contract AuthorityExample {
  3. address authority;
  4. uint64 counter;
  5. modifier needs_authority() {
  6. for (uint64 i = 0; i < tx.accounts.length; i++) {
  7. AccountInfo ai = tx.accounts[i];
  8. if (ai.key == authority && ai.is_signer) {
  9. _;
  10. return;
  11. }
  12. }
  13. print("not signed by authority");
  14. revert();
  15. }
  16. constructor(address initial_authority) {
  17. authority = initial_authority;
  18. }
  19. function set_new_authority(address new_authority) needs_authority public {
  20. authority = new_authority;
  21. }
  22. function inc() needs_authority public {
  23. counter += 1;
  24. }
  25. function get() public view returns (uint64) {
  26. return counter;
  27. }
  28. }