system_instruction_example.sol 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: Apache-2.0
  2. import '../../solana-library/system_instruction.sol';
  3. contract TestingInstruction {
  4. @mutableSigner(from)
  5. @mutableSigner(to)
  6. function create_account(uint64 lamports, uint64 space, address owner) external {
  7. SystemInstruction.create_account(tx.accounts.from.key, tx.accounts.to.key, lamports, space, owner);
  8. }
  9. @mutableSigner(from)
  10. @mutableAccount(to)
  11. @signer(base)
  12. function create_account_with_seed(string seed, uint64 lamports, uint64 space, address owner) external {
  13. SystemInstruction.create_account_with_seed(
  14. tx.accounts.from.key, tx.accounts.to.key, tx.accounts.base.key, seed, lamports, space, owner);
  15. }
  16. @mutableSigner(assignAccount)
  17. function assign(address owner) external {
  18. SystemInstruction.assign(tx.accounts.assignAccount.key, owner);
  19. }
  20. @mutableAccount(assignAccount)
  21. @signer(base)
  22. function assign_with_seed(string seed, address owner) external {
  23. SystemInstruction.assign_with_seed(tx.accounts.assignAccount.key, tx.accounts.base.key, seed, owner);
  24. }
  25. @mutableSigner(from)
  26. @mutableAccount(to)
  27. function transfer(uint64 lamports) external {
  28. SystemInstruction.transfer(tx.accounts.from.key, tx.accounts.to.key, lamports);
  29. }
  30. @mutableAccount(fromKey)
  31. @signer(fromBase)
  32. @mutableAccount(toKey)
  33. function transfer_with_seed(string seed, address from_owner, uint64 lamports) external {
  34. SystemInstruction.transfer_with_seed(
  35. tx.accounts.fromKey.key,
  36. tx.accounts.fromBase.key,
  37. seed,
  38. from_owner,
  39. tx.accounts.toKey.key,
  40. lamports);
  41. }
  42. @mutableSigner(accKey)
  43. function allocate(uint64 space) external {
  44. SystemInstruction.allocate(tx.accounts.accKey.key, space);
  45. }
  46. @mutableAccount(accKey)
  47. @signer(base)
  48. function allocate_with_seed(string seed, uint64 space, address owner) external {
  49. SystemInstruction.allocate_with_seed(
  50. tx.accounts.accKey.key,
  51. tx.accounts.base.key,
  52. seed,
  53. space,
  54. owner);
  55. }
  56. @mutableSigner(from)
  57. @mutableAccount(nonce)
  58. @signer(base)
  59. function create_nonce_account_with_seed(string seed, address authority, uint64 lamports) external {
  60. SystemInstruction.create_nonce_account_with_seed(
  61. tx.accounts.from.key,
  62. tx.accounts.nonce.key,
  63. tx.accounts.base.key,
  64. seed,
  65. authority,
  66. lamports);
  67. }
  68. @mutableSigner(from)
  69. @mutableSigner(nonce)
  70. function create_nonce_account(address authority, uint64 lamports) external {
  71. SystemInstruction.create_nonce_account(tx.accounts.from.key,
  72. tx.accounts.nonce.key, authority, lamports);
  73. }
  74. @mutableAccount(nonce)
  75. function advance_nonce_account(address authorized) external {
  76. SystemInstruction.advance_nonce_account(
  77. tx.accounts.nonce.key, authorized);
  78. }
  79. @mutableAccount(nonce)
  80. @mutableAccount(to)
  81. @signer(authority)
  82. function withdraw_nonce_account(uint64 lamports) external {
  83. SystemInstruction.withdraw_nonce_account(
  84. tx.accounts.nonce.key,
  85. tx.accounts.authority.key,
  86. tx.accounts.to.key, lamports);
  87. }
  88. @mutableAccount(nonce)
  89. @signer(authority)
  90. function authorize_nonce_account(address new_authority) external {
  91. SystemInstruction.authorize_nonce_account(
  92. tx.accounts.nonce.key,
  93. tx.accounts.authority.key, new_authority);
  94. }
  95. // This is not available on Solana v1.9.15
  96. // function upgrade_nonce_account(address nonce) external {
  97. // SystemInstruction.upgrade_nonce_account(nonce);
  98. // }
  99. }