checking-accounts.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import "solana";
  2. @program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
  3. contract checking_accounts {
  4. // The dataAccount is unused in this example, but is a required account when using Solang
  5. @payer(payer) // "payer" is the account that pays to create the dataAccount
  6. constructor() {}
  7. @account(accountToChange)
  8. @mutableSigner(accountToCreate)
  9. function checkAccounts(address accountToChange, address accountToCreate) external view {
  10. print("Number of Accounts Provided: {:}".format(tx.accounts.length));
  11. // Perform checks on the account
  12. programOwnerCheck(tx.accounts.accountToChange);
  13. notInitializedCheck(tx.accounts.accountToCreate);
  14. signerCheck(tx.accounts.accountToCreate);
  15. // (Create account...) (unimplemented)
  16. // (Change account...) (unimplemented)
  17. }
  18. function programOwnerCheck(AccountInfo account) internal pure {
  19. print("Progam Owner Check");
  20. // The owner of this account should be this program
  21. require(account.owner == type(checking_accounts).program_id, "Account to change does not have the correct program id.");
  22. }
  23. function notInitializedCheck(AccountInfo account) internal pure {
  24. print("Check Account Not Initialized");
  25. // This account should not be initialized (has no lamports)
  26. require(account.lamports == 0, "The program expected the account to create to not yet be initialized.");
  27. }
  28. function signerCheck(AccountInfo account) internal pure {
  29. print("Check Account Signed Transaction");
  30. // This account should be a signer on the transaction
  31. require(account.is_signer, "Account required to be a signer");
  32. }
  33. }