Skip to content

Commit

Permalink
fix: runtime tendermint (#58)
Browse files Browse the repository at this point in the history
* fix: removed index from event attributes

* fix: properly map over begin and end block events
  • Loading branch information
troykessler authored Aug 8, 2023
1 parent 9bdff5a commit 38e0b17
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 62 deletions.
5 changes: 1 addition & 4 deletions common/protocol/src/reactors/storageProviders/Bundlr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export class Bundlr implements IStorageProvider {
}

async saveBundle(bundle: Buffer, tags: BundleTag[]) {
const transaction = this.bundlrClient.createTransaction(
bundle,
{ tags }
);
const transaction = this.bundlrClient.createTransaction(bundle, { tags });

await transaction.sign();
await transaction.upload();
Expand Down
Binary file added integrations/.DS_Store
Binary file not shown.
65 changes: 41 additions & 24 deletions integrations/tendermint/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ interface IConfig {
rpc: string;
}

interface IAttribute {
key: string;
value: string;
index?: boolean;
}

interface IEvent {
type: string;
attributes: IAttribute[];
}

export default class Tendermint implements IRuntime {
public name = name;
public version = version;
Expand Down Expand Up @@ -101,53 +112,59 @@ export default class Tendermint implements IRuntime {
// event "fungible_token_packet" since it is producing non-deterministic
// values likely due to a bug

const compareEventAttribute = (a: any, b: any) =>
const compareEventAttribute = (a: IAttribute, b: IAttribute) =>
a.key.toLowerCase() > b.key.toLowerCase()
? 1
: b.key.toLowerCase() > a.key.toLowerCase()
? -1
: 0;

// sort attributes in begin_block_events
if (item.value?.begin_block_events) {
item.value.begin_block_events = item.value.begin_block_events.map(
(event: any) => {
event.attributes.sort(compareEventAttribute);
// sort attributes and remove index in begin_block_events
if (item.value.block_results.begin_block_events) {
item.value.block_results.begin_block_events =
item.value.block_results.begin_block_events.map((event: IEvent) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: IAttribute) => attribute);
return event;
}
);
});
}

// sort attributes in end_block_events
if (item.value?.end_block_events) {
item.value.end_block_events = item.value.end_block_events.map(
(event: any) => {
event.attributes.sort(compareEventAttribute);
// sort attributes and remove index in end_block_events
if (item.value.block_results.end_block_events) {
item.value.block_results.end_block_events =
item.value.block_results.end_block_events.map((event: IEvent) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: IAttribute) => attribute);
return event;
}
);
});
}

if (item.value?.block_results?.txs_results) {
if (item.value.block_results.txs_results) {
item.value.block_results.txs_results =
item.value.block_results.txs_results.map((tx_result: any) => {
// delete log property of transaction results since it stores duplicate data
delete tx_result.log;

if (tx_result.events) {
tx_result.events = tx_result.events.map((event: any) => {
tx_result.events = tx_result.events.map((event: IEvent) => {
// sort attributes in txs_results
event.attributes.sort(compareEventAttribute);
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: IAttribute) => attribute);

// set attribute "acknowledgement" in ibc event "fungible_token_packet" to empty string
if (event.type === 'fungible_token_packet') {
event.attributes = event.attributes.map((attribute: any) => {
if (attribute.key === 'YWNrbm93bGVkZ2VtZW50') {
attribute.value = '';
}
event.attributes = event.attributes.map(
(attribute: IAttribute) => {
if (attribute.key === 'YWNrbm93bGVkZ2VtZW50') {
attribute.value = '';
}

return attribute;
});
return attribute;
}
);
}

return event;
Expand Down
39 changes: 5 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,6 @@
near-api-js "^0.44.2"
near-seed-phrase "^0.2.0"

"@celo-tools/celo-ethers-wrapper@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@celo-tools/celo-ethers-wrapper/-/celo-ethers-wrapper-0.3.0.tgz#14e19edde1c71da912927344590029e9ffcb3a97"
integrity sha512-qJgVQ3EeVYzM0uvGcVxPB4cH8BaEnoLMyG8k/gAWzSCjJFIgNTlRs05IFGzAb7U0GlbDKCDSualHSGMXq+OHEw==

"@confio/ics23@^0.6.3", "@confio/ics23@^0.6.8":
version "0.6.8"
resolved "https://registry.yarnpkg.com/@confio/ics23/-/ics23-0.6.8.tgz#2a6b4f1f2b7b20a35d9a0745bb5a446e72930b3d"
Expand Down Expand Up @@ -3645,13 +3640,6 @@ axios@^0.24.0:
dependencies:
follow-redirects "^1.14.4"

axios@^0.26.1:
version "0.26.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
dependencies:
follow-redirects "^1.14.8"

axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
Expand All @@ -3660,7 +3648,7 @@ axios@^0.27.2:
follow-redirects "^1.14.9"
form-data "^4.0.0"

axios@^1.0.0, axios@^1.3.4:
axios@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f"
integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==
Expand Down Expand Up @@ -5121,7 +5109,7 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

ethers@^5.5.1, ethers@^5.6.5, ethers@^5.6.9:
ethers@^5.5.1:
version "5.7.2"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e"
integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==
Expand Down Expand Up @@ -5446,7 +5434,7 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==

follow-redirects@^1.14.0, follow-redirects@^1.14.4, follow-redirects@^1.14.7, follow-redirects@^1.14.8, follow-redirects@^1.14.9, follow-redirects@^1.15.0:
follow-redirects@^1.14.0, follow-redirects@^1.14.4, follow-redirects@^1.14.7, follow-redirects@^1.14.9, follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
Expand Down Expand Up @@ -7631,11 +7619,6 @@ nan@^2.13.2:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb"
integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==

nanoid@^3.3.3:
version "3.3.6"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==

napi-build-utils@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"
Expand Down Expand Up @@ -8487,7 +8470,7 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@^2.3.0, prettier@^2.4.1, prettier@^2.5.1, prettier@^2.6.2, prettier@^2.7.1:
prettier@^2.3.0, prettier@^2.4.1, prettier@^2.5.1, prettier@^2.7.1:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
Expand Down Expand Up @@ -9129,11 +9112,6 @@ smart-buffer@^4.2.0:
resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae"
integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==

snekfetch@^3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/snekfetch/-/snekfetch-3.6.4.tgz#d13e80a616d892f3d38daae4289f4d258a645120"
integrity sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==

socks-proxy-agent@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-7.0.0.tgz#dc069ecf34436621acb41e3efa66ca1b5fed15b6"
Expand Down Expand Up @@ -9844,7 +9822,7 @@ typescript-json-schema@^0.53.1:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

typescript@^4.4.3, typescript@^4.5.5, typescript@^4.6.3, typescript@^4.6.4, typescript@^4.7.3, typescript@^4.7.4:
typescript@^4.4.3, typescript@^4.5.5, typescript@^4.6.4, typescript@^4.7.3, typescript@^4.7.4:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
Expand Down Expand Up @@ -10046,13 +10024,6 @@ wcwidth@^1.0.0, wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

webhook-discord@^3.7.8:
version "3.7.8"
resolved "https://registry.yarnpkg.com/webhook-discord/-/webhook-discord-3.7.8.tgz#856ce6928713ee7d1a05dbc8a64dfc233d0d816d"
integrity sha512-IDEvKmu83SIAPZD0efpEXj3ZEm+X8Q68iRuKEKtyXlGN9S9lVtdL7cp4I0AXqTapVj+eh+Wby7y9DaxP01Yk2g==
dependencies:
snekfetch "^3.6.4"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
Expand Down

0 comments on commit 38e0b17

Please sign in to comment.