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