123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- #pragma warning disable CS8600
- #pragma warning disable CS8604
- #pragma warning disable CS8618
- #pragma warning disable CS8603
- #pragma warning disable CS8625
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Numerics;
- using System.Threading.Tasks;
- using Solana.Unity;
- using Solana.Unity.Programs.Abstract;
- using Solana.Unity.Programs.Utilities;
- using Solana.Unity.Rpc;
- using Solana.Unity.Rpc.Builders;
- using Solana.Unity.Rpc.Core.Http;
- using Solana.Unity.Rpc.Core.Sockets;
- using Solana.Unity.Rpc.Types;
- using Solana.Unity.Wallet;
- using Velocity;
- using Velocity.Program;
- using Velocity.Errors;
- using Velocity.Accounts;
- using Velocity.Types;
- namespace Velocity
- {
- namespace Accounts
- {
- public partial class Entity
- {
- public static ulong ACCOUNT_DISCRIMINATOR => 1751670451238706478UL;
- public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{46, 157, 161, 161, 254, 46, 79, 24};
- public static string ACCOUNT_DISCRIMINATOR_B58 => "8oEQa6zH67R";
- public ulong Id { get; set; }
- public static Entity Deserialize(ReadOnlySpan<byte> _data)
- {
- int offset = 0;
- ulong accountHashValue = _data.GetU64(offset);
- offset += 8;
- if (accountHashValue != ACCOUNT_DISCRIMINATOR)
- {
- return null;
- }
- Entity result = new Entity();
- result.Id = _data.GetU64(offset);
- offset += 8;
- return result;
- }
- }
- public partial class SessionToken
- {
- public static ulong ACCOUNT_DISCRIMINATOR => 1081168673100727529UL;
- public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{233, 4, 115, 14, 46, 21, 1, 15};
- public static string ACCOUNT_DISCRIMINATOR_B58 => "fyZWTdUu1pS";
- public PublicKey Authority { get; set; }
- public PublicKey TargetProgram { get; set; }
- public PublicKey SessionSigner { get; set; }
- public long ValidUntil { get; set; }
- public static SessionToken Deserialize(ReadOnlySpan<byte> _data)
- {
- int offset = 0;
- ulong accountHashValue = _data.GetU64(offset);
- offset += 8;
- if (accountHashValue != ACCOUNT_DISCRIMINATOR)
- {
- return null;
- }
- SessionToken result = new SessionToken();
- result.Authority = _data.GetPubKey(offset);
- offset += 32;
- result.TargetProgram = _data.GetPubKey(offset);
- offset += 32;
- result.SessionSigner = _data.GetPubKey(offset);
- offset += 32;
- result.ValidUntil = _data.GetS64(offset);
- offset += 8;
- return result;
- }
- }
- public partial class Velocity
- {
- public static ulong ACCOUNT_DISCRIMINATOR => 17932774833452681865UL;
- public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{137, 10, 3, 249, 178, 3, 222, 248};
- public static string ACCOUNT_DISCRIMINATOR_B58 => "PvTAh7RLish";
- public long X { get; set; }
- public long Y { get; set; }
- public long Z { get; set; }
- public long LastApplied { get; set; }
- public string Description { get; set; }
- public BoltMetadata BoltMetadata { get; set; }
- public static Velocity Deserialize(ReadOnlySpan<byte> _data)
- {
- int offset = 0;
- ulong accountHashValue = _data.GetU64(offset);
- offset += 8;
- if (accountHashValue != ACCOUNT_DISCRIMINATOR)
- {
- return null;
- }
- Velocity result = new Velocity();
- result.X = _data.GetS64(offset);
- offset += 8;
- result.Y = _data.GetS64(offset);
- offset += 8;
- result.Z = _data.GetS64(offset);
- offset += 8;
- result.LastApplied = _data.GetS64(offset);
- offset += 8;
- offset += _data.GetBorshString(offset, out var resultDescription);
- result.Description = resultDescription;
- offset += BoltMetadata.Deserialize(_data, offset, out var resultBoltMetadata);
- result.BoltMetadata = resultBoltMetadata;
- return result;
- }
- }
- }
- namespace Errors
- {
- public enum VelocityErrorKind : uint
- {
- }
- }
- namespace Types
- {
- public partial class BoltMetadata
- {
- public PublicKey Authority { get; set; }
- public int Serialize(byte[] _data, int initialOffset)
- {
- int offset = initialOffset;
- _data.WritePubKey(Authority, offset);
- offset += 32;
- return offset - initialOffset;
- }
- public static int Deserialize(ReadOnlySpan<byte> _data, int initialOffset, out BoltMetadata result)
- {
- int offset = initialOffset;
- result = new BoltMetadata();
- result.Authority = _data.GetPubKey(offset);
- offset += 32;
- return offset - initialOffset;
- }
- }
- }
- public partial class VelocityClient : TransactionalBaseClient<VelocityErrorKind>
- {
- public VelocityClient(IRpcClient rpcClient, IStreamingRpcClient streamingRpcClient, PublicKey programId = null) : base(rpcClient, streamingRpcClient, programId ?? new PublicKey(VelocityProgram.ID))
- {
- }
- public async Task<Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<Entity>>> GetEntitysAsync(string programAddress = VelocityProgram.ID, Commitment commitment = Commitment.Confirmed)
- {
- var list = new List<Solana.Unity.Rpc.Models.MemCmp>{new Solana.Unity.Rpc.Models.MemCmp{Bytes = Entity.ACCOUNT_DISCRIMINATOR_B58, Offset = 0}};
- var res = await RpcClient.GetProgramAccountsAsync(programAddress, commitment, memCmpList: list);
- if (!res.WasSuccessful || !(res.Result?.Count > 0))
- return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<Entity>>(res);
- List<Entity> resultingAccounts = new List<Entity>(res.Result.Count);
- resultingAccounts.AddRange(res.Result.Select(result => Entity.Deserialize(Convert.FromBase64String(result.Account.Data[0]))));
- return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<Entity>>(res, resultingAccounts);
- }
- public async Task<Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<SessionToken>>> GetSessionTokensAsync(string programAddress = VelocityProgram.ID, Commitment commitment = Commitment.Confirmed)
- {
- var list = new List<Solana.Unity.Rpc.Models.MemCmp>{new Solana.Unity.Rpc.Models.MemCmp{Bytes = SessionToken.ACCOUNT_DISCRIMINATOR_B58, Offset = 0}};
- var res = await RpcClient.GetProgramAccountsAsync(programAddress, commitment, memCmpList: list);
- if (!res.WasSuccessful || !(res.Result?.Count > 0))
- return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<SessionToken>>(res);
- List<SessionToken> resultingAccounts = new List<SessionToken>(res.Result.Count);
- resultingAccounts.AddRange(res.Result.Select(result => SessionToken.Deserialize(Convert.FromBase64String(result.Account.Data[0]))));
- return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<SessionToken>>(res, resultingAccounts);
- }
- public async Task<Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<Velocity.Accounts.Velocity>>> GetVelocitysAsync(string programAddress = VelocityProgram.ID, Commitment commitment = Commitment.Confirmed)
- {
- var list = new List<Solana.Unity.Rpc.Models.MemCmp>{new Solana.Unity.Rpc.Models.MemCmp{Bytes = Velocity.Accounts.Velocity.ACCOUNT_DISCRIMINATOR_B58, Offset = 0}};
- var res = await RpcClient.GetProgramAccountsAsync(programAddress, commitment, memCmpList: list);
- if (!res.WasSuccessful || !(res.Result?.Count > 0))
- return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<Velocity.Accounts.Velocity>>(res);
- List<Velocity.Accounts.Velocity> resultingAccounts = new List<Velocity.Accounts.Velocity>(res.Result.Count);
- resultingAccounts.AddRange(res.Result.Select(result => Velocity.Accounts.Velocity.Deserialize(Convert.FromBase64String(result.Account.Data[0]))));
- return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<Velocity.Accounts.Velocity>>(res, resultingAccounts);
- }
- public async Task<Solana.Unity.Programs.Models.AccountResultWrapper<Entity>> GetEntityAsync(string accountAddress, Commitment commitment = Commitment.Finalized)
- {
- var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment);
- if (!res.WasSuccessful)
- return new Solana.Unity.Programs.Models.AccountResultWrapper<Entity>(res);
- var resultingAccount = Entity.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0]));
- return new Solana.Unity.Programs.Models.AccountResultWrapper<Entity>(res, resultingAccount);
- }
- public async Task<Solana.Unity.Programs.Models.AccountResultWrapper<SessionToken>> GetSessionTokenAsync(string accountAddress, Commitment commitment = Commitment.Finalized)
- {
- var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment);
- if (!res.WasSuccessful)
- return new Solana.Unity.Programs.Models.AccountResultWrapper<SessionToken>(res);
- var resultingAccount = SessionToken.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0]));
- return new Solana.Unity.Programs.Models.AccountResultWrapper<SessionToken>(res, resultingAccount);
- }
- public async Task<Solana.Unity.Programs.Models.AccountResultWrapper<Velocity.Accounts.Velocity>> GetVelocityAsync(string accountAddress, Commitment commitment = Commitment.Finalized)
- {
- var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment);
- if (!res.WasSuccessful)
- return new Solana.Unity.Programs.Models.AccountResultWrapper<Velocity.Accounts.Velocity>(res);
- var resultingAccount = Velocity.Accounts.Velocity.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0]));
- return new Solana.Unity.Programs.Models.AccountResultWrapper<Velocity.Accounts.Velocity>(res, resultingAccount);
- }
- public async Task<SubscriptionState> SubscribeEntityAsync(string accountAddress, Action<SubscriptionState, Solana.Unity.Rpc.Messages.ResponseValue<Solana.Unity.Rpc.Models.AccountInfo>, Entity> callback, Commitment commitment = Commitment.Finalized)
- {
- SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) =>
- {
- Entity parsingResult = null;
- if (e.Value?.Data?.Count > 0)
- parsingResult = Entity.Deserialize(Convert.FromBase64String(e.Value.Data[0]));
- callback(s, e, parsingResult);
- }, commitment);
- return res;
- }
- public async Task<SubscriptionState> SubscribeSessionTokenAsync(string accountAddress, Action<SubscriptionState, Solana.Unity.Rpc.Messages.ResponseValue<Solana.Unity.Rpc.Models.AccountInfo>, SessionToken> callback, Commitment commitment = Commitment.Finalized)
- {
- SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) =>
- {
- SessionToken parsingResult = null;
- if (e.Value?.Data?.Count > 0)
- parsingResult = SessionToken.Deserialize(Convert.FromBase64String(e.Value.Data[0]));
- callback(s, e, parsingResult);
- }, commitment);
- return res;
- }
- public async Task<SubscriptionState> SubscribeVelocityAsync(string accountAddress, Action<SubscriptionState, Solana.Unity.Rpc.Messages.ResponseValue<Solana.Unity.Rpc.Models.AccountInfo>, Velocity.Accounts.Velocity> callback, Commitment commitment = Commitment.Finalized)
- {
- SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) =>
- {
- Velocity.Accounts.Velocity parsingResult = null;
- if (e.Value?.Data?.Count > 0)
- parsingResult = Velocity.Accounts.Velocity.Deserialize(Convert.FromBase64String(e.Value.Data[0]));
- callback(s, e, parsingResult);
- }, commitment);
- return res;
- }
- protected override Dictionary<uint, ProgramError<VelocityErrorKind>> BuildErrorsDictionary()
- {
- return new Dictionary<uint, ProgramError<VelocityErrorKind>>{};
- }
- }
- namespace Program
- {
- public class InitializeAccounts
- {
- public PublicKey Payer { get; set; }
- public PublicKey Data { get; set; }
- public PublicKey Entity { get; set; }
- public PublicKey Authority { get; set; }
- public PublicKey InstructionSysvarAccount { get; set; } = new PublicKey("Sysvar1nstructions1111111111111111111111111");
- public PublicKey SystemProgram { get; set; } = new PublicKey("11111111111111111111111111111111");
- }
- public class UpdateAccounts
- {
- public PublicKey BoltComponent { get; set; }
- public PublicKey Authority { get; set; }
- public PublicKey InstructionSysvarAccount { get; set; } = new PublicKey("Sysvar1nstructions1111111111111111111111111");
- public PublicKey SessionToken { get; set; }
- }
- public static class VelocityProgram
- {
- public const string ID = "CbHEFbSQdRN4Wnoby9r16umnJ1zWbULBHg4yqzGQonU1";
- public static Solana.Unity.Rpc.Models.TransactionInstruction Initialize(InitializeAccounts accounts, PublicKey programId = null)
- {
- programId ??= new(ID);
- List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
- {Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Payer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Data, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Entity, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Authority, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.InstructionSysvarAccount, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
- byte[] _data = new byte[1200];
- int offset = 0;
- _data.WriteU64(17121445590508351407UL, offset);
- offset += 8;
- byte[] resultData = new byte[offset];
- Array.Copy(_data, resultData, offset);
- return new Solana.Unity.Rpc.Models.TransactionInstruction{Keys = keys, ProgramId = programId.KeyBytes, Data = resultData};
- }
- public static Solana.Unity.Rpc.Models.TransactionInstruction Update(UpdateAccounts accounts, byte[] data, PublicKey programId = null)
- {
- programId ??= new(ID);
- List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
- {Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.BoltComponent, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Authority, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.InstructionSysvarAccount, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false)};
- byte[] _data = new byte[1200];
- int offset = 0;
- _data.WriteU64(9222597562720635099UL, offset);
- offset += 8;
- _data.WriteS32(data.Length, offset);
- offset += 4;
- _data.WriteSpan(data, offset);
- offset += data.Length;
- byte[] resultData = new byte[offset];
- Array.Copy(_data, resultData, offset);
- return new Solana.Unity.Rpc.Models.TransactionInstruction{Keys = keys, ProgramId = programId.KeyBytes, Data = resultData};
- }
- }
- }
- }
|