Skip to content

Commit 603a7e5

Browse files
committed
Updated getTransaction to allow different response encodings & added support for loadedAddresses, rewards and dynamic version json types
Updated getTransaction to allow different response encodings & added support for loadedAddresses, rewards and dynamic version json types. Organized transaction models and gave them their own space. Addresses loaded from the AddressLookupTable will be found in loadedAddresses when retrieving versioned transactions
1 parent 93b7cbf commit 603a7e5

File tree

5 files changed

+421
-276
lines changed

5 files changed

+421
-276
lines changed

src/Solnet.Rpc/IRpcClient.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,10 @@ Task<RequestResult<ResponseValue<TokenBalance>>> GetTokenSupplyAsync(string toke
852852
/// <param name="signature">Transaction signature as base-58 encoded string.</param>
853853
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
854854
/// <param name="maxSupportedTransactionVersion">Max supported transaction version either LEGACY or 1</param>
855+
/// <param name="encoding"></param>
855856
/// <returns>Returns a task that holds the asynchronous operation result and state.</returns>
856857
Task<RequestResult<TransactionMetaSlotInfo>> GetTransactionAsync(string signature,
857-
Commitment commitment = Commitment.Finalized, int maxSupportedTransactionVersion = 0);
858+
Commitment commitment = Commitment.Finalized, int maxSupportedTransactionVersion = 0, string encoding = "json");
858859

