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