create_contract.sol 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'solana';
  2. contract creator {
  3. function create_child() external {
  4. print("Going to create child");
  5. Child.new();
  6. Child.say_hello();
  7. }
  8. function create_seed1(bytes seed, bytes1 bump, uint64 space) external {
  9. print("Going to create Seed1");
  10. Seed1.new(seed, bump, space);
  11. Seed1.say_hello();
  12. }
  13. function create_seed2(bytes seed, uint32 space) external {
  14. print("Going to create Seed2");
  15. Seed2.new(seed, space);
  16. }
  17. function create_child_with_metas(address child, address payer) public {
  18. print("Going to create child with metas");
  19. AccountMeta[3] metas = [
  20. AccountMeta({pubkey: child, is_signer: true, is_writable: true}),
  21. AccountMeta({pubkey: payer, is_signer: true, is_writable: true}),
  22. AccountMeta({pubkey: address"11111111111111111111111111111111", is_writable: false, is_signer: false})
  23. ];
  24. Child.new{accounts: metas}();
  25. Child.use_metas();
  26. }
  27. function create_without_annotation() external {
  28. MyCreature.new();
  29. MyCreature.say_my_name();
  30. }
  31. }
  32. @program_id("Chi1d5XD6nTAp2EyaNGqMxZzUjh6NvhXRxbGHP3D1RaT")
  33. contract Child {
  34. @payer(payer)
  35. @space(511 + 7)
  36. constructor() {
  37. assert(tx.accounts.payer.is_signer);
  38. assert(tx.accounts.payer.is_writable);
  39. print("In child constructor");
  40. }
  41. function say_hello() pure public {
  42. print("Hello there");
  43. }
  44. function use_metas() pure public {
  45. print("I am using metas");
  46. }
  47. }
  48. @program_id("SeedHw4CsFsDEGu2AVwFM1toGXsbAJSKnb7kS8TrLxu")
  49. contract Seed1 {
  50. @payer(payer)
  51. constructor(@seed bytes seed, @bump bytes1 bump, @space uint64 space) {
  52. print("In Seed1 constructor");
  53. }
  54. function say_hello() pure public {
  55. print("Hello from Seed1");
  56. }
  57. }
  58. @program_id("Seed23VDZ9HFCfKvFwmemB6dpi25n5XjZdP52B2RUmh")
  59. contract Seed2 {
  60. bytes my_seed;
  61. @payer(payer)
  62. @seed("sunflower")
  63. constructor(@seed bytes seed, @space uint64 space) {
  64. my_seed = seed;
  65. print("In Seed2 constructor");
  66. }
  67. function check() public view {
  68. address pda = create_program_address([ "sunflower", my_seed ], address(this));
  69. if (pda == tx.accounts.dataAccount.key) {
  70. print("I am PDA.");
  71. }
  72. }
  73. }
  74. @program_id("8gTkAidfM82u3DGbKcZpHwL5p47KQA16MDb4WmrHdmF6")
  75. contract MyCreature {
  76. constructor() {
  77. print("In child constructor");
  78. }
  79. function say_my_name() public pure {
  80. print("say_my_name");
  81. }
  82. }