859860
/// <summary>
860861
/// Returns transaction details for a confirmed transaction.
@@ -865,11 +866,12 @@ Task<RequestResult<TransactionMetaSlotInfo>> GetTransactionAsync(string signatur
865866
/// </para>
866867
/// </remarks>
867868
/// </summary>
868-
/// <param name="signature">Transaction signature as base-58 encoded string.</param>
869-
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
870-
/// <param name="maxSupportedTransactionVersion">Max supported transaction version either LEGACY or 1</param>
871-
/// <returns>Returns an object that wraps the result along with possible errors with the request.</returns>
872-
RequestResult<TransactionMetaSlotInfo> GetTransaction(string signature, Commitment commitment = Commitment.Finalized, int maxSupportedTransactionVersion = 0);
869+
/// <param name="signature"></param>
870+
/// <param name="commitment"></param>
871+
/// <param name="maxSupportedTransactionVersion"></param>
872+
/// <param name="encoding"></param>
873+
/// <returns>Returns a task that holds the asynchronous operation result and state.</returns>
874+
RequestResult<TransactionMetaSlotInfo> GetTransaction(string signature, Commitment commitment = Commitment.Finalized, int maxSupportedTransactionVersion = 0, string encoding = "json");
873875

874876
/// <summary>
875877
/// Gets the total transaction count of the ledger.

src/Solnet.Rpc/Models/Block.cs

-267
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// ReSharper disable UnusedAutoPropertyAccessor.Global
2-
// ReSharper disable ClassNeverInstantiated.Global
3-
4-
using System.Text.Json.Serialization;
5-
61
namespace Solnet.Rpc.Models
72
{
83
/// <summary>
@@ -55,268 +50,6 @@ public class BlockInfo
5550
public TransactionMetaInfo[] Transactions { get; set; }
5651
}
5752

58-
/// <summary>
59-
/// Represents the transaction, metadata and its containing slot.
60-
/// </summary>
61-
public class TransactionMetaSlotInfo : TransactionMetaInfo
62-
{
63-
/// <summary>
64-
/// The slot this transaction was processed in.
65-
/// </summary>
66-
public ulong Slot { get; set; }
67-
68-
/// <summary>
69-
/// Estimated block production time.
70-
/// </summary>
71-
public long? BlockTime { get; set; }
72-
}
73-
74-
75-
/// <summary>
76-
/// Represents the tuple transaction and metadata.
77-
/// </summary>
78-
public class TransactionMetaInfo
79-
{
80-
/// <summary>
81-
/// The transaction information.
82-
/// </summary>
83-
public TransactionInfo Transaction { get; set; }
84-
85-
/// <summary>
86-
/// The metadata information.
87-
/// </summary>
88-
public TransactionMeta Meta { get; set; }
89-
}
90-
91-
/// <summary>
92-
/// Represents the reward information related to a given account.
93-
/// </summary>
94-
public class RewardInfo
95-
{
96-
/// <summary>
97-
/// The account pubkey as base58 encoded string.
98-
/// </summary>
99-
public string Pubkey { get; set; }
100-
/// <summary>
101-
/// Number of reward lamports credited or debited by the account.
102-
/// </summary>
103-
public long Lamports { get; set; }
104-
105-
/// <summary>
106-
/// Account balance in lamports after the reward was applied.
107-
/// </summary>
108-
public ulong PostBalance { get; set; }
109-
110-
/// <summary>
111-
/// Type of the reward.
112-
/// </summary>
113-
public RewardType RewardType { get; set; }
114-
}
115-
116-
/// <summary>
117-
/// The type of the reward.
118-
/// </summary>
119-
public enum RewardType
120-
{
121-
/// <summary>
122-
/// Default value in case the returned value is undefined.
123-
/// </summary>
124-
Unknown,
125-
126-
/// <summary>
127-
/// Fee reward.
128-
/// </summary>
129-
Fee,
130-
131-
/// <summary>
132-
/// Rent reward.
133-
/// </summary>
134-
Rent,
135-
136-
/// <summary>
137-
/// Voting reward.
138-
/// </summary>
139-
Voting,
140-
141-
/// <summary>
142-
/// Staking reward.
143-
/// </summary>
144-
Staking
145-
}
146-
147-
/// <summary>
148-
/// Represents a transaction.
149-
/// </summary>
150-
public class TransactionInfo
151-
{
152-
/// <summary>
153-
/// The signatures of this transaction.
154-
/// </summary>
155-
public string[] Signatures { get; set; }
156-
157-
/// <summary>
158-
/// The message contents of the transaction.
159-
/// </summary>
160-
public TransactionContentInfo Message { get; set; }
161-
}
162-
163-
/// <summary>
164-
/// Represents the contents of the trasaction.
165-
/// </summary>
166-
public class TransactionContentInfo
167-
{
168-
/// <summary>
169-
/// List of base-58 encoded public keys used by the transaction, including by the instructions and for signatures.
170-
/// </summary>
171-
public string[] AccountKeys { get; set; }
172-
173-
/// <summary>
174-
/// Details the account types and signatures required by the transaction.
175-
/// </summary>
176-
public TransactionHeaderInfo Header { get; set; }
177-
178-
/// <summary>
179-
/// A base-58 encoded hash of a recent block in the ledger used to prevent transaction duplication and to give transactions lifetimes.
180-
/// </summary>
181-
public string RecentBlockhash { get; set; }
182-
183-
/// <summary>
184-
/// List of program instructions that will be executed in sequence and committed in one atomic transaction if all succeed.
185-
/// </summary>
186-
public InstructionInfo[] Instructions { get; set; }
187-
}
188-
189-
/// <summary>
190-
/// Details the number and type of accounts and signatures in a given transaction.
191-
/// </summary>
192-
public class TransactionHeaderInfo
193-
{
194-
/// <summary>
195-
/// The total number of signatures required to make the transaction valid.
196-
/// </summary>
197-
public int NumRequiredSignatures { get; set; }
198-
199-
/// <summary>
200-
/// The last NumReadonlySignedAccounts of the signed keys are read-only accounts.
201-
/// </summary>
202-
public int NumReadonlySignedAccounts { get; set; }
203-
204-
/// <summary>
205-
/// The last NumReadonlyUnsignedAccounts of the unsigned keys are read-only accounts.
206-
/// </summary>
207-
public int NumReadonlyUnsignedAccounts { get; set; }
208-
}
209-
210-
/// <summary>
211-
/// Represents the transaction metadata.
212-
/// </summary>
213-
public class TransactionMeta
214-
{
215-
/// <summary>
216-
/// Possible transaction error.
217-
/// </summary>
218-
[JsonPropertyName("err")]
219-
public TransactionError Error { get; set; }
220-
221-
/// <summary>
222-
/// Fee this transaction was charged.
223-
/// </summary>
224-
public ulong Fee { get; set; }
225-
226-
/// <summary>
227-
/// Collection of account balances from before the transaction was processed.
228-
/// </summary>
229-
public ulong[] PreBalances { get; set; }
230-
231-
/// <summary>
232-
/// Collection of account balances after the transaction was processed.
233-
/// </summary>
234-
public ulong[] PostBalances { get; set; }
235-
236-
/// <summary>
237-
/// List of inner instructions or omitted if inner instruction recording was not yet enabled during this transaction.
238-
/// </summary>
239-
public InnerInstruction[] InnerInstructions { get; set; }
240-
241-
/// <summary>
242-
/// List of token balances from before the transaction was processed or omitted if token balance recording was not yet enabled during this transaction.
243-
/// </summary>
244-
public TokenBalanceInfo[] PreTokenBalances { get; set; }
245-
246-
/// <summary>
247-
/// List of token balances from after the transaction was processed or omitted if token balance recording was not yet enabled during this transaction.
248-
/// </summary>
249-
public TokenBalanceInfo[] PostTokenBalances { get; set; }
250-
251-
/// <summary>
252-
/// Array of string log messages or omitted if log message recording was not yet enabled during this transaction.
253-
/// </summary>
254-
public string[] LogMessages { get; set; }
255-
}
256-
257-
/// <summary>
258-
/// Represents the structure of a token balance metadata for a transaction.
259-
/// </summary>
260-
public class TokenBalanceInfo
261-
{
262-
/// <summary>
263-
/// Index of the account in which the token balance is provided for.
264-
/// </summary>
265-
public int AccountIndex { get; set; }
266-
267-
/// <summary>
268-
/// Pubkey of the token's mint.
269-
/// </summary>
270-
public string Mint { get; set; }
271-
272-
/// <summary>
273-
/// Pubkey of the token owner
274-
/// </summary>
275-
public string Owner { get; set; }
276-
277-
/// <summary>
278-
/// Token balance details.
279-
/// </summary>
280-
public TokenBalance UiTokenAmount { get; set; }
281-
}
282-
283-
/// <summary>
284-
/// Represents an inner instruction. Inner instruction are cross-program instructions that are invoked during transaction processing.
285-
/// </summary>
286-
public class InnerInstruction
287-
{
288-
/// <summary>
289-
/// Index of the transaction instruction from which the inner instruction(s) originated
290-
/// </summary>
291-
public int Index { get; set; }
292-
293-
/// <summary>
294-
/// List of program instructions that will be executed in sequence and committed in one atomic transaction if all succeed.
295-
/// </summary>
296-
public InstructionInfo[] Instructions { get; set; }
297-
}
298-
299-
/// <summary>
300-
/// Represents the data of given instruction.
301-
/// </summary>
302-
public class InstructionInfo
303-
{
304-
/// <summary>
305-
/// Index into the <i>Message.AccountKeys</i> array indicating the program account that executes this instruction.
306-
/// </summary>
307-
public int ProgramIdIndex { get; set; }
308-
309-
/// <summary>
310-
/// List of ordered indices into the <i>Message.AccountKeys</i> array indicating which accounts to pass to the program.
311-
/// </summary>
312-
public int[] Accounts { get; set; }
313-
314-
/// <summary>
315-
/// The program input data encoded in a base-58 string.
316-
/// </summary>
317-
public string Data { get; set; }
318-
}
319-
32053
/// <summary>
32154
/// Represents the block commitment info.
32255
/// </summary>

src/Solnet.Rpc/Models/RewardInfo.cs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace Solnet.Rpc.Models
2+
{
3+
/// <summary>
4+
/// Represents the reward information related to a given account.
5+
/// </summary>
6+
public class RewardInfo
7+
{
8+
/// <summary>
9+
/// The account pubkey as base58 encoded string.
10+
/// </summary>
11+
public string Pubkey { get; set; }
12+
/// <summary>
13+
/// Number of reward lamports credited or debited by the account.
14+
/// </summary>
15+
public long Lamports { get; set; }
16+
17+
/// <summary>
18+
/// Account balance in lamports after the reward was applied.
19+
/// </summary>
20+
public ulong PostBalance { get; set; }
21+
22+
}
23+
24+
/// <summary>
25+
/// The type of the reward.
26+
/// </summary>
27+
public enum RewardType
28+
{
29+
/// <summary>
30+
/// Default value in case the returned value is undefined.
31+
/// </summary>
32+
Unknown,
33+
34+
/// <summary>
35+
/// Fee reward.
36+
/// </summary>
37+
Fee,
38+
39+
/// <summary>
40+
/// Rent reward.
41+
/// </summary>
42+
Rent,
43+
44+
/// <summary>
45+
/// Voting reward.
46+
/// </summary>
47+
Voting,
48+
49+
/// <summary>
50+
/// Staking reward.
51+
/// </summary>
52+
Staking
53+
}
54+
}

0 commit comments

Comments
 (0)