From f155a8c34fc77aeb6d55258d6b4f9b1281123e97 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Tue, 8 Mar 2022 20:57:01 +0100 Subject: [PATCH 01/21] be more conform between optimistic and final operation --- src/families/cosmos/js-signOperation.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index ffd71f8804..ddf1d8d5cf 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -120,11 +120,6 @@ const signOperation = ({ const senders: string[] = []; const recipients: string[] = []; - if (type === "OUT") { - senders.push(account.freshAddress); - recipients.push(transaction.recipient); - } - // build optimistic operation const operation: Operation = { id: encodeOperationId(accountId, hash, type), @@ -143,6 +138,22 @@ const signOperation = ({ date: new Date(), }; + switch (type) { + case "OUT": + operation.senders.push(account.freshAddress); + operation.recipients.push(transaction.recipient); + break; + + case "REWARD": + case "DELEGATE": + case "UNDELEGATE": + operation.value = new BigNumber(fee); + operation.extra.validators = transaction.validators; + operation.extra.cosmosSourceValidator = + transaction.cosmosSourceValidator; + break; + } + o.next({ type: "signed", signedOperation: { From 24fa16dfa529d91edd1296c3345bfcbb991bd425 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Wed, 9 Mar 2022 13:56:17 +0100 Subject: [PATCH 02/21] use old code logic --- src/families/cosmos/js-signOperation.ts | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index ddf1d8d5cf..0a0fec6449 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -105,6 +105,7 @@ const signOperation = ({ const hash = ""; // resolved at broadcast time const accountId = account.id; const fee = transaction.fees || new BigNumber(0); + const extra = {}; const type: OperationType = transaction.mode === "undelegate" @@ -117,8 +118,20 @@ const signOperation = ({ ? "REWARD" : "OUT"; - const senders: string[] = []; - const recipients: string[] = []; + const senders: string[] = [account.freshAddress]; + const recipients: string[] = [transaction.recipient]; + + if (transaction.mode === "redelegate") { + Object.assign(extra, { + cosmosSourceValidator: transaction.cosmosSourceValidator, + }); + } + + if (transaction.mode !== "send") { + Object.assign(extra, { + validators: transaction.validators, + }); + } // build optimistic operation const operation: Operation = { @@ -129,7 +142,7 @@ const signOperation = ({ ? account.spendableBalance : transaction.amount.plus(fee), fee, - extra: {}, + extra, blockHash: null, blockHeight: null, senders, @@ -138,22 +151,6 @@ const signOperation = ({ date: new Date(), }; - switch (type) { - case "OUT": - operation.senders.push(account.freshAddress); - operation.recipients.push(transaction.recipient); - break; - - case "REWARD": - case "DELEGATE": - case "UNDELEGATE": - operation.value = new BigNumber(fee); - operation.extra.validators = transaction.validators; - operation.extra.cosmosSourceValidator = - transaction.cosmosSourceValidator; - break; - } - o.next({ type: "signed", signedOperation: { From 3b0a03c78f7708264a11398f3ec816a2f14a9aa5 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Wed, 9 Mar 2022 16:10:34 +0100 Subject: [PATCH 03/21] fix senders/recipients regression --- src/families/cosmos/js-signOperation.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index 0a0fec6449..8ede2b5a0b 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -118,8 +118,13 @@ const signOperation = ({ ? "REWARD" : "OUT"; - const senders: string[] = [account.freshAddress]; - const recipients: string[] = [transaction.recipient]; + const senders: string[] = []; + const recipients: string[] = []; + + if (transaction.mode === "send") { + senders.push(account.freshAddress); + recipients.push(transaction.recipient); + } if (transaction.mode === "redelegate") { Object.assign(extra, { From 86f5367f91f498a8f928519b3146fa76854e99a9 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Wed, 9 Mar 2022 16:51:07 +0100 Subject: [PATCH 04/21] fix duplicate data --- src/families/cosmos/js-signOperation.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index 8df1b524db..744871aaee 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -121,18 +121,6 @@ const signOperation = ({ const senders: string[] = [account.freshAddress]; const recipients: string[] = [transaction.recipient]; - if (transaction.mode === "redelegate") { - Object.assign(extra, { - cosmosSourceValidator: transaction.cosmosSourceValidator, - }); - } - - if (transaction.mode !== "send") { - Object.assign(extra, { - validators: transaction.validators, - }); - } - if (transaction.mode === "send") { senders.push(account.freshAddress); recipients.push(transaction.recipient); From 85dddb6eebc67a6abda5ad69a6bd870c6e68961b Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Wed, 9 Mar 2022 16:57:53 +0100 Subject: [PATCH 05/21] fix duplicate data (again) --- src/families/cosmos/js-signOperation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index 744871aaee..8ede2b5a0b 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -118,8 +118,8 @@ const signOperation = ({ ? "REWARD" : "OUT"; - const senders: string[] = [account.freshAddress]; - const recipients: string[] = [transaction.recipient]; + const senders: string[] = []; + const recipients: string[] = []; if (transaction.mode === "send") { senders.push(account.freshAddress); From 565e8be8f9d0644c0c5c1a224b5460671a616118 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Wed, 9 Mar 2022 17:21:55 +0100 Subject: [PATCH 06/21] append block height --- src/families/cosmos/api/Cosmos.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/families/cosmos/api/Cosmos.ts b/src/families/cosmos/api/Cosmos.ts index 04190c2517..5d9e0127f3 100644 --- a/src/families/cosmos/api/Cosmos.ts +++ b/src/families/cosmos/api/Cosmos.ts @@ -246,7 +246,10 @@ export const broadcast = async ({ ); } - return patchOperationWithHash(operation, data.tx_response.txhash); + return patchOperationWithHash( + { ...operation, blockHeight: data.tx_response.height }, + data.tx_response.txhash + ); }; export const getBlock = async (height: number): Promise => { From 489cdd861fa8fd15a52c78efd254b456862297c3 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Thu, 10 Mar 2022 14:10:56 +0100 Subject: [PATCH 07/21] fix specific empty amount case in reward transaction --- src/families/cosmos/js-synchronisation.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 52c506295e..55701589ce 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -63,8 +63,11 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { case "withdraw_rewards": if ( - attributes.amount && - attributes.amount.indexOf(currency.units[1].code) != -1 + (attributes.amount && + attributes.amount.indexOf(currency.units[1].code) != -1) || + // handle specifc case with empty amount value like + // tx DF458FE6A82C310837D7A33735FA5298BCF71B0BFF7A4134641AAE30F6F1050 + attributes.amount === "" ) { op.type = "REWARD"; op.value = new BigNumber(fees); From b93e8462d9a61166889b3718494e47ae71298578 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Thu, 10 Mar 2022 20:49:46 +0100 Subject: [PATCH 08/21] temporary debug operation broadcasted --- src/families/cosmos/api/Cosmos.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/families/cosmos/api/Cosmos.ts b/src/families/cosmos/api/Cosmos.ts index c515b08ed7..aff6dba916 100644 --- a/src/families/cosmos/api/Cosmos.ts +++ b/src/families/cosmos/api/Cosmos.ts @@ -3,6 +3,7 @@ import BigNumber from "bignumber.js"; import network from "../../../network"; import { Operation } from "../../../types"; import { patchOperationWithHash } from "../../../operation"; +import { log } from "@ledgerhq/logs"; const defaultEndpoint = getEnv( "API_COSMOS_BLOCKCHAIN_EXPLORER_API_ENDPOINT" @@ -281,6 +282,15 @@ export const broadcast = async ({ ); } + log( + "info", + "debug operation: ", + patchOperationWithHash( + { ...operation, blockHeight: data.tx_response.height }, + data.tx_response.txhash + ) + ); + return patchOperationWithHash( { ...operation, blockHeight: data.tx_response.height }, data.tx_response.txhash From 6379b0ae751979591950b79368281f9535877f64 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 08:13:27 +0100 Subject: [PATCH 09/21] use toOperationRaw method --- src/families/cosmos/api/Cosmos.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/families/cosmos/api/Cosmos.ts b/src/families/cosmos/api/Cosmos.ts index aff6dba916..e1ce253a4f 100644 --- a/src/families/cosmos/api/Cosmos.ts +++ b/src/families/cosmos/api/Cosmos.ts @@ -4,6 +4,7 @@ import network from "../../../network"; import { Operation } from "../../../types"; import { patchOperationWithHash } from "../../../operation"; import { log } from "@ledgerhq/logs"; +import { toOperationRaw } from "../../../account"; const defaultEndpoint = getEnv( "API_COSMOS_BLOCKCHAIN_EXPLORER_API_ENDPOINT" @@ -285,9 +286,11 @@ export const broadcast = async ({ log( "info", "debug operation: ", - patchOperationWithHash( - { ...operation, blockHeight: data.tx_response.height }, - data.tx_response.txhash + toOperationRaw( + patchOperationWithHash( + { ...operation, blockHeight: data.tx_response.height }, + data.tx_response.txhash + ) ) ); From f05abf72e4fc93f1b8fb020c134e780950466479 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 09:06:14 +0100 Subject: [PATCH 10/21] return patchedOperation --- src/families/cosmos/api/Cosmos.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/families/cosmos/api/Cosmos.ts b/src/families/cosmos/api/Cosmos.ts index e1ce253a4f..7eb3073633 100644 --- a/src/families/cosmos/api/Cosmos.ts +++ b/src/families/cosmos/api/Cosmos.ts @@ -283,19 +283,12 @@ export const broadcast = async ({ ); } - log( - "info", - "debug operation: ", - toOperationRaw( - patchOperationWithHash( - { ...operation, blockHeight: data.tx_response.height }, - data.tx_response.txhash - ) - ) - ); - - return patchOperationWithHash( + const patchedOperation = patchOperationWithHash( { ...operation, blockHeight: data.tx_response.height }, data.tx_response.txhash ); + + log("info", "debug operation: ", toOperationRaw(patchedOperation)); + + return patchedOperation; }; From 8bda82c6f259b06ae406a4c1f20bde41c4c332d4 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 10:56:54 +0100 Subject: [PATCH 11/21] restore broadcast operation --- src/families/cosmos/api/Cosmos.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/families/cosmos/api/Cosmos.ts b/src/families/cosmos/api/Cosmos.ts index 7eb3073633..e179aa04ee 100644 --- a/src/families/cosmos/api/Cosmos.ts +++ b/src/families/cosmos/api/Cosmos.ts @@ -3,8 +3,6 @@ import BigNumber from "bignumber.js"; import network from "../../../network"; import { Operation } from "../../../types"; import { patchOperationWithHash } from "../../../operation"; -import { log } from "@ledgerhq/logs"; -import { toOperationRaw } from "../../../account"; const defaultEndpoint = getEnv( "API_COSMOS_BLOCKCHAIN_EXPLORER_API_ENDPOINT" @@ -283,12 +281,5 @@ export const broadcast = async ({ ); } - const patchedOperation = patchOperationWithHash( - { ...operation, blockHeight: data.tx_response.height }, - data.tx_response.txhash - ); - - log("info", "debug operation: ", toOperationRaw(patchedOperation)); - - return patchedOperation; + return patchOperationWithHash(operation, data.tx_response.txhash); }; From 607f359a8c4336e08258697d9bff11490617119e Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 10:57:04 +0100 Subject: [PATCH 12/21] Update js-synchronisation.ts --- src/families/cosmos/js-synchronisation.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 55701589ce..2603895f74 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -1,4 +1,4 @@ -import { Account, Operation } from "../../types"; +import { Account, Operation, OperationType } from "../../types"; import { BigNumber } from "bignumber.js"; import { makeSync, GetAccountShape, mergeOps } from "../../bridge/jsHelpers"; import { encodeAccountId } from "../../account"; @@ -20,13 +20,13 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { const op: Operation = { id: "", hash: tx.txhash, - type: "" as any, + type: "" as OperationType, value: new BigNumber(0), fee: fees, blockHash: null, blockHeight: tx.height, - senders: [] as any, - recipients: [] as any, + senders: [] as string[], + recipients: [] as string[], accountId: id, date: new Date(tx.timestamp), extra: { From eb7198f9ab1edef8a82a1edcccaefc9907e99868 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 10:57:15 +0100 Subject: [PATCH 13/21] remove block height support --- src/families/cosmos/js-synchronisation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 2603895f74..8495212a50 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -24,7 +24,7 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { value: new BigNumber(0), fee: fees, blockHash: null, - blockHeight: tx.height, + blockHeight: null, senders: [] as string[], recipients: [] as string[], accountId: id, From 44cd92f120d67b3c1d09a0d118906c0f6e76fb69 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 13:32:50 +0100 Subject: [PATCH 14/21] Revert "remove block height support" This reverts commit eb7198f9ab1edef8a82a1edcccaefc9907e99868. --- src/families/cosmos/js-synchronisation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 8495212a50..2603895f74 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -24,7 +24,7 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { value: new BigNumber(0), fee: fees, blockHash: null, - blockHeight: null, + blockHeight: tx.height, senders: [] as string[], recipients: [] as string[], accountId: id, From 7a7f6fa9bf594a0dc40959786858759bc65081ec Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 16:57:39 +0100 Subject: [PATCH 15/21] More strict type --- src/families/cosmos/js-synchronisation.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 2603895f74..838967b856 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -5,6 +5,7 @@ import { encodeAccountId } from "../../account"; import { getAccountInfo } from "./api/Cosmos"; import { pubkeyToAddress, decodeBech32Pubkey } from "@cosmjs/amino"; import { encodeOperationId } from "../../operation"; +import { CosmosDelegationInfo } from "./types"; const txToOps = (info: any, id: string, txs: any): Operation[] => { const { address, currency } = info; @@ -30,7 +31,7 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { accountId: id, date: new Date(tx.timestamp), extra: { - validators: [] as any, + validators: [] as CosmosDelegationInfo[], }, }; From 78097b87dc82227387b041039b1d6ca364fcb331 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 17:31:53 +0100 Subject: [PATCH 16/21] reverse order of validators --- src/families/cosmos/js-synchronisation.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 838967b856..5e19f25b74 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -73,8 +73,8 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { op.type = "REWARD"; op.value = new BigNumber(fees); op.extra.validators.push({ - amount: attributes.amount.replace(currency.units[1].code, ""), address: attributes.validator, + amount: attributes.amount.replace(currency.units[1].code, ""), }); } break; @@ -87,8 +87,8 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { op.type = "DELEGATE"; op.value = new BigNumber(fees); op.extra.validators.push({ - amount: attributes.amount.replace(currency.units[1].code, ""), address: attributes.validator, + amount: attributes.amount.replace(currency.units[1].code, ""), }); } break; @@ -103,8 +103,8 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { op.type = "REDELEGATE"; op.value = new BigNumber(fees); op.extra.validators.push({ - amount: attributes.amount.replace(currency.units[1].code, ""), address: attributes.destination_validator, + amount: attributes.amount.replace(currency.units[1].code, ""), }); op.extra.cosmosSourceValidator = attributes.source_validator; } @@ -119,8 +119,8 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { op.type = "UNDELEGATE"; op.value = new BigNumber(fees); op.extra.validators.push({ - amount: attributes.amount.replace(currency.units[1].code, ""), address: attributes.validator, + amount: attributes.amount.replace(currency.units[1].code, ""), }); } break; From 8f2ceb4b20e962bc0973a9b1bb1b69289c6a8f2c Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 20:05:20 +0100 Subject: [PATCH 17/21] fix validators type in createTransmission --- src/families/cosmos/js-createTransaction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/families/cosmos/js-createTransaction.ts b/src/families/cosmos/js-createTransaction.ts index 0da7675ffb..1027809f3a 100644 --- a/src/families/cosmos/js-createTransaction.ts +++ b/src/families/cosmos/js-createTransaction.ts @@ -1,5 +1,5 @@ import { BigNumber } from "bignumber.js"; -import type { Transaction } from "./types"; +import type { CosmosDelegationInfo, Transaction } from "./types"; /** * Create an empty transaction @@ -17,7 +17,7 @@ const createTransaction = (): Transaction => ({ networkInfo: null, memo: null, cosmosSourceValidator: null, - validators: [], + validators: [] as CosmosDelegationInfo[], }); export default createTransaction; From e1cf2f06adcc318bb7427f4c6e2c7077e27fbaff Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 20:55:43 +0100 Subject: [PATCH 18/21] add sequence to ops --- src/families/cosmos/js-signOperation.ts | 1 + src/families/cosmos/js-synchronisation.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index 8ede2b5a0b..d8fb56515e 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -154,6 +154,7 @@ const signOperation = ({ recipients, accountId, date: new Date(), + transactionSequenceNumber: sequence, }; o.next({ diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index 5e19f25b74..b81e733840 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -33,6 +33,7 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { extra: { validators: [] as CosmosDelegationInfo[], }, + transactionSequenceNumber: tx.tx.auth_info.signer_infos.sequence, }; tx.logs[0].events.forEach((message) => { From a7a2972ce68d85a7b595bd4a3d48abf0829851c7 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 21:19:35 +0100 Subject: [PATCH 19/21] strict output getAccount type --- src/families/cosmos/api/Cosmos.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/families/cosmos/api/Cosmos.ts b/src/families/cosmos/api/Cosmos.ts index e179aa04ee..19f0d878b9 100644 --- a/src/families/cosmos/api/Cosmos.ts +++ b/src/families/cosmos/api/Cosmos.ts @@ -46,7 +46,9 @@ export const getAccountInfo = async (address: string): Promise => { } }; -export const getAccount = async (address: string): Promise => { +export const getAccount = async ( + address: string +): Promise<{ address: string; accountNumber: number; sequence: number }> => { const response = { address: address, accountNumber: 0, From 7b7ffe18794e777d63c4d48def845900051b0de0 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 11 Mar 2022 21:21:51 +0100 Subject: [PATCH 20/21] fix operations sequence --- src/families/cosmos/js-synchronisation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index b81e733840..d5eb008b08 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -33,7 +33,9 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { extra: { validators: [] as CosmosDelegationInfo[], }, - transactionSequenceNumber: tx.tx.auth_info.signer_infos.sequence, + transactionSequenceNumber: parseInt( + tx.tx.auth_info.signer_infos[0].sequence + ), }; tx.logs[0].events.forEach((message) => { From 356029650f0f6e54b1c61ed07ab9d8c32c315ec6 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Mon, 14 Mar 2022 12:21:19 +0100 Subject: [PATCH 21/21] fix multiple tx messages --- src/families/cosmos/js-synchronisation.ts | 184 +++++++++++----------- 1 file changed, 96 insertions(+), 88 deletions(-) diff --git a/src/families/cosmos/js-synchronisation.ts b/src/families/cosmos/js-synchronisation.ts index d5eb008b08..a9491b52ca 100644 --- a/src/families/cosmos/js-synchronisation.ts +++ b/src/families/cosmos/js-synchronisation.ts @@ -38,96 +38,104 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => { ), }; - tx.logs[0].events.forEach((message) => { - // parse attributes as key:value - const attributes: { [id: string]: any } = {}; - message.attributes.forEach((item) => (attributes[item.key] = item.value)); - - // https://docs.cosmos.network/v0.42/modules/staking/07_events.html - switch (message.type) { - case "transfer": - if (attributes.sender && attributes.recipient && attributes.amount) { - op.senders.push(attributes.sender); - op.recipients.push(attributes.recipient); - - if (attributes.amount.indexOf(currency.units[1].code) != -1) { - op.value = op.value.plus( - attributes.amount.replace(currency.units[1].code, "") - ); + tx.logs.forEach((log) => { + log.events.forEach((message) => { + // parse attributes as key:value + const attributes: { [id: string]: any } = {}; + message.attributes.forEach( + (item) => (attributes[item.key] = item.value) + ); + + // https://docs.cosmos.network/v0.42/modules/staking/07_events.html + switch (message.type) { + case "transfer": + if ( + attributes.sender && + attributes.recipient && + attributes.amount + ) { + op.senders.push(attributes.sender); + op.recipients.push(attributes.recipient); + + if (attributes.amount.indexOf(currency.units[1].code) != -1) { + op.value = op.value.plus( + attributes.amount.replace(currency.units[1].code, "") + ); + } + + if (!op.type && attributes.sender === address) { + op.type = "OUT"; + op.value = op.value.plus(fees); + } else if (!op.type && attributes.recipient === address) { + op.type = "IN"; + } } - - if (!op.type && attributes.sender === address) { - op.type = "OUT"; - op.value = op.value.plus(fees); - } else if (!op.type && attributes.recipient === address) { - op.type = "IN"; + break; + + case "withdraw_rewards": + if ( + (attributes.amount && + attributes.amount.indexOf(currency.units[1].code) != -1) || + // handle specifc case with empty amount value like + // tx DF458FE6A82C310837D7A33735FA5298BCF71B0BFF7A4134641AAE30F6F1050 + attributes.amount === "" + ) { + op.type = "REWARD"; + op.value = new BigNumber(fees); + op.extra.validators.push({ + address: attributes.validator, + amount: attributes.amount.replace(currency.units[1].code, ""), + }); + } + break; + + case "delegate": + if ( + attributes.amount && + attributes.amount.indexOf(currency.units[1].code) != -1 + ) { + op.type = "DELEGATE"; + op.value = new BigNumber(fees); + op.extra.validators.push({ + address: attributes.validator, + amount: attributes.amount.replace(currency.units[1].code, ""), + }); + } + break; + + case "redelegate": + if ( + attributes.amount && + attributes.amount.indexOf(currency.units[1].code) != -1 && + attributes.destination_validator && + attributes.source_validator + ) { + op.type = "REDELEGATE"; + op.value = new BigNumber(fees); + op.extra.validators.push({ + address: attributes.destination_validator, + amount: attributes.amount.replace(currency.units[1].code, ""), + }); + op.extra.cosmosSourceValidator = attributes.source_validator; + } + break; + + case "unbond": + if ( + attributes.amount && + attributes.amount.indexOf(currency.units[1].code) != -1 && + attributes.validator + ) { + op.type = "UNDELEGATE"; + op.value = new BigNumber(fees); + op.extra.validators.push({ + address: attributes.validator, + amount: attributes.amount.replace(currency.units[1].code, ""), + }); } - } - break; - - case "withdraw_rewards": - if ( - (attributes.amount && - attributes.amount.indexOf(currency.units[1].code) != -1) || - // handle specifc case with empty amount value like - // tx DF458FE6A82C310837D7A33735FA5298BCF71B0BFF7A4134641AAE30F6F1050 - attributes.amount === "" - ) { - op.type = "REWARD"; - op.value = new BigNumber(fees); - op.extra.validators.push({ - address: attributes.validator, - amount: attributes.amount.replace(currency.units[1].code, ""), - }); - } - break; - - case "delegate": - if ( - attributes.amount && - attributes.amount.indexOf(currency.units[1].code) != -1 - ) { - op.type = "DELEGATE"; - op.value = new BigNumber(fees); - op.extra.validators.push({ - address: attributes.validator, - amount: attributes.amount.replace(currency.units[1].code, ""), - }); - } - break; - - case "redelegate": - if ( - attributes.amount && - attributes.amount.indexOf(currency.units[1].code) != -1 && - attributes.destination_validator && - attributes.source_validator - ) { - op.type = "REDELEGATE"; - op.value = new BigNumber(fees); - op.extra.validators.push({ - address: attributes.destination_validator, - amount: attributes.amount.replace(currency.units[1].code, ""), - }); - op.extra.cosmosSourceValidator = attributes.source_validator; - } - break; - - case "unbond": - if ( - attributes.amount && - attributes.amount.indexOf(currency.units[1].code) != -1 && - attributes.validator - ) { - op.type = "UNDELEGATE"; - op.value = new BigNumber(fees); - op.extra.validators.push({ - address: attributes.validator, - amount: attributes.amount.replace(currency.units[1].code, ""), - }); - } - break; - } + break; + } + }); }); if (!["IN", "OUT"].includes(op.type)) {