sdk/js : add parseSequencesFromLog*

This commit is contained in:
Evan Gray 2021-12-27 17:26:17 +00:00 committed by Evan Gray
parent cd56eb08b7
commit 2998031b16
3 changed files with 59 additions and 6 deletions

View File

@ -1,16 +1,29 @@
# Changelog # Changelog
## 0.1.6
### Added
added parseSequencesFromLog\*
## 0.1.5 ## 0.1.5
deprecated postVaaSolana ### Added
added postVaaSolanaWithRetry, which will retry transactions which failed during processing.
added createVerifySignaturesInstructions, createPostVaaInstruction, which allows users to construct the postVaa process for themselves at the instruction level.
added chunks and sendAndConfirmTransactionsWithRetry as utility functions.
added integration tests for postVaaSolanaWithRetry. added postVaaSolanaWithRetry, which will retry transactions which failed during processing
added createVerifySignaturesInstructions, createPostVaaInstruction, which allows users to construct the postVaa process for themselves at the instruction level
added chunks and sendAndConfirmTransactionsWithRetry as utility functions
added integration tests for postVaaSolanaWithRetry
initial Oasis support initial Oasis support
### Changed
deprecated postVaaSolana
## 0.1.4 ## 0.1.4
initial AVAX testnet support initial AVAX testnet support

View File

@ -1,6 +1,6 @@
{ {
"name": "@certusone/wormhole-sdk", "name": "@certusone/wormhole-sdk",
"version": "0.1.5", "version": "0.1.6",
"description": "SDK for interacting with Wormhole", "description": "SDK for interacting with Wormhole",
"homepage": "https://wormholenetwork.com", "homepage": "https://wormholenetwork.com",
"main": "./lib/cjs/index.js", "main": "./lib/cjs/index.js",

View File

@ -17,6 +17,22 @@ export function parseSequenceFromLogEth(
return sequence.toString(); return sequence.toString();
} }
export function parseSequencesFromLogEth(
receipt: ContractReceipt,
bridgeAddress: string
): string[] {
// TODO: dangerous!(?)
const bridgeLogs = receipt.logs.filter((l) => {
return l.address === bridgeAddress;
});
return bridgeLogs.map((bridgeLog) => {
const {
args: { sequence },
} = Implementation__factory.createInterface().parseLog(bridgeLog);
return sequence.toString();
});
}
export function parseSequenceFromLogTerra(info: TxInfo): string { export function parseSequenceFromLogTerra(info: TxInfo): string {
// Scan for the Sequence attribute in all the outputs of the transaction. // Scan for the Sequence attribute in all the outputs of the transaction.
// TODO: Make this not horrible. // TODO: Make this not horrible.
@ -35,6 +51,23 @@ export function parseSequenceFromLogTerra(info: TxInfo): string {
return sequence.toString(); return sequence.toString();
} }
export function parseSequencesFromLogTerra(info: TxInfo): string[] {
// Scan for the Sequence attribute in all the outputs of the transaction.
// TODO: Make this not horrible.
const sequences: string[] = [];
const jsonLog = JSON.parse(info.raw_log);
jsonLog.map((row: any) => {
row.events.map((event: any) => {
event.attributes.map((attribute: any) => {
if (attribute.key === "message.sequence") {
sequences.push(attribute.value.toString());
}
});
});
});
return sequences;
}
const SOLANA_SEQ_LOG = "Program log: Sequence: "; const SOLANA_SEQ_LOG = "Program log: Sequence: ";
export function parseSequenceFromLogSolana(info: TransactionResponse) { export function parseSequenceFromLogSolana(info: TransactionResponse) {
// TODO: better parsing, safer // TODO: better parsing, safer
@ -46,3 +79,10 @@ export function parseSequenceFromLogSolana(info: TransactionResponse) {
} }
return sequence.toString(); return sequence.toString();
} }
export function parseSequencesFromLogSolana(info: TransactionResponse) {
// TODO: better parsing, safer
return info.meta?.logMessages
?.filter((msg) => msg.startsWith(SOLANA_SEQ_LOG))
.map((msg) => msg.replace(SOLANA_SEQ_LOG, ""));
}