Skip to content

Commit

Permalink
Merge branch 'main' into fix-dictionary-bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo committed Aug 23, 2024
2 parents 2fc1c4a + f38c84e commit 5133262
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
Empty file added .yarn/versions/92eab379.yml
Empty file.
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Filter out transactions that can't be decoded (#280)

### Change
- Support bigint filter
Expand Down
5 changes: 3 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/node-cosmos",
"version": "4.1.0",
"version": "4.1.1-0",
"description": "",
"author": "SubQuery Pte Ltd",
"license": "GPL-3.0",
Expand Down Expand Up @@ -56,5 +56,6 @@
"files": [
"/dist",
"/bin"
]
],
"stableVersion": "4.1.0"
}
18 changes: 18 additions & 0 deletions packages/node/src/utils/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,24 @@ describe('Cosmos 0.50 support', () => {

expect(event.log.events.length).toEqual(0);
});

// block.tx when block.block.tx cannot be decoded
// {
// code: 2,
// codespace: 'sdk',
// log: 'tx parse error',
// data: undefined,
// events: [],
// gasWanted: 0n,
// gasUsed: 0n
// }

it('doesnt throw when a block contains ExtendedCommitInfo in the transactions', async () => {
const [firstBlock] = await fetchBlocksBatches(api, [13_379_322]); // https://www.mintscan.io/neutron/block/13379322
const block = firstBlock.block;

expect(block.messages.length).toEqual(4);
});
});

describe('Cosmos bigint support', () => {
Expand Down
34 changes: 24 additions & 10 deletions packages/node/src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,30 @@ export function wrapTx(
block: CosmosBlock,
txResults: TxData[],
): CosmosTransaction[] {
return txResults.map((tx, idx) => ({
idx,
block: block,
tx,
hash: toHex(sha256(block.block.txs[idx])).toUpperCase(),
get decodedTx() {
delete (this as any).decodedTx;
return ((this.decodedTx as any) = decodeTxRaw(block.block.txs[idx]));
},
}));
return (
txResults
.map((tx, idx) => ({
idx,
block: block,
tx,
hash: toHex(sha256(block.block.txs[idx])).toUpperCase(),
get decodedTx() {
delete (this as any).decodedTx;
try {
return ((this.decodedTx as any) = decodeTxRaw(
block.block.txs[idx],
));
} catch (e) {
throw new Error(
`Failed to decode transaction idx="${idx}" at height="${block.block.header.height}"`,
{ cause: e },
);
}
},
}))
// Somtimes there might be other data types in the transactions, ExtendedCommitInfo, we filter them out here so that `decodedTx` doesn't fail
.filter((tx) => tx.tx.log !== 'tx parse error')
);
}

export function wrapCosmosMsg(
Expand Down

0 comments on commit 5133262

Please sign in to comment.