Skip to content

Commit

Permalink
feat: ensure txns in snap state have the same status and timestamp as… (
Browse files Browse the repository at this point in the history
#10)

* feat: ensure txns in snap state have the same status and timestamp as that of Voyager

* feat: changed all blockIdentifier to latest to accommodate mainnet instability
  • Loading branch information
jonesho authored Sep 21, 2022
1 parent a3adc8b commit 7c6de7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/starknet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/ConsenSys/starknet-snap.git"
},
"source": {
"shasum": "9k8ZDr5ZNJOsYza0mhp3KMiKBThzs9CXAKFq7f1yR9I=",
"shasum": "ZjVbz5xyzjNC8nS3bLJz3+C6VqHWxceozLOXUwk05Pk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
13 changes: 11 additions & 2 deletions packages/starknet-snap/src/getTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export async function getTransactions(params: ApiParams) {
console.log(`getTransactions\nstoredUnsettledDeployTxns:\n${JSON.stringify(storedUnsettledDeployTxns)}`);
storedUnsettledTxns = [...storedUnsettledTxns, ...storedUnsettledDeployTxns];
}

// For each "unsettled" txn, update the status and timestamp from the same txn found in massagedTxns
storedUnsettledTxns.forEach((txn) => {
const foundMassagedTxn = massagedTxns.find((massagedTxn) =>
number.toBN(massagedTxn.txnHash).eq(number.toBN(txn.txnHash)),
);
txn.status = foundMassagedTxn?.status ?? txn.status;
txn.timestamp = foundMassagedTxn?.timestamp ?? txn.timestamp;
});

console.log(`getTransactions\nstoredUnsettledTxns:\n${JSON.stringify(storedUnsettledTxns)}`);

// Retrieve the REJECTED txns from snap state
Expand All @@ -85,8 +95,7 @@ export async function getTransactions(params: ApiParams) {
);
console.log(`getTransactions\nstoredRejectedTxns:\n${JSON.stringify(storedRejectedTxns)}`);

// For each "unsettled" txn, call get_transacton_status endpoint from feeder_gateway to
// get the latest status
// For each "unsettled" txn, get the latest status from the provider (RPC or sequencer)
await Promise.allSettled(
storedUnsettledTxns.map(async (txn) => {
const txnStatus = await utils.getTransactionStatus(txn.txnHash, network);
Expand Down
13 changes: 8 additions & 5 deletions packages/starknet-snap/src/utils/starknetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ export const callContract = async (
contractCallData: RawCalldata = [],
): Promise<CallContractResponse> => {
const provider = getProvider(network);
return provider.callContract({
contractAddress,
entrypoint: contractFuncName,
calldata: contractCallData,
});
return provider.callContract(
{
contractAddress,
entrypoint: contractFuncName,
calldata: contractCallData,
},
'latest',
);
};

export const estimateFee = async (
Expand Down

0 comments on commit 7c6de7c

Please sign in to comment.