create_contract.sol 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'solana';
  2. contract creator {
  3. Child public c;
  4. function create_child(address child, address payer) public {
  5. print("Going to create child");
  6. c = new Child{address: child}(payer);
  7. c.say_hello();
  8. }
  9. function create_seed1(address child, address payer, bytes seed, bytes1 bump, uint64 space) public {
  10. print("Going to create Seed1");
  11. Seed1 s = new Seed1{address: child}(payer, seed, bump, space);
  12. s.say_hello();
  13. }
  14. function create_seed2(address child, address payer, bytes seed, uint32 space) public {
  15. print("Going to create Seed2");
  16. new Seed2{address: child}(payer, seed, space);
  17. }
  18. }
  19. @program_id("Chi1d5XD6nTAp2EyaNGqMxZzUjh6NvhXRxbGHP3D1RaT")
  20. contract Child {
  21. @payer(payer)
  22. @space(511 + 7)
  23. constructor(address payer) {
  24. print("In child constructor");
  25. }
  26. function say_hello() pure public {
  27. print("Hello there");
  28. }
  29. }
  30. @program_id("SeedHw4CsFsDEGu2AVwFM1toGXsbAJSKnb7kS8TrLxu")
  31. contract Seed1 {
  32. @payer(payer)
  33. @seed(seed)
  34. @bump(bump)
  35. @space(space)
  36. constructor(address payer, bytes seed, bytes1 bump, uint64 space) {
  37. print("In Seed1 constructor");
  38. }
  39. function say_hello() pure public {
  40. print("Hello from Seed1");
  41. }
  42. }
  43. @program_id("Seed23VDZ9HFCfKvFwmemB6dpi25n5XjZdP52B2RUmh")
  44. contract Seed2 {
  45. bytes my_seed;
  46. @payer(payer)
  47. @seed("sunflower")
  48. @seed(seed)
  49. @space(space + 23)
  50. constructor(address payer, bytes seed, uint64 space) {
  51. my_seed = seed;
  52. print("In Seed2 constructor");
  53. }
  54. function check() public {
  55. address pda = create_program_address([ "sunflower", my_seed ], tx.program_id);
  56. if (pda == address(this)) {
  57. print("I am PDA.");
  58. }
  59. }
  60. }