AddEntity.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma warning disable CS1591
  2. using Solana.Unity.Rpc;
  3. using Solana.Unity.Rpc.Models;
  4. using Solana.Unity.Wallet;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using World.Program;
  8. namespace Bolt {
  9. public partial class World {
  10. public class AddEntityInstruction {
  11. public PublicKey Pda { get; set; }
  12. public TransactionInstruction Instruction { get; set; }
  13. }
  14. public static async Task<AddEntityInstruction> AddEntity(PublicKey world, PublicKey payer, PublicKey entityPda, string seed) {
  15. return await AddEntity(world, payer, entityPda, Encoding.UTF8.GetBytes(seed));
  16. }
  17. public static async Task<AddEntityInstruction> AddEntity(PublicKey world, PublicKey payer, PublicKey entityPda, byte[] seed = null) {
  18. var addEntity = new AddEntityAccounts() {
  19. Payer = payer,
  20. Entity = entityPda,
  21. World = world,
  22. };
  23. return new AddEntityInstruction() {
  24. Pda = entityPda,
  25. Instruction = WorldProgram.AddEntity(addEntity, seed, new PublicKey(WorldProgram.ID)),
  26. };
  27. }
  28. public static async Task<AddEntityInstruction> AddEntity(IRpcClient client, PublicKey world, PublicKey payer, string seed) {
  29. var worldData = await GetWorld(client, world);
  30. return await AddEntity(world, payer, seed, worldData.Id);
  31. }
  32. public static async Task<AddEntityInstruction> AddEntity(PublicKey world, PublicKey payer, string seed, ulong worldId) {
  33. return await AddEntity(world, payer, Encoding.UTF8.GetBytes(seed), worldId);
  34. }
  35. public static async Task<AddEntityInstruction> AddEntity(PublicKey world, PublicKey payer, byte[] seed, ulong worldId) {
  36. var entityPda = WorldProgram.FindEntityPda(worldId, seed);
  37. return await AddEntity(world, payer, entityPda, seed);
  38. }
  39. public static async Task<AddEntityInstruction> AddEntity(IRpcClient client, PublicKey world, PublicKey payer) {
  40. var worldData = await GetWorld(client, world);
  41. var entityPda = WorldProgram.FindEntityPda(worldData.Id, worldData.Entities);
  42. return await AddEntity(world, payer, entityPda);
  43. }
  44. }
  45. }