Skip to content

Commit

Permalink
Use algorand indexer to retrieve past transactions (#224)
Browse files Browse the repository at this point in the history
* Use algorand indexer to retrieve past transactions

* Fix inner-txns logs encoding

* Perform extra safety checks
  • Loading branch information
stefanofa committed Jul 4, 2023
1 parent db10af4 commit c4f6e17
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/components/Recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import { COLORS } from "../muiTheme";
import { setRecoveryVaa as setRecoveryNFTVaa } from "../store/nftSlice";
import { setRecoveryVaa } from "../store/transferSlice";
import {
ALGORAND_HOST,
ALGORAND_TOKEN_BRIDGE_ID,
CHAINS,
CHAINS_BY_ID,
Expand All @@ -91,6 +90,7 @@ import {
XPLA_LCD_CLIENT_CONFIG,
getWalletAddressNative,
CLUSTER,
ALGORAND_INDEXER,
} from "../utils/consts";
import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
import {
Expand Down Expand Up @@ -200,28 +200,40 @@ function handleError(e: any, enqueueSnackbar: any) {

async function algo(tx: string, enqueueSnackbar: any) {
try {
const algodClient = new algosdk.Algodv2(
ALGORAND_HOST.algodToken,
ALGORAND_HOST.algodServer,
ALGORAND_HOST.algodPort
const algoIndexer = new algosdk.Indexer(
ALGORAND_INDEXER.token,
ALGORAND_INDEXER.server,
ALGORAND_INDEXER.port
);
const pendingInfo = await algodClient
.pendingTransactionInformation(tx)
.do();
const txnInfo = await algoIndexer.lookupTransactionByID(tx).do();
let confirmedTxInfo: Record<string, any> | undefined = undefined;
// This is the code from waitForConfirmation
if (pendingInfo !== undefined) {
if (txnInfo?.transaction !== undefined) {
if (
pendingInfo["confirmed-round"] !== null &&
pendingInfo["confirmed-round"] > 0
txnInfo?.transaction["confirmed-round"] !== null &&
txnInfo?.transaction["confirmed-round"] > 0
) {
//Got the completed Transaction
confirmedTxInfo = pendingInfo;
confirmedTxInfo = txnInfo.transaction;
}
}
if (!confirmedTxInfo) {
throw new Error("Transaction not found or not confirmed");
}
if (!confirmedTxInfo["inner-txns"]) {
throw new Error("Source Tx does not refer to a valid bridge transaction");
}
// transform the object to match the format expected by parseSequenceFromLogAlgorand
confirmedTxInfo["inner-txns"] = confirmedTxInfo["inner-txns"].map(
(innerTxn: any) => {
return {
...innerTxn,
logs: innerTxn["logs"]?.[0]
? [Buffer.from(innerTxn["logs"][0], "base64")]
: undefined,
};
}
);
const sequence = parseSequenceFromLogAlgorand(confirmedTxInfo);
if (!sequence) {
throw new Error("Sequence not found");
Expand Down
19 changes: 19 additions & 0 deletions src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,25 @@ export const ALGORAND_HOST =
algodServer: "http://localhost",
algodPort: "4001",
};
export const ALGORAND_INDEXER =
CLUSTER === "mainnet"
? {
token: "",
server: "https://mainnet-idx.algonode.cloud",
port: "443",
}
: CLUSTER === "testnet"
? {
token: "",
server: "https://testnet-idx.algonode.cloud",
port: "443",
}
: {
token:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
server: "http://localhost",
port: "8980",
};
export const KARURA_HOST =
CLUSTER === "mainnet"
? "https://eth-rpc-karura.aca-api.network/"
Expand Down

0 comments on commit c4f6e17

Please sign in to comment.