starknet 8.3.1 → 8.4.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +47 -1
- package/dist/index.global.js +111 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6546,6 +6546,48 @@ var RpcChannel2 = class {
|
|
|
6546
6546
|
}
|
|
6547
6547
|
return txReceipt;
|
|
6548
6548
|
}
|
|
6549
|
+
async fastWaitForTransaction(txHash, address, initNonceBN, options) {
|
|
6550
|
+
const initNonce = BigInt(initNonceBN);
|
|
6551
|
+
let retries = options?.retries ?? 50;
|
|
6552
|
+
const retryInterval = options?.retryInterval ?? 500;
|
|
6553
|
+
const errorStates = [RPCSPEC09.ETransactionExecutionStatus.REVERTED];
|
|
6554
|
+
const successStates = [
|
|
6555
|
+
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
|
|
6556
|
+
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1,
|
|
6557
|
+
RPCSPEC09.ETransactionFinalityStatus.PRE_CONFIRMED
|
|
6558
|
+
];
|
|
6559
|
+
let txStatus;
|
|
6560
|
+
const start = (/* @__PURE__ */ new Date()).getTime();
|
|
6561
|
+
while (retries > 0) {
|
|
6562
|
+
await wait(retryInterval);
|
|
6563
|
+
txStatus = await this.getTransactionStatus(txHash);
|
|
6564
|
+
logger.info(
|
|
6565
|
+
`${retries} ${JSON.stringify(txStatus)} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
|
|
6566
|
+
);
|
|
6567
|
+
const executionStatus = txStatus.execution_status ?? "";
|
|
6568
|
+
const finalityStatus = txStatus.finality_status;
|
|
6569
|
+
if (errorStates.includes(executionStatus)) {
|
|
6570
|
+
const message = `${executionStatus}: ${finalityStatus}`;
|
|
6571
|
+
const error = new Error(message);
|
|
6572
|
+
error.response = txStatus;
|
|
6573
|
+
throw error;
|
|
6574
|
+
} else if (successStates.includes(finalityStatus)) {
|
|
6575
|
+
let currentNonce = initNonce;
|
|
6576
|
+
while (currentNonce === initNonce && retries > 0) {
|
|
6577
|
+
currentNonce = BigInt(await this.getNonceForAddress(address, BlockTag.PRE_CONFIRMED));
|
|
6578
|
+
logger.info(
|
|
6579
|
+
`${retries} Checking new nonce ${currentNonce} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
|
|
6580
|
+
);
|
|
6581
|
+
if (currentNonce !== initNonce) return true;
|
|
6582
|
+
await wait(retryInterval);
|
|
6583
|
+
retries -= 1;
|
|
6584
|
+
}
|
|
6585
|
+
return false;
|
|
6586
|
+
}
|
|
6587
|
+
retries -= 1;
|
|
6588
|
+
}
|
|
6589
|
+
return false;
|
|
6590
|
+
}
|
|
6549
6591
|
getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
6550
6592
|
const contract_address = toHex(contractAddress);
|
|
6551
6593
|
const parsedKey = toStorageKey(key);
|
|
@@ -8393,6 +8435,31 @@ var RpcProvider = class {
|
|
|
8393
8435
|
);
|
|
8394
8436
|
return createTransactionReceipt(receiptWoHelper);
|
|
8395
8437
|
}
|
|
8438
|
+
/**
|
|
8439
|
+
* Wait up until a new transaction is possible with same the account.
|
|
8440
|
+
* This method is fast, but Events and transaction report are not yet
|
|
8441
|
+
* available. Useful for gaming activity.
|
|
8442
|
+
* - only rpc 0.9 and onwards.
|
|
8443
|
+
* @param {BigNumberish} txHash - transaction hash
|
|
8444
|
+
* @param {string} address - address of the account
|
|
8445
|
+
* @param {BigNumberish} initNonce - initial nonce of the account (before the transaction).
|
|
8446
|
+
* @param {fastWaitForTransactionOptions} [options={retries: 50, retryInterval: 500}] - options to scan the network for the next possible transaction. `retries` is the number of times to retry.
|
|
8447
|
+
* @returns {Promise<boolean>} Returns true if the next transaction is possible,
|
|
8448
|
+
* false if the timeout has been reached,
|
|
8449
|
+
* throw an error in case of provider communication.
|
|
8450
|
+
*/
|
|
8451
|
+
async fastWaitForTransaction(txHash, address, initNonce, options) {
|
|
8452
|
+
if (this.channel instanceof rpc_0_9_0_exports.RpcChannel) {
|
|
8453
|
+
const isSuccess = await this.channel.fastWaitForTransaction(
|
|
8454
|
+
txHash,
|
|
8455
|
+
address,
|
|
8456
|
+
initNonce,
|
|
8457
|
+
options
|
|
8458
|
+
);
|
|
8459
|
+
return isSuccess;
|
|
8460
|
+
}
|
|
8461
|
+
throw new Error("Unsupported channel type");
|
|
8462
|
+
}
|
|
8396
8463
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
8397
8464
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
8398
8465
|
}
|
|
@@ -10800,6 +10867,50 @@ var Account = class extends RpcProvider2 {
|
|
|
10800
10867
|
}
|
|
10801
10868
|
);
|
|
10802
10869
|
}
|
|
10870
|
+
/**
|
|
10871
|
+
* Execute one or multiple calls through the account contract,
|
|
10872
|
+
* responding as soon as a new transaction is possible with the same account.
|
|
10873
|
+
* Useful for gaming usage.
|
|
10874
|
+
* - This method requires the provider to be initialized with `pre_confirmed` blockIdentifier option.
|
|
10875
|
+
* - Rpc 0.9 minimum.
|
|
10876
|
+
* - In a normal myAccount.execute() call, followed by myProvider.waitForTransaction(), you have an immediate access to the events and to the transaction report. Here, we are processing consecutive transactions faster, but events & transaction reports are not available immediately.
|
|
10877
|
+
* - As a consequence of the previous point, do not use contract/account deployment with this method.
|
|
10878
|
+
* @param {AllowArray<Call>} transactions - Single call or array of calls to execute
|
|
10879
|
+
* @param {UniversalDetails} [transactionsDetail] - Transaction execution options
|
|
10880
|
+
* @param {fastWaitForTransactionOptions} [waitDetail={retries: 50, retryInterval: 500}] - options to scan the network for the next possible transaction. `retries` is the number of times to retry, `retryInterval` is the time in ms between retries.
|
|
10881
|
+
* @returns {Promise<fastExecuteResponse>} Response containing the transaction result and status for the next transaction. If `isReady` is true, you can execute the next transaction. If false, timeout has been reached before the next transaction was possible.
|
|
10882
|
+
* @example
|
|
10883
|
+
* ```typescript
|
|
10884
|
+
* const myProvider = new RpcProvider({ nodeUrl: url, blockIdentifier: BlockTag.PRE_CONFIRMED });
|
|
10885
|
+
* const myAccount = new Account({ provider: myProvider, address: accountAddress0, signer: privateKey0 });
|
|
10886
|
+
* const resp = await myAccount.fastExecute(
|
|
10887
|
+
* call, { tip: recommendedTip},
|
|
10888
|
+
* { retries: 30, retryInterval: 500 });
|
|
10889
|
+
* // if resp.isReady is true, you can launch immediately a new tx.
|
|
10890
|
+
* ```
|
|
10891
|
+
*/
|
|
10892
|
+
async fastExecute(transactions, transactionsDetail = {}, waitDetail = {}) {
|
|
10893
|
+
assert(
|
|
10894
|
+
this.channel instanceof rpc_0_9_0_exports.RpcChannel,
|
|
10895
|
+
"Wrong Rpc version in Provider. At least Rpc v0.9 required."
|
|
10896
|
+
);
|
|
10897
|
+
assert(
|
|
10898
|
+
this.channel.blockIdentifier === BlockTag.PRE_CONFIRMED,
|
|
10899
|
+
"Provider needs to be initialized with `pre_confirmed` blockIdentifier option."
|
|
10900
|
+
);
|
|
10901
|
+
const initNonce = BigInt(
|
|
10902
|
+
transactionsDetail.nonce ?? await this.getNonceForAddress(this.address, BlockTag.PRE_CONFIRMED)
|
|
10903
|
+
);
|
|
10904
|
+
const details = { ...transactionsDetail, nonce: initNonce };
|
|
10905
|
+
const resultTx = await this.execute(transactions, details);
|
|
10906
|
+
const resultWait = await this.fastWaitForTransaction(
|
|
10907
|
+
resultTx.transaction_hash,
|
|
10908
|
+
this.address,
|
|
10909
|
+
initNonce,
|
|
10910
|
+
waitDetail
|
|
10911
|
+
);
|
|
10912
|
+
return { txResult: resultTx, isReady: resultWait };
|
|
10913
|
+
}
|
|
10803
10914
|
/**
|
|
10804
10915
|
* First check if contract is already declared, if not declare it
|
|
10805
10916
|
* If contract already declared returned transaction_hash is ''.
|