-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameIdl.cs
394 lines (325 loc) · 21.2 KB
/
GameIdl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
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 SolDungeons;
using SolDungeons.Program;
using SolDungeons.Errors;
using SolDungeons.Accounts;
namespace SolDungeons
{
namespace Accounts
{
public partial class User
{
public static ulong ACCOUNT_DISCRIMINATOR => 17022084798167872927UL;
public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{159, 117, 95, 227, 239, 151, 58, 236};
public static string ACCOUNT_DISCRIMINATOR_B58 => "TfwwBiNJtao";
public PublicKey Authority { get; set; }
public string Username { get; set; }
public byte CurrentCharacterId { get; set; }
public static User Deserialize(ReadOnlySpan<byte> _data)
{
int offset = 0;
ulong accountHashValue = _data.GetU64(offset);
offset += 8;
if (accountHashValue != ACCOUNT_DISCRIMINATOR)
{
return null;
}
User result = new User();
result.Authority = _data.GetPubKey(offset);
offset += 32;
offset += _data.GetBorshString(offset, out var resultUsername);
result.Username = resultUsername;
result.CurrentCharacterId = _data.GetU8(offset);
offset += 1;
return result;
}
}
public partial class UserCharacter
{
public static ulong ACCOUNT_DISCRIMINATOR => 6663967752651742160UL;
public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{208, 27, 119, 35, 93, 43, 123, 92};
public static string ACCOUNT_DISCRIMINATOR_B58 => "bouHCPMrFuu";
public byte MintId { get; set; }
public bool Locked { get; set; }
public ulong LastLockedTime { get; set; }
public static UserCharacter Deserialize(ReadOnlySpan<byte> _data)
{
int offset = 0;
ulong accountHashValue = _data.GetU64(offset);
offset += 8;
if (accountHashValue != ACCOUNT_DISCRIMINATOR)
{
return null;
}
UserCharacter result = new UserCharacter();
result.MintId = _data.GetU8(offset);
offset += 1;
result.Locked = _data.GetBool(offset);
offset += 1;
result.LastLockedTime = _data.GetU64(offset);
offset += 8;
return result;
}
}
}
namespace Errors
{
public enum SolDungeonsErrorKind : uint
{
WrongAuthority = 6000U
}
}
public partial class SolDungeonsClient : TransactionalBaseClient<SolDungeonsErrorKind>
{
public SolDungeonsClient(IRpcClient rpcClient, IStreamingRpcClient streamingRpcClient, PublicKey programId) : base(rpcClient, streamingRpcClient, programId)
{
}
public async Task<Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<User>>> GetUsersAsync(string programAddress, Commitment commitment = Commitment.Finalized)
{
var list = new List<Solana.Unity.Rpc.Models.MemCmp>{new Solana.Unity.Rpc.Models.MemCmp{Bytes = User.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<User>>(res);
List<User> resultingAccounts = new List<User>(res.Result.Count);
resultingAccounts.AddRange(res.Result.Select(result => User.Deserialize(Convert.FromBase64String(result.Account.Data[0]))));
return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<User>>(res, resultingAccounts);
}
public async Task<Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<UserCharacter>>> GetUserCharactersAsync(string programAddress, Commitment commitment = Commitment.Finalized)
{
var list = new List<Solana.Unity.Rpc.Models.MemCmp>{new Solana.Unity.Rpc.Models.MemCmp{Bytes = UserCharacter.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<UserCharacter>>(res);
List<UserCharacter> resultingAccounts = new List<UserCharacter>(res.Result.Count);
resultingAccounts.AddRange(res.Result.Select(result => UserCharacter.Deserialize(Convert.FromBase64String(result.Account.Data[0]))));
return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper<List<UserCharacter>>(res, resultingAccounts);
}
public async Task<Solana.Unity.Programs.Models.AccountResultWrapper<User>> GetUserAsync(string accountAddress, Commitment commitment = Commitment.Finalized)
{
var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment);
if (!res.WasSuccessful)
return new Solana.Unity.Programs.Models.AccountResultWrapper<User>(res);
var resultingAccount = User.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0]));
return new Solana.Unity.Programs.Models.AccountResultWrapper<User>(res, resultingAccount);
}
public async Task<Solana.Unity.Programs.Models.AccountResultWrapper<UserCharacter>> GetUserCharacterAsync(string accountAddress, Commitment commitment = Commitment.Finalized)
{
var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment);
if (!res.WasSuccessful)
return new Solana.Unity.Programs.Models.AccountResultWrapper<UserCharacter>(res);
var resultingAccount = UserCharacter.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0]));
return new Solana.Unity.Programs.Models.AccountResultWrapper<UserCharacter>(res, resultingAccount);
}
public async Task<SubscriptionState> SubscribeUserAsync(string accountAddress, Action<SubscriptionState, Solana.Unity.Rpc.Messages.ResponseValue<Solana.Unity.Rpc.Models.AccountInfo>, User> callback, Commitment commitment = Commitment.Finalized)
{
SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) =>
{
User parsingResult = null;
if (e.Value?.Data?.Count > 0)
parsingResult = User.Deserialize(Convert.FromBase64String(e.Value.Data[0]));
callback(s, e, parsingResult);
}, commitment);
return res;
}
public async Task<SubscriptionState> SubscribeUserCharacterAsync(string accountAddress, Action<SubscriptionState, Solana.Unity.Rpc.Messages.ResponseValue<Solana.Unity.Rpc.Models.AccountInfo>, UserCharacter> callback, Commitment commitment = Commitment.Finalized)
{
SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) =>
{
UserCharacter parsingResult = null;
if (e.Value?.Data?.Count > 0)
parsingResult = UserCharacter.Deserialize(Convert.FromBase64String(e.Value.Data[0]));
callback(s, e, parsingResult);
}, commitment);
return res;
}
public async Task<RequestResult<string>> SendInitializeUserAsync(InitializeUserAccounts accounts, string username, PublicKey feePayer, Func<byte[], PublicKey, byte[]> signingCallback, PublicKey programId)
{
Solana.Unity.Rpc.Models.TransactionInstruction instr = Program.SolDungeonsProgram.InitializeUser(accounts, username, programId);
return await SignAndSendTransaction(instr, feePayer, signingCallback);
}
public async Task<RequestResult<string>> SendUpdateUsernameAsync(UpdateUsernameAccounts accounts, string username, PublicKey feePayer, Func<byte[], PublicKey, byte[]> signingCallback, PublicKey programId)
{
Solana.Unity.Rpc.Models.TransactionInstruction instr = Program.SolDungeonsProgram.UpdateUsername(accounts, username, programId);
return await SignAndSendTransaction(instr, feePayer, signingCallback);
}
public async Task<RequestResult<string>> SendAssignPlayerCharacterAsync(AssignPlayerCharacterAccounts accounts, byte characterMintId, PublicKey feePayer, Func<byte[], PublicKey, byte[]> signingCallback, PublicKey programId)
{
Solana.Unity.Rpc.Models.TransactionInstruction instr = Program.SolDungeonsProgram.AssignPlayerCharacter(accounts, characterMintId, programId);
return await SignAndSendTransaction(instr, feePayer, signingCallback);
}
public async Task<RequestResult<string>> SendLockCurrentUserCharacterAsync(LockCurrentUserCharacterAccounts accounts, PublicKey feePayer, Func<byte[], PublicKey, byte[]> signingCallback, PublicKey programId)
{
Solana.Unity.Rpc.Models.TransactionInstruction instr = Program.SolDungeonsProgram.LockCurrentUserCharacter(accounts, programId);
return await SignAndSendTransaction(instr, feePayer, signingCallback);
}
public async Task<RequestResult<string>> SendAddTokenAsync(AddTokenAccounts accounts, ulong amount, PublicKey feePayer, Func<byte[], PublicKey, byte[]> signingCallback, PublicKey programId)
{
Solana.Unity.Rpc.Models.TransactionInstruction instr = Program.SolDungeonsProgram.AddToken(accounts, amount, programId);
return await SignAndSendTransaction(instr, feePayer, signingCallback);
}
public async Task<RequestResult<string>> SendReduceTokenAsync(ReduceTokenAccounts accounts, ulong amount, PublicKey feePayer, Func<byte[], PublicKey, byte[]> signingCallback, PublicKey programId)
{
Solana.Unity.Rpc.Models.TransactionInstruction instr = Program.SolDungeonsProgram.ReduceToken(accounts, amount, programId);
return await SignAndSendTransaction(instr, feePayer, signingCallback);
}
protected override Dictionary<uint, ProgramError<SolDungeonsErrorKind>> BuildErrorsDictionary()
{
return new Dictionary<uint, ProgramError<SolDungeonsErrorKind>>{{6000U, new ProgramError<SolDungeonsErrorKind>(SolDungeonsErrorKind.WrongAuthority, "Wrong Authority")}, };
}
}
namespace Program
{
public class InitializeUserAccounts
{
public PublicKey Signer { get; set; }
public PublicKey User { get; set; }
public PublicKey SystemProgram { get; set; }
}
public class UpdateUsernameAccounts
{
public PublicKey Signer { get; set; }
public PublicKey User { get; set; }
public PublicKey SessionToken { get; set; }
public PublicKey SystemProgram { get; set; }
}
public class AssignPlayerCharacterAccounts
{
public PublicKey Signer { get; set; }
public PublicKey User { get; set; }
public PublicKey UserCharacter { get; set; }
public PublicKey SessionToken { get; set; }
public PublicKey SystemProgram { get; set; }
}
public class LockCurrentUserCharacterAccounts
{
public PublicKey Signer { get; set; }
public PublicKey User { get; set; }
public PublicKey UserCharacter { get; set; }
public PublicKey SessionToken { get; set; }
public PublicKey SystemProgram { get; set; }
}
public class AddTokenAccounts
{
public PublicKey Signer { get; set; }
public PublicKey User { get; set; }
public PublicKey VaultPda { get; set; }
public PublicKey VaultAta { get; set; }
public PublicKey UserAta { get; set; }
public PublicKey GameToken { get; set; }
public PublicKey TokenProgram { get; set; }
public PublicKey SessionToken { get; set; }
public PublicKey AssociatedTokenProgram { get; set; }
public PublicKey SystemProgram { get; set; }
}
public class ReduceTokenAccounts
{
public PublicKey Signer { get; set; }
public PublicKey SignerWallet { get; set; }
public PublicKey User { get; set; }
public PublicKey VaultPda { get; set; }
public PublicKey VaultAta { get; set; }
public PublicKey UserAta { get; set; }
public PublicKey GameToken { get; set; }
public PublicKey TokenProgram { get; set; }
public PublicKey SessionToken { get; set; }
public PublicKey AssociatedTokenProgram { get; set; }
public PublicKey SystemProgram { get; set; }
}
public static class SolDungeonsProgram
{
public static Solana.Unity.Rpc.Models.TransactionInstruction InitializeUser(InitializeUserAccounts accounts, string username, PublicKey programId)
{
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Signer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.User, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
byte[] _data = new byte[1200];
int offset = 0;
_data.WriteU64(18313459337071759727UL, offset);
offset += 8;
offset += _data.WriteBorshString(username, offset);
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 UpdateUsername(UpdateUsernameAccounts accounts, string username, PublicKey programId)
{
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Signer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.User, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
byte[] _data = new byte[1200];
int offset = 0;
_data.WriteU64(18147365723531208681UL, offset);
offset += 8;
offset += _data.WriteBorshString(username, offset);
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 AssignPlayerCharacter(AssignPlayerCharacterAccounts accounts, byte characterMintId, PublicKey programId)
{
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Signer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.User, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.UserCharacter, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
byte[] _data = new byte[1200];
int offset = 0;
_data.WriteU64(18030146948214668928UL, offset);
offset += 8;
_data.WriteU8(characterMintId, offset);
offset += 1;
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 LockCurrentUserCharacter(LockCurrentUserCharacterAccounts accounts, PublicKey programId)
{
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Signer, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.User, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.UserCharacter, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
byte[] _data = new byte[1200];
int offset = 0;
_data.WriteU64(14638810002693361809UL, 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 AddToken(AddTokenAccounts accounts, ulong amount, PublicKey programId)
{
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Signer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.User, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.VaultPda, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.VaultAta, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.UserAta, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.GameToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.TokenProgram, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.AssociatedTokenProgram, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
byte[] _data = new byte[1200];
int offset = 0;
_data.WriteU64(3766188206372618221UL, offset);
offset += 8;
_data.WriteU64(amount, 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 ReduceToken(ReduceTokenAccounts accounts, ulong amount, PublicKey programId)
{
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Signer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.SignerWallet, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.User, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.VaultPda, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.VaultAta, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.UserAta, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.GameToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.TokenProgram, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.AssociatedTokenProgram, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
byte[] _data = new byte[1200];
int offset = 0;
_data.WriteU64(15217381811324258862UL, offset);
offset += 8;
_data.WriteU64(amount, 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};
}
}
}
}