From f155a8c34fc77aeb6d55258d6b4f9b1281123e97 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Tue, 8 Mar 2022 20:57:01 +0100 Subject: [PATCH 01/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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;