AddEntity.cs 2.4 KB

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