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.js
CHANGED
|
@@ -6716,6 +6716,48 @@ var RpcChannel2 = class {
|
|
|
6716
6716
|
}
|
|
6717
6717
|
return txReceipt;
|
|
6718
6718
|
}
|
|
6719
|
+
async fastWaitForTransaction(txHash, address, initNonceBN, options) {
|
|
6720
|
+
const initNonce = BigInt(initNonceBN);
|
|
6721
|
+
let retries = options?.retries ?? 50;
|
|
6722
|
+
const retryInterval = options?.retryInterval ?? 500;
|
|
6723
|
+
const errorStates = [RPCSPEC09.ETransactionExecutionStatus.REVERTED];
|
|
6724
|
+
const successStates = [
|
|
6725
|
+
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
|
|
6726
|
+
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1,
|
|
6727
|
+
RPCSPEC09.ETransactionFinalityStatus.PRE_CONFIRMED
|
|
6728
|
+
];
|
|
6729
|
+
let txStatus;
|
|
6730
|
+
const start = (/* @__PURE__ */ new Date()).getTime();
|
|
6731
|
+
while (retries > 0) {
|
|
6732
|
+
await wait(retryInterval);
|
|
6733
|
+
txStatus = await this.getTransactionStatus(txHash);
|
|
6734
|
+
logger.info(
|
|
6735
|
+
`${retries} ${JSON.stringify(txStatus)} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
|
|
6736
|
+
);
|
|
6737
|
+
const executionStatus = txStatus.execution_status ?? "";
|
|
6738
|
+
const finalityStatus = txStatus.finality_status;
|
|
6739
|
+
if (errorStates.includes(executionStatus)) {
|
|
6740
|
+
const message = `${executionStatus}: ${finalityStatus}`;
|
|
6741
|
+
const error = new Error(message);
|
|
6742
|
+
error.response = txStatus;
|
|
6743
|
+
throw error;
|
|
6744
|
+
} else if (successStates.includes(finalityStatus)) {
|
|
6745
|
+
let currentNonce = initNonce;
|
|
6746
|
+
while (currentNonce === initNonce && retries > 0) {
|
|
6747
|
+
currentNonce = BigInt(await this.getNonceForAddress(address, BlockTag.PRE_CONFIRMED));
|
|
6748
|
+
logger.info(
|
|
6749
|
+
`${retries} Checking new nonce ${currentNonce} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
|
|
6750
|
+
);
|
|
6751
|
+
if (currentNonce !== initNonce) return true;
|
|
6752
|
+
await wait(retryInterval);
|
|
6753
|
+
retries -= 1;
|
|
6754
|
+
}
|
|
6755
|
+
return false;
|
|
6756
|
+
}
|
|
6757
|
+
retries -= 1;
|
|
6758
|
+
}
|
|
6759
|
+
return false;
|
|
6760
|
+
}
|
|
6719
6761
|
getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
6720
6762
|
const contract_address = toHex(contractAddress);
|
|
6721
6763
|
const parsedKey = toStorageKey(key);
|
|
@@ -8563,6 +8605,31 @@ var RpcProvider = class {
|
|
|
8563
8605
|
);
|
|
8564
8606
|
return createTransactionReceipt(receiptWoHelper);
|
|
8565
8607
|
}
|
|
8608
|
+
/**
|
|
8609
|
+
* Wait up until a new transaction is possible with same the account.
|
|
8610
|
+
* This method is fast, but Events and transaction report are not yet
|
|
8611
|
+
* available. Useful for gaming activity.
|
|
8612
|
+
* - only rpc 0.9 and onwards.
|
|
8613
|
+
* @param {BigNumberish} txHash - transaction hash
|
|
8614
|
+
* @param {string} address - address of the account
|
|
8615
|
+
* @param {BigNumberish} initNonce - initial nonce of the account (before the transaction).
|
|
8616
|
+
* @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.
|
|
8617
|
+
* @returns {Promise<boolean>} Returns true if the next transaction is possible,
|
|
8618
|
+
* false if the timeout has been reached,
|
|
8619
|
+
* throw an error in case of provider communication.
|
|
8620
|
+
*/
|
|
8621
|
+
async fastWaitForTransaction(txHash, address, initNonce, options) {
|
|
8622
|
+
if (this.channel instanceof rpc_0_9_0_exports.RpcChannel) {
|
|
8623
|
+
const isSuccess = await this.channel.fastWaitForTransaction(
|
|
8624
|
+
txHash,
|
|
8625
|
+
address,
|
|
8626
|
+
initNonce,
|
|
8627
|
+
options
|
|
8628
|
+
);
|
|
8629
|
+
return isSuccess;
|
|
8630
|
+
}
|
|
8631
|
+
throw new Error("Unsupported channel type");
|
|
8632
|
+
}
|
|
8566
8633
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
8567
8634
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
8568
8635
|
}
|
|
@@ -10970,6 +11037,50 @@ var Account = class extends RpcProvider2 {
|
|
|
10970
11037
|
}
|
|
10971
11038
|
);
|
|
10972
11039
|
}
|
|
11040
|
+
/**
|
|
11041
|
+
* Execute one or multiple calls through the account contract,
|
|
11042
|
+
* responding as soon as a new transaction is possible with the same account.
|
|
11043
|
+
* Useful for gaming usage.
|
|
11044
|
+
* - This method requires the provider to be initialized with `pre_confirmed` blockIdentifier option.
|
|
11045
|
+
* - Rpc 0.9 minimum.
|
|
11046
|
+
* - 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.
|
|
11047
|
+
* - As a consequence of the previous point, do not use contract/account deployment with this method.
|
|
11048
|
+
* @param {AllowArray<Call>} transactions - Single call or array of calls to execute
|
|
11049
|
+
* @param {UniversalDetails} [transactionsDetail] - Transaction execution options
|
|
11050
|
+
* @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.
|
|
11051
|
+
* @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.
|
|
11052
|
+
* @example
|
|
11053
|
+
* ```typescript
|
|
11054
|
+
* const myProvider = new RpcProvider({ nodeUrl: url, blockIdentifier: BlockTag.PRE_CONFIRMED });
|
|
11055
|
+
* const myAccount = new Account({ provider: myProvider, address: accountAddress0, signer: privateKey0 });
|
|
11056
|
+
* const resp = await myAccount.fastExecute(
|
|
11057
|
+
* call, { tip: recommendedTip},
|
|
11058
|
+
* { retries: 30, retryInterval: 500 });
|
|
11059
|
+
* // if resp.isReady is true, you can launch immediately a new tx.
|
|
11060
|
+
* ```
|
|
11061
|
+
*/
|
|
11062
|
+
async fastExecute(transactions, transactionsDetail = {}, waitDetail = {}) {
|
|
11063
|
+
assert(
|
|
11064
|
+
this.channel instanceof rpc_0_9_0_exports.RpcChannel,
|
|
11065
|
+
"Wrong Rpc version in Provider. At least Rpc v0.9 required."
|
|
11066
|
+
);
|
|
11067
|
+
assert(
|
|
11068
|
+
this.channel.blockIdentifier === BlockTag.PRE_CONFIRMED,
|
|
11069
|
+
"Provider needs to be initialized with `pre_confirmed` blockIdentifier option."
|
|
11070
|
+
);
|
|
11071
|
+
const initNonce = BigInt(
|
|
11072
|
+
transactionsDetail.nonce ?? await this.getNonceForAddress(this.address, BlockTag.PRE_CONFIRMED)
|
|
11073
|
+
);
|
|
11074
|
+
const details = { ...transactionsDetail, nonce: initNonce };
|
|
11075
|
+
const resultTx = await this.execute(transactions, details);
|
|
11076
|
+
const resultWait = await this.fastWaitForTransaction(
|
|
11077
|
+
resultTx.transaction_hash,
|
|
11078
|
+
this.address,
|
|
11079
|
+
initNonce,
|
|
11080
|
+
waitDetail
|
|
11081
|
+
);
|
|
11082
|
+
return { txResult: resultTx, isReady: resultWait };
|
|
11083
|
+
}
|
|
10973
11084
|
/**
|
|
10974
11085
|
* First check if contract is already declared, if not declare it
|
|
10975
11086
|
* If contract already declared returned transaction_hash is ''.
|