hand.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import "solana";
  2. // Interface to the lever program.
  3. @program_id("4wFN9As94uDgcBK9umEi6DNjRLi8gq7jaHwSw3829xq8")
  4. interface leverInterface {
  5. function switchPower(string name) external;
  6. }
  7. @program_id("9rN5nSQBX1gcbweshWAfRE4Ccv5puJfxUJhqKZ5BEdoP")
  8. contract hand {
  9. // Creating a data account is required by Solang, but the account is not used in this example.
  10. // We only interact with the lever program.
  11. @payer(payer) // payer for the data account
  12. constructor() {}
  13. // "Pull the lever" by calling the switchPower instruction on the lever program via a Cross Program Invocation.
  14. @mutableAccount(leverData)
  15. function pullLever(string name) external {
  16. // The account required by the switchPower instruction.
  17. // This is the data account created by the lever program (not this program), which stores the state of the switch.
  18. AccountMeta[1] metas = [
  19. AccountMeta({pubkey: tx.accounts.leverData.key, is_writable: true, is_signer: false})
  20. ];
  21. // The data required by the switchPower instruction.
  22. string instructionData = name;
  23. // Invoke the switchPower instruction on the lever program.
  24. leverInterface.switchPower{accounts: metas}(instructionData);
  25. }
  26. }