hand.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import "solana";
  2. // Interface to the lever program.
  3. leverInterface constant leverProgram = leverInterface(address'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(address payer) {}
  13. // "Pull the lever" by calling the switchPower instruction on the lever program via a Cross Program Invocation.
  14. function pullLever(address dataAccount, string name) public {
  15. // The account required by the switchPower instruction.
  16. // This is the data account created by the lever program (not this program), which stores the state of the switch.
  17. AccountMeta[1] metas = [
  18. AccountMeta({pubkey: dataAccount, is_writable: true, is_signer: false})
  19. ];
  20. // The data required by the switchPower instruction.
  21. string instructionData = name;
  22. // Invoke the switchPower instruction on the lever program.
  23. leverProgram.switchPower{accounts: metas}(instructionData);
  24. }
  25. }