create_contract.sol 2.7 KB

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