50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { TransactionResponse } from "@solana/web3.js";
|
|
import { ContractReceipt } from "ethers";
|
|
import { TxResult } from "@terra-money/wallet-provider";
|
|
import { Implementation__factory } from "../ethers-contracts";
|
|
|
|
export function parseSequenceFromLogEth(
|
|
receipt: ContractReceipt,
|
|
bridgeAddress: string
|
|
): string {
|
|
// TODO: dangerous!(?)
|
|
const bridgeLog = receipt.logs.filter((l) => {
|
|
console.log(l.address, bridgeAddress);
|
|
return l.address === bridgeAddress;
|
|
})[0];
|
|
const {
|
|
args: { sequence },
|
|
} = Implementation__factory.createInterface().parseLog(bridgeLog);
|
|
return sequence.toString();
|
|
}
|
|
|
|
export function parseSequenceFromLogTerra(result: TxResult): string {
|
|
// Scan for the Sequence attribute in all the outputs of the transaction.
|
|
// TODO: Make this not horrible.
|
|
let sequence = "";
|
|
const jsonLog = JSON.parse(result.result.raw_log);
|
|
jsonLog.map((row: any) => {
|
|
row.events.map((event: any) => {
|
|
event.attributes.map((attribute: any) => {
|
|
if(attribute.key === "message.sequence") {
|
|
sequence = attribute.value;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
console.log('Terra Sequence: ', sequence);
|
|
return sequence.toString();
|
|
}
|
|
|
|
const SOLANA_SEQ_LOG = "Program log: Sequence: ";
|
|
export function parseSequenceFromLogSolana(info: TransactionResponse) {
|
|
// TODO: better parsing, safer
|
|
const sequence = info.meta?.logMessages
|
|
?.filter((msg) => msg.startsWith(SOLANA_SEQ_LOG))[0]
|
|
.replace(SOLANA_SEQ_LOG, "");
|
|
if (!sequence) {
|
|
throw new Error("sequence not found");
|
|
}
|
|
return sequence.toString();
|
|
}
|