near-api-js 7.0.0-rc.1 → 7.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accounts/account.d.ts +27 -22
- package/lib/accounts/account.js +46 -14
- package/lib/accounts/nonce-manager.d.ts +9 -0
- package/lib/accounts/nonce-manager.js +43 -0
- package/lib/providers/errors/contract_execution.d.ts +152 -0
- package/lib/providers/errors/contract_execution.js +230 -0
- package/lib/providers/errors/handler.d.ts +121 -0
- package/lib/providers/errors/handler.js +182 -0
- package/lib/providers/errors/parse.d.ts +11 -0
- package/lib/providers/errors/parse.js +607 -0
- package/lib/providers/errors/request_validation.d.ts +9 -0
- package/lib/providers/errors/request_validation.js +11 -0
- package/lib/providers/errors/rpc.d.ts +5 -0
- package/lib/providers/errors/rpc.js +8 -0
- package/lib/providers/errors/transaction_execution.d.ts +306 -0
- package/lib/providers/errors/transaction_execution.js +457 -0
- package/lib/providers/failover-rpc-provider.d.ts +44 -38
- package/lib/providers/failover-rpc-provider.js +10 -11
- package/lib/providers/fetch_json.d.ts +2 -8
- package/lib/providers/fetch_json.js +0 -3
- package/lib/providers/json-rpc-provider.d.ts +75 -37
- package/lib/providers/json-rpc-provider.js +123 -60
- package/lib/providers/methods.d.ts +163 -0
- package/lib/providers/methods.js +1 -0
- package/lib/providers/provider.d.ts +49 -29
- package/lib/rpc/index.d.ts +1 -0
- package/lib/rpc/index.js +2 -0
- package/lib/rpc/types.gen.d.ts +6120 -0
- package/lib/rpc/types.gen.js +47 -0
- package/lib/seed-phrase/index.d.ts +6 -0
- package/lib/seed-phrase/index.js +13 -0
- package/lib/types/provider/response.d.ts +2 -2
- package/lib/utils/provider.d.ts +2 -1
- package/lib/utils/provider.js +4 -1
- package/package.json +10 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type KeyPairString, PublicKey } from '../crypto/index.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type Provider } from '../providers/index.js';
|
|
3
3
|
import { type SignedMessage, type Signer } from '../signers/index.js';
|
|
4
4
|
import type { SignDelegateActionReturn } from '../signers/signer.js';
|
|
5
5
|
import type { FungibleToken, NativeToken } from '../tokens/index.js';
|
|
6
6
|
import { type Action, type DelegateAction, type SignedTransaction } from '../transactions/index.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { FinalExecutionOutcome, SerializedReturnValue, TxExecutionStatus } from '../types/index.js';
|
|
8
8
|
export declare const DEFAULT_WAIT_STATUS: TxExecutionStatus;
|
|
9
9
|
export interface AccountState {
|
|
10
10
|
balance: {
|
|
@@ -44,6 +44,7 @@ export interface SignAndSendTransactionArgs {
|
|
|
44
44
|
waitUntil?: TxExecutionStatus;
|
|
45
45
|
throwOnFailure?: boolean;
|
|
46
46
|
signer?: Signer;
|
|
47
|
+
retries?: number;
|
|
47
48
|
}
|
|
48
49
|
export interface SignAndSendTransactionsArgs {
|
|
49
50
|
transactions: Array<{
|
|
@@ -99,7 +100,8 @@ export declare class Account {
|
|
|
99
100
|
readonly accountId: string;
|
|
100
101
|
readonly provider: Provider;
|
|
101
102
|
private signer?;
|
|
102
|
-
|
|
103
|
+
private readonly nonceManager;
|
|
104
|
+
constructor(accountId: string, provider: Provider | string, signer?: Signer | KeyPairString);
|
|
103
105
|
/**
|
|
104
106
|
* Allows to set the signer used to control the account
|
|
105
107
|
*
|
|
@@ -116,21 +118,27 @@ export declare class Account {
|
|
|
116
118
|
* Calls {@link Provider.viewAccessKey} to retrieve information for a
|
|
117
119
|
* specific key in the account
|
|
118
120
|
*/
|
|
119
|
-
getAccessKey(publicKey: PublicKey | string): Promise<AccessKeyView>;
|
|
121
|
+
getAccessKey(publicKey: PublicKey | string): Promise<import("../types/index.js").AccessKeyView>;
|
|
120
122
|
/**
|
|
121
123
|
* Calls {@link Provider.viewAccessKeyList} to retrieve the account's keys
|
|
122
124
|
*/
|
|
123
|
-
getAccessKeyList(): Promise<AccessKeyList
|
|
125
|
+
getAccessKeyList(): Promise<import("../rpc/types.gen.js").AccessKeyList & {
|
|
126
|
+
block_hash: import("../rpc/types.gen.js").CryptoHash;
|
|
127
|
+
block_height: number;
|
|
128
|
+
}>;
|
|
124
129
|
/**
|
|
125
130
|
* Calls {@link Provider.viewContractCode} to retrieve the account's
|
|
126
131
|
* contract code and its hash
|
|
127
132
|
*/
|
|
128
|
-
getContractCode(): Promise<ContractCodeView>;
|
|
133
|
+
getContractCode(): Promise<import("../types/index.js").ContractCodeView>;
|
|
129
134
|
/**
|
|
130
135
|
* Calls {@link Provider.viewContractState} to retrieve the keys and values
|
|
131
136
|
* stored on the account's contract
|
|
132
137
|
*/
|
|
133
|
-
getContractState(prefix?: string): Promise<
|
|
138
|
+
getContractState(prefix?: string): Promise<import("../rpc/types.gen.js").ViewStateResult & {
|
|
139
|
+
block_hash: import("../rpc/types.gen.js").CryptoHash;
|
|
140
|
+
block_height: number;
|
|
141
|
+
}>;
|
|
134
142
|
/**
|
|
135
143
|
* Create a transaction that can be later signed with a {@link Signer}
|
|
136
144
|
*
|
|
@@ -168,8 +176,8 @@ export declare class Account {
|
|
|
168
176
|
* @returns {Promise<FinalExecutionOutcome>} A promise that resolves to the final execution outcome of the transaction.
|
|
169
177
|
*
|
|
170
178
|
*/
|
|
171
|
-
signAndSendTransaction({ receiverId, actions, waitUntil, throwOnFailure, signer, }: SignAndSendTransactionArgs):
|
|
172
|
-
signAndSendTransactions({ transactions, waitUntil, throwOnFailure, signer, }: SignAndSendTransactionsArgs): Promise<
|
|
179
|
+
signAndSendTransaction({ receiverId, actions, waitUntil, throwOnFailure, signer, retries, }: SignAndSendTransactionArgs): any;
|
|
180
|
+
signAndSendTransactions({ transactions, waitUntil, throwOnFailure, signer, }: SignAndSendTransactionsArgs): Promise<any[]>;
|
|
173
181
|
/**
|
|
174
182
|
* Creates a new NEAR account with a given ID and public key.
|
|
175
183
|
*
|
|
@@ -186,7 +194,7 @@ export declare class Account {
|
|
|
186
194
|
* @param nearToTransfer how much NEAR to transfer to the account in yoctoNEAR (default: 0)
|
|
187
195
|
*
|
|
188
196
|
*/
|
|
189
|
-
createAccount({ newAccountId, publicKey, nearToTransfer
|
|
197
|
+
createAccount({ newAccountId, publicKey, nearToTransfer }: CreateAccountArgs): Promise<any>;
|
|
190
198
|
/**
|
|
191
199
|
* Creates a sub account of this account. For example, if the account is
|
|
192
200
|
* ana.near, you can create sub.ana.near.
|
|
@@ -196,7 +204,7 @@ export declare class Account {
|
|
|
196
204
|
* @param nearToTransfer how much NEAR to transfer to the account (default: 0)
|
|
197
205
|
*
|
|
198
206
|
*/
|
|
199
|
-
createSubAccount({ accountOrPrefix, publicKey, nearToTransfer
|
|
207
|
+
createSubAccount({ accountOrPrefix, publicKey, nearToTransfer }: CreateSubAccountArgs): Promise<any>;
|
|
200
208
|
/**
|
|
201
209
|
* Deletes the account, transferring all remaining NEAR to a beneficiary
|
|
202
210
|
* account
|
|
@@ -205,20 +213,20 @@ export declare class Account {
|
|
|
205
213
|
*
|
|
206
214
|
* @param beneficiaryId Will receive the account's remaining balance
|
|
207
215
|
*/
|
|
208
|
-
deleteAccount(beneficiaryId: string): Promise<
|
|
216
|
+
deleteAccount(beneficiaryId: string): Promise<any>;
|
|
209
217
|
/**
|
|
210
218
|
* Deploy a smart contract in the account
|
|
211
219
|
*
|
|
212
220
|
* @param code The compiled contract code bytes
|
|
213
221
|
*/
|
|
214
|
-
deployContract(code: Uint8Array): Promise<
|
|
222
|
+
deployContract(code: Uint8Array): Promise<any>;
|
|
215
223
|
/**
|
|
216
224
|
* Deploy a global contract that can be reused by multiple accounts
|
|
217
225
|
*
|
|
218
226
|
* @param code The compiled contract code bytes
|
|
219
227
|
* @param deployMode Deploy mode - "codeHash" for immutable contracts, "accountId" for updateable contracts
|
|
220
228
|
*/
|
|
221
|
-
deployGlobalContract(code: Uint8Array, deployMode: 'codeHash' | 'accountId'): Promise<
|
|
229
|
+
deployGlobalContract(code: Uint8Array, deployMode: 'codeHash' | 'accountId'): Promise<any>;
|
|
222
230
|
/**
|
|
223
231
|
* Use a previously deployed global contract on this account
|
|
224
232
|
*
|
|
@@ -228,7 +236,7 @@ export declare class Account {
|
|
|
228
236
|
accountId: string;
|
|
229
237
|
} | {
|
|
230
238
|
codeHash: string | Uint8Array;
|
|
231
|
-
}): Promise<
|
|
239
|
+
}): Promise<any>;
|
|
232
240
|
/**
|
|
233
241
|
*
|
|
234
242
|
* @param options
|
|
@@ -238,19 +246,17 @@ export declare class Account {
|
|
|
238
246
|
* @param options.allowance The amount of NEAR this key can expend in gas
|
|
239
247
|
* @returns
|
|
240
248
|
*/
|
|
241
|
-
addFunctionCallAccessKey({ publicKey, contractId, methodNames, allowance, }: AddFunctionAccessKeyArgs): Promise<
|
|
249
|
+
addFunctionCallAccessKey({ publicKey, contractId, methodNames, allowance, }: AddFunctionAccessKeyArgs): Promise<any>;
|
|
242
250
|
/**
|
|
243
251
|
* Add a full access key to the account
|
|
244
252
|
*
|
|
245
253
|
* @param publicKey The public key to be added
|
|
246
|
-
* @returns {Promise<FinalExecutionOutcome>}
|
|
247
254
|
*/
|
|
248
|
-
addFullAccessKey(publicKey: PublicKey | string): Promise<
|
|
255
|
+
addFullAccessKey(publicKey: PublicKey | string): Promise<any>;
|
|
249
256
|
/**
|
|
250
257
|
* @param publicKey The public key to be deleted
|
|
251
|
-
* @returns {Promise<FinalExecutionOutcome>}
|
|
252
258
|
*/
|
|
253
|
-
deleteKey(publicKey: PublicKey | string): Promise<
|
|
259
|
+
deleteKey(publicKey: PublicKey | string): Promise<any>;
|
|
254
260
|
/**
|
|
255
261
|
* Call a function on a smart contract and return parsed transaction result
|
|
256
262
|
*
|
|
@@ -274,9 +280,8 @@ export declare class Account {
|
|
|
274
280
|
* @param options.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
|
|
275
281
|
* @param options.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
|
|
276
282
|
* @param options.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
|
|
277
|
-
* @returns {FinalExecutionOutcome}
|
|
278
283
|
*/
|
|
279
|
-
callFunctionRaw({ contractId, methodName, args, deposit, gas, waitUntil, }: CallFunctionArgs): Promise<
|
|
284
|
+
callFunctionRaw({ contractId, methodName, args, deposit, gas, waitUntil, }: CallFunctionArgs): Promise<any>;
|
|
280
285
|
/**
|
|
281
286
|
* This function simply calls the `signNep413Message` method of the Signer
|
|
282
287
|
*
|
package/lib/accounts/account.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { PublicKey } from '../crypto/index.js';
|
|
2
|
+
import { parseTransactionExecutionError } from '../providers/errors/parse.js';
|
|
3
|
+
import { InvalidNonceError } from '../providers/errors/transaction_execution.js';
|
|
4
|
+
import { JsonRpcProvider } from '../providers/index.js';
|
|
2
5
|
import { KeyPairSigner } from '../signers/index.js';
|
|
3
6
|
import { NEAR } from '../tokens/index.js';
|
|
4
7
|
import { actionCreators, buildDelegateAction, createTransaction, GlobalContractDeployMode, GlobalContractIdentifier, } from '../transactions/index.js';
|
|
5
|
-
import { baseDecode, getTransactionLastResult
|
|
8
|
+
import { baseDecode, getTransactionLastResult } from '../utils/index.js';
|
|
9
|
+
import { NonceManager } from './nonce-manager.js';
|
|
6
10
|
const { addKey, createAccount, deleteAccount, deleteKey, deployContract, deployGlobalContract, fullAccessKey, functionCall, functionCallAccessKey, transfer, useGlobalContract, } = actionCreators;
|
|
7
11
|
const DEFAULT_FINALITY = 'optimistic';
|
|
8
12
|
export const DEFAULT_WAIT_STATUS = 'EXECUTED_OPTIMISTIC';
|
|
@@ -16,13 +20,19 @@ const DEFAULT_FUNCTION_CALL_GAS = 30000000000000n; // 30 TGas
|
|
|
16
20
|
export class Account {
|
|
17
21
|
constructor(accountId, provider, signer) {
|
|
18
22
|
this.accountId = accountId;
|
|
19
|
-
|
|
23
|
+
if (typeof provider === 'string') {
|
|
24
|
+
this.provider = new JsonRpcProvider({ url: provider });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.provider = provider;
|
|
28
|
+
}
|
|
20
29
|
if (typeof signer === 'string') {
|
|
21
30
|
this.signer = KeyPairSigner.fromSecretKey(signer);
|
|
22
31
|
}
|
|
23
32
|
else {
|
|
24
33
|
this.signer = signer;
|
|
25
34
|
}
|
|
35
|
+
this.nonceManager = new NonceManager();
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
28
38
|
* Allows to set the signer used to control the account
|
|
@@ -51,6 +61,10 @@ export class Account {
|
|
|
51
61
|
},
|
|
52
62
|
}),
|
|
53
63
|
]);
|
|
64
|
+
if (typeof protocolConfig.runtime_config !== 'object' || protocolConfig.runtime_config === null)
|
|
65
|
+
throw new Error('runtime_config is not defined in protocol config');
|
|
66
|
+
if (typeof protocolConfig.runtime_config.storage_amount_per_byte === 'undefined')
|
|
67
|
+
throw new Error('runtime_config.storage_amount_per_byte is not defined in protocol config');
|
|
54
68
|
const costPerByte = BigInt(protocolConfig.runtime_config.storage_amount_per_byte);
|
|
55
69
|
const usedOnStorage = BigInt(state.storage_usage) * costPerByte;
|
|
56
70
|
const locked = BigInt(state.locked);
|
|
@@ -127,15 +141,14 @@ export class Account {
|
|
|
127
141
|
if (!publicKey)
|
|
128
142
|
throw new Error('Please provide a public key');
|
|
129
143
|
const pk = PublicKey.from(publicKey);
|
|
130
|
-
const [
|
|
131
|
-
this.
|
|
144
|
+
const [nonce, block] = await Promise.all([
|
|
145
|
+
this.nonceManager.resolveNextNonce(pk, this.accountId, this.provider),
|
|
132
146
|
this.provider.viewBlock({
|
|
133
147
|
finality: DEFAULT_FINALITY,
|
|
134
148
|
}),
|
|
135
149
|
]);
|
|
136
150
|
const recentBlockHash = block.header.hash;
|
|
137
|
-
|
|
138
|
-
return createTransaction(this.accountId, pk, receiverId, nonce + 1n, actions, baseDecode(recentBlockHash));
|
|
151
|
+
return createTransaction(this.accountId, pk, receiverId, nonce, actions, baseDecode(recentBlockHash));
|
|
139
152
|
}
|
|
140
153
|
/**
|
|
141
154
|
* Create a signed transaction ready to be broadcast by a {@link Provider}
|
|
@@ -206,18 +219,40 @@ export class Account {
|
|
|
206
219
|
* @returns {Promise<FinalExecutionOutcome>} A promise that resolves to the final execution outcome of the transaction.
|
|
207
220
|
*
|
|
208
221
|
*/
|
|
209
|
-
async signAndSendTransaction({ receiverId, actions, waitUntil = DEFAULT_WAIT_STATUS, throwOnFailure = true, signer = this.signer, }) {
|
|
222
|
+
async signAndSendTransaction({ receiverId, actions, waitUntil = DEFAULT_WAIT_STATUS, throwOnFailure = true, signer = this.signer, retries = 3, }) {
|
|
210
223
|
const signedTx = await this.createSignedTransaction({
|
|
211
224
|
receiverId,
|
|
212
225
|
actions,
|
|
213
226
|
signer,
|
|
214
227
|
});
|
|
215
|
-
|
|
228
|
+
let result;
|
|
229
|
+
try {
|
|
230
|
+
result = await this.provider.sendTransactionUntil(signedTx, waitUntil);
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
if (error instanceof InvalidNonceError) {
|
|
234
|
+
// invalidate nonce cache so we don't send another transaction with stale nonce
|
|
235
|
+
await this.nonceManager.invalidate(signedTx.transaction.publicKey);
|
|
236
|
+
if (retries > 0) {
|
|
237
|
+
return this.signAndSendTransaction({
|
|
238
|
+
receiverId,
|
|
239
|
+
actions,
|
|
240
|
+
waitUntil,
|
|
241
|
+
throwOnFailure,
|
|
242
|
+
signer,
|
|
243
|
+
retries: retries - 1,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
216
249
|
if (throwOnFailure &&
|
|
217
250
|
typeof result.status === 'object' &&
|
|
251
|
+
result.status !== null &&
|
|
252
|
+
'Failure' in result.status &&
|
|
218
253
|
typeof result.status.Failure === 'object' &&
|
|
219
254
|
result.status.Failure !== null) {
|
|
220
|
-
throw
|
|
255
|
+
throw parseTransactionExecutionError(result.status.Failure, result.transaction_outcome.id, result.transaction_outcome.block_hash);
|
|
221
256
|
}
|
|
222
257
|
return result;
|
|
223
258
|
}
|
|
@@ -251,7 +286,7 @@ export class Account {
|
|
|
251
286
|
* @param nearToTransfer how much NEAR to transfer to the account in yoctoNEAR (default: 0)
|
|
252
287
|
*
|
|
253
288
|
*/
|
|
254
|
-
async createAccount({ newAccountId, publicKey, nearToTransfer = 0n
|
|
289
|
+
async createAccount({ newAccountId, publicKey, nearToTransfer = 0n }) {
|
|
255
290
|
if (newAccountId.endsWith(this.accountId)) {
|
|
256
291
|
return this.createSubAccount({ accountOrPrefix: newAccountId, publicKey, nearToTransfer });
|
|
257
292
|
}
|
|
@@ -279,7 +314,7 @@ export class Account {
|
|
|
279
314
|
* @param nearToTransfer how much NEAR to transfer to the account (default: 0)
|
|
280
315
|
*
|
|
281
316
|
*/
|
|
282
|
-
async createSubAccount({ accountOrPrefix, publicKey, nearToTransfer = 0n
|
|
317
|
+
async createSubAccount({ accountOrPrefix, publicKey, nearToTransfer = 0n }) {
|
|
283
318
|
if (!this.signer)
|
|
284
319
|
throw new Error('Please set a signer');
|
|
285
320
|
const newAccountId = accountOrPrefix.includes('.') ? accountOrPrefix : `${accountOrPrefix}.${this.accountId}`;
|
|
@@ -380,7 +415,6 @@ export class Account {
|
|
|
380
415
|
* Add a full access key to the account
|
|
381
416
|
*
|
|
382
417
|
* @param publicKey The public key to be added
|
|
383
|
-
* @returns {Promise<FinalExecutionOutcome>}
|
|
384
418
|
*/
|
|
385
419
|
async addFullAccessKey(publicKey) {
|
|
386
420
|
return this.signAndSendTransaction({
|
|
@@ -390,7 +424,6 @@ export class Account {
|
|
|
390
424
|
}
|
|
391
425
|
/**
|
|
392
426
|
* @param publicKey The public key to be deleted
|
|
393
|
-
* @returns {Promise<FinalExecutionOutcome>}
|
|
394
427
|
*/
|
|
395
428
|
async deleteKey(publicKey) {
|
|
396
429
|
return this.signAndSendTransaction({
|
|
@@ -424,7 +457,6 @@ export class Account {
|
|
|
424
457
|
* @param options.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
|
|
425
458
|
* @param options.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
|
|
426
459
|
* @param options.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
|
|
427
|
-
* @returns {FinalExecutionOutcome}
|
|
428
460
|
*/
|
|
429
461
|
async callFunctionRaw({ contractId, methodName, args = {}, deposit = 0n, gas = DEFAULT_FUNCTION_CALL_GAS, waitUntil = DEFAULT_WAIT_STATUS, }) {
|
|
430
462
|
return await this.signAndSendTransaction({
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PublicKey } from '../crypto/public_key.js';
|
|
2
|
+
import type { Provider } from '../providers/provider.js';
|
|
3
|
+
export declare class NonceManager {
|
|
4
|
+
private nonces;
|
|
5
|
+
private locks;
|
|
6
|
+
constructor();
|
|
7
|
+
resolveNextNonce(pk: PublicKey, accountId: string, provider: Provider): Promise<bigint>;
|
|
8
|
+
invalidate(pk: PublicKey): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class NonceManager {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.nonces = {};
|
|
4
|
+
this.locks = {};
|
|
5
|
+
}
|
|
6
|
+
async resolveNextNonce(pk, accountId, provider) {
|
|
7
|
+
const key = pk.toString();
|
|
8
|
+
// wait until unlocked
|
|
9
|
+
const lock = this.locks[key];
|
|
10
|
+
if (lock)
|
|
11
|
+
await lock;
|
|
12
|
+
if (typeof this.nonces[key] === 'bigint') {
|
|
13
|
+
this.nonces[key] = this.nonces[key] + 1n;
|
|
14
|
+
return this.nonces[key];
|
|
15
|
+
}
|
|
16
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: unlock is immediately overwritten
|
|
17
|
+
let unlock = () => { };
|
|
18
|
+
const newLock = new Promise((resolve) => {
|
|
19
|
+
unlock = resolve;
|
|
20
|
+
});
|
|
21
|
+
this.locks[key] = newLock;
|
|
22
|
+
try {
|
|
23
|
+
const accessKey = await provider.viewAccessKey({
|
|
24
|
+
accountId,
|
|
25
|
+
publicKey: pk,
|
|
26
|
+
finalityQuery: { finality: 'optimistic' },
|
|
27
|
+
});
|
|
28
|
+
this.nonces[key] = accessKey.nonce + 1n;
|
|
29
|
+
return this.nonces[key];
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
unlock();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async invalidate(pk) {
|
|
36
|
+
const key = pk.toString();
|
|
37
|
+
// make sure to wait until unlocked
|
|
38
|
+
const lock = this.locks[key];
|
|
39
|
+
if (lock)
|
|
40
|
+
await lock;
|
|
41
|
+
delete this.nonces[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { PrepareError, WasmTrap } from '../../rpc/types.gen.js';
|
|
2
|
+
import type { BlockHash } from '../../types/index.js';
|
|
3
|
+
import { HandlerError } from './handler.js';
|
|
4
|
+
export declare class ContractExecutionError extends HandlerError {
|
|
5
|
+
readonly blockHash: BlockHash;
|
|
6
|
+
readonly blockHeight: number;
|
|
7
|
+
constructor(message: string, blockHash: BlockHash, blockHeight: number);
|
|
8
|
+
}
|
|
9
|
+
export declare class WasmTrapError extends ContractExecutionError {
|
|
10
|
+
readonly reason: WasmTrap;
|
|
11
|
+
constructor(reason: WasmTrap, blockHash: BlockHash, blockHeight: number);
|
|
12
|
+
}
|
|
13
|
+
export declare class ContractCodeDoesNotExistError extends ContractExecutionError {
|
|
14
|
+
readonly contractId: string;
|
|
15
|
+
constructor(contractId: string, blockHash: BlockHash, blockHeight: number);
|
|
16
|
+
}
|
|
17
|
+
export declare class ContractMethodNotFoundError extends ContractExecutionError {
|
|
18
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
19
|
+
}
|
|
20
|
+
export declare class ContractMethodNameEmptyError extends ContractExecutionError {
|
|
21
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
22
|
+
}
|
|
23
|
+
export declare class ContractMethodInvalidSignatureError extends ContractExecutionError {
|
|
24
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
25
|
+
}
|
|
26
|
+
export declare class PrepareWasmError extends ContractExecutionError {
|
|
27
|
+
readonly reason: PrepareError;
|
|
28
|
+
constructor(reason: PrepareError, blockHash: BlockHash, blockHeight: number);
|
|
29
|
+
}
|
|
30
|
+
export declare class HostBadUtf16Error extends ContractExecutionError {
|
|
31
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
32
|
+
}
|
|
33
|
+
export declare class HostBadUtf8Error extends ContractExecutionError {
|
|
34
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
35
|
+
}
|
|
36
|
+
export declare class HostGasExceededError extends ContractExecutionError {
|
|
37
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
38
|
+
}
|
|
39
|
+
export declare class HostGasLimitExceededError extends ContractExecutionError {
|
|
40
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
41
|
+
}
|
|
42
|
+
export declare class HostBalanceExceededError extends ContractExecutionError {
|
|
43
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
44
|
+
}
|
|
45
|
+
export declare class HostEmptyMethodNameError extends ContractExecutionError {
|
|
46
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
47
|
+
}
|
|
48
|
+
export declare class HostGuestPanicError extends ContractExecutionError {
|
|
49
|
+
readonly panicMessage: string;
|
|
50
|
+
constructor(panicMessage: string, blockHash: BlockHash, blockHeight: number);
|
|
51
|
+
}
|
|
52
|
+
export declare class HostIntegerOverflowError extends ContractExecutionError {
|
|
53
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
54
|
+
}
|
|
55
|
+
export declare class HostInvalidPromiseIndexError extends ContractExecutionError {
|
|
56
|
+
readonly promiseIndex: number;
|
|
57
|
+
constructor(promiseIndex: number, blockHash: BlockHash, blockHeight: number);
|
|
58
|
+
}
|
|
59
|
+
export declare class HostCannotAppendActionToJointPromiseError extends ContractExecutionError {
|
|
60
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
61
|
+
}
|
|
62
|
+
export declare class HostCannotReturnJointPromiseError extends ContractExecutionError {
|
|
63
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
64
|
+
}
|
|
65
|
+
export declare class HostInvalidPromiseResultIndexError extends ContractExecutionError {
|
|
66
|
+
readonly resultIndex: number;
|
|
67
|
+
constructor(resultIndex: number, blockHash: BlockHash, blockHeight: number);
|
|
68
|
+
}
|
|
69
|
+
export declare class HostInvalidRegisterIdError extends ContractExecutionError {
|
|
70
|
+
readonly registerId: number;
|
|
71
|
+
constructor(registerId: number, blockHash: BlockHash, blockHeight: number);
|
|
72
|
+
}
|
|
73
|
+
export declare class HostIteratorWasInvalidatedError extends ContractExecutionError {
|
|
74
|
+
readonly iteratorIndex: number;
|
|
75
|
+
constructor(iteratorIndex: number, blockHash: BlockHash, blockHeight: number);
|
|
76
|
+
}
|
|
77
|
+
export declare class HostMemoryAccessViolationError extends ContractExecutionError {
|
|
78
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
79
|
+
}
|
|
80
|
+
export declare class HostInvalidReceiptIndexError extends ContractExecutionError {
|
|
81
|
+
readonly receiptIndex: number;
|
|
82
|
+
constructor(receiptIndex: number, blockHash: BlockHash, blockHeight: number);
|
|
83
|
+
}
|
|
84
|
+
export declare class HostInvalidIteratorIndexError extends ContractExecutionError {
|
|
85
|
+
readonly iteratorIndex: number;
|
|
86
|
+
constructor(iteratorIndex: number, blockHash: BlockHash, blockHeight: number);
|
|
87
|
+
}
|
|
88
|
+
export declare class HostInvalidAccountIdError extends ContractExecutionError {
|
|
89
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
90
|
+
}
|
|
91
|
+
export declare class HostInvalidMethodNameError extends ContractExecutionError {
|
|
92
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
93
|
+
}
|
|
94
|
+
export declare class HostInvalidPublicKeyError extends ContractExecutionError {
|
|
95
|
+
constructor(blockHash: BlockHash, blockHeight: number);
|
|
96
|
+
}
|
|
97
|
+
export declare class HostProhibitedInViewError extends ContractExecutionError {
|
|
98
|
+
readonly methodName: string;
|
|
99
|
+
constructor(methodName: string, blockHash: BlockHash, blockHeight: number);
|
|
100
|
+
}
|
|
101
|
+
export declare class HostNumberOfLogsExceededError extends ContractExecutionError {
|
|
102
|
+
readonly limit: number;
|
|
103
|
+
constructor(limit: number, blockHash: BlockHash, blockHeight: number);
|
|
104
|
+
}
|
|
105
|
+
export declare class HostKeyLengthExceededError extends ContractExecutionError {
|
|
106
|
+
readonly length: number;
|
|
107
|
+
readonly limit: number;
|
|
108
|
+
constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
|
|
109
|
+
}
|
|
110
|
+
export declare class HostValueLengthExceededError extends ContractExecutionError {
|
|
111
|
+
readonly length: number;
|
|
112
|
+
readonly limit: number;
|
|
113
|
+
constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
|
|
114
|
+
}
|
|
115
|
+
export declare class HostTotalLogLengthExceededError extends ContractExecutionError {
|
|
116
|
+
readonly length: number;
|
|
117
|
+
readonly limit: number;
|
|
118
|
+
constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
|
|
119
|
+
}
|
|
120
|
+
export declare class HostNumberPromisesExceededError extends ContractExecutionError {
|
|
121
|
+
readonly limit: number;
|
|
122
|
+
readonly numberOfPromises: number;
|
|
123
|
+
constructor(limit: number, numberOfPromises: number, blockHash: BlockHash, blockHeight: number);
|
|
124
|
+
}
|
|
125
|
+
export declare class HostNumberInputDataDependenciesExceededError extends ContractExecutionError {
|
|
126
|
+
readonly limit: number;
|
|
127
|
+
readonly numberOfInputDataDependencies: number;
|
|
128
|
+
constructor(limit: number, numberOfInputDataDependencies: number, blockHash: BlockHash, blockHeight: number);
|
|
129
|
+
}
|
|
130
|
+
export declare class HostReturnedValueLengthExceededError extends ContractExecutionError {
|
|
131
|
+
readonly length: number;
|
|
132
|
+
readonly limit: number;
|
|
133
|
+
constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
|
|
134
|
+
}
|
|
135
|
+
export declare class HostSizeExceededError extends ContractExecutionError {
|
|
136
|
+
readonly size: number;
|
|
137
|
+
readonly limit: number;
|
|
138
|
+
constructor(size: number, limit: number, blockHash: BlockHash, blockHeight: number);
|
|
139
|
+
}
|
|
140
|
+
export declare class HostDeprecatedError extends ContractExecutionError {
|
|
141
|
+
readonly methodName: string;
|
|
142
|
+
constructor(methodName: string, blockHash: BlockHash, blockHeight: number);
|
|
143
|
+
}
|
|
144
|
+
export declare class HostECRecoverError extends ContractExecutionError {
|
|
145
|
+
constructor(message: string, blockHash: BlockHash, blockHeight: number);
|
|
146
|
+
}
|
|
147
|
+
export declare class HostAltBn128InvalidInputError extends ContractExecutionError {
|
|
148
|
+
constructor(message: string, blockHash: BlockHash, blockHeight: number);
|
|
149
|
+
}
|
|
150
|
+
export declare class HostEd25519VerifyInvalidInputError extends ContractExecutionError {
|
|
151
|
+
constructor(message: string, blockHash: BlockHash, blockHeight: number);
|
|
152
|
+
}
|