AddEntity.cs 2.4 KB

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