Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use algorand indexer to retrieve past transactions #224

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
}
: {
sebastianscatularo marked this conversation as resolved.
Show resolved Hide resolved
token:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
server: "http://localhost",
port: "8980",
};
export const KARURA_HOST =
CLUSTER === "mainnet"
? "https://eth-rpc-karura.aca-api.network/"
Expand Down