-
Notifications
You must be signed in to change notification settings - Fork 908
/
getTransaction.ts
249 lines (232 loc) · 8.96 KB
/
getTransaction.ts
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
import type { Address } from '@solana/addresses';
import type { Signature } from '@solana/keys';
import type { RpcApiMethods } from '@solana/rpc-spec';
import type {
Base58EncodedBytes,
Base58EncodedDataResponse,
Base64EncodedDataResponse,
Blockhash,
Commitment,
LamportsUnsafeBeyond2Pow53Minus1,
Reward,
Slot,
TokenBalance,
TransactionError,
TransactionStatus,
U64UnsafeBeyond2Pow53Minus1,
UnixTimestamp,
} from '@solana/rpc-types';
import type { TransactionVersion } from '@solana/transaction-messages';
type ReturnData = {
/** the return data itself */
data: Base64EncodedDataResponse;
/** the program that generated the return data */
programId: Address;
};
type TransactionMetaBase = Readonly<{
/** number of compute units consumed by the transaction */
computeUnitsConsumed?: U64UnsafeBeyond2Pow53Minus1;
/** Error if transaction failed, null if transaction succeeded. */
err: TransactionError | null;
/** fee this transaction was charged */
fee: LamportsUnsafeBeyond2Pow53Minus1;
/** array of string log messages or null if log message recording was not enabled during this transaction */
logMessages: readonly string[] | null;
/** array of account balances after the transaction was processed */
postBalances: readonly LamportsUnsafeBeyond2Pow53Minus1[];
/** List of token balances from after the transaction was processed or omitted if token balance recording was not yet enabled during this transaction */
postTokenBalances?: readonly TokenBalance[];
/** array of account balances from before the transaction was processed */
preBalances: readonly LamportsUnsafeBeyond2Pow53Minus1[];
/** List of token balances from before the transaction was processed or omitted if token balance recording was not yet enabled during this transaction */
preTokenBalances?: readonly TokenBalance[];
/** the most-recent return data generated by an instruction in the transaction */
returnData?: ReturnData;
/** transaction-level rewards */
rewards: readonly Reward[] | null;
/**
* Transaction status
* @deprecated
*/
status: TransactionStatus;
}>;
type AddressTableLookup = Readonly<{
/** public key for an address lookup table account. */
accountKey: Address;
/** List of indices used to load addresses of readonly accounts from a lookup table. */
readableIndexes: readonly number[];
/** List of indices used to load addresses of writable accounts from a lookup table. */
writableIndexes: readonly number[];
}>;
type TransactionBase = Readonly<{
message: {
recentBlockhash: Blockhash;
};
signatures: readonly Base58EncodedBytes[];
}>;
type TransactionInstruction = Readonly<{
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
}>;
type TransactionJson = Readonly<{
message: {
accountKeys: readonly Address[];
header: {
numReadonlySignedAccounts: number;
numReadonlyUnsignedAccounts: number;
numRequiredSignatures: number;
};
instructions: readonly TransactionInstruction[];
};
}> &
TransactionBase;
type PartiallyDecodedTransactionInstruction = Readonly<{
accounts: readonly Address[];
data: Base58EncodedBytes;
programId: Address;
}>;
type ParsedTransactionInstruction = Readonly<{
parsed: {
info?: object;
type: string;
};
program: string;
programId: Address;
}>;
type TransactionJsonParsed = Readonly<{
message: {
accountKeys: [
{
pubkey: Address;
signer: boolean;
source: string;
writable: boolean;
},
];
instructions: readonly (ParsedTransactionInstruction | PartiallyDecodedTransactionInstruction)[];
};
}> &
TransactionBase;
type GetTransactionCommonConfig<TMaxSupportedTransactionVersion> = Readonly<{
commitment?: Commitment;
maxSupportedTransactionVersion?: TMaxSupportedTransactionVersion;
}>;
type GetTransactionApiResponseBase = Readonly<{
/** estimated production time of when the transaction was processed. null if not available */
blockTime: UnixTimestamp | null;
/** the slot this transaction was processed in */
slot: Slot;
}>;
type TransactionMetaLoadedAddresses = Readonly<{
loadedAddresses: {
readonly: readonly Address[];
writable: readonly Address[];
};
}>;
type InnerInstructions<TInstructionType> = Readonly<{
index: number;
instructions: readonly TInstructionType[];
}>;
type TransactionMetaInnerInstructionsNotParsed = Readonly<{
innerInstructions?: readonly InnerInstructions<TransactionInstruction>[] | null;
}>;
type TransactionMetaInnerInstructionsParsed = Readonly<{
innerInstructions?:
| readonly InnerInstructions<ParsedTransactionInstruction | PartiallyDecodedTransactionInstruction>[]
| null;
}>;
type TransactionAddressTableLookups = Readonly<{
message: Readonly<{
addressTableLookups: readonly AddressTableLookup[];
}>;
}>;
export interface GetTransactionApi extends RpcApiMethods {
/**
* Returns transaction details for a confirmed transaction
*/
getTransaction<TMaxSupportedTransactionVersion extends TransactionVersion | void = void>(
signature: Signature,
config: GetTransactionCommonConfig<TMaxSupportedTransactionVersion> &
Readonly<{
encoding: 'jsonParsed';
}>,
):
| (GetTransactionApiResponseBase &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: { version: TransactionVersion }) & {
meta: (TransactionMetaBase & TransactionMetaInnerInstructionsParsed) | null;
transaction: TransactionJsonParsed &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: TransactionAddressTableLookups);
})
| null;
getTransaction<TMaxSupportedTransactionVersion extends TransactionVersion | void = void>(
signature: Signature,
config: GetTransactionCommonConfig<TMaxSupportedTransactionVersion> &
Readonly<{
encoding: 'base64';
}>,
):
| (GetTransactionApiResponseBase &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: { version: TransactionVersion }) & {
meta:
| (TransactionMetaBase &
TransactionMetaInnerInstructionsNotParsed &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: TransactionMetaLoadedAddresses))
| null;
transaction: Base64EncodedDataResponse;
})
| null;
getTransaction<TMaxSupportedTransactionVersion extends TransactionVersion | void = void>(
signature: Signature,
config: GetTransactionCommonConfig<TMaxSupportedTransactionVersion> &
Readonly<{
encoding: 'base58';
}>,
):
| (GetTransactionApiResponseBase &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: { version: TransactionVersion }) & {
meta:
| (TransactionMetaBase &
TransactionMetaInnerInstructionsNotParsed &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: TransactionMetaLoadedAddresses))
| null;
transaction: Base58EncodedDataResponse;
})
| null;
getTransaction<TMaxSupportedTransactionVersion extends TransactionVersion | void = void>(
signature: Signature,
config?: GetTransactionCommonConfig<TMaxSupportedTransactionVersion> &
Readonly<{
encoding?: 'json';
}>,
):
| (GetTransactionApiResponseBase &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: { version: TransactionVersion }) & {
meta:
| (TransactionMetaBase &
TransactionMetaInnerInstructionsNotParsed &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: TransactionMetaLoadedAddresses))
| null;
transaction: TransactionJson &
(TMaxSupportedTransactionVersion extends void
? Record<string, never>
: TransactionAddressTableLookups);
})
| null;
}