|
1 | | -import _ from 'lodash'; |
2 | 1 | import { |
3 | 2 | AuditDecryptedKeyParams, |
4 | 3 | BaseCoin, |
@@ -116,39 +115,27 @@ export class Stx extends BaseCoin { |
116 | 115 | throw new Error('missing required tx prebuild property txHex'); |
117 | 116 | } |
118 | 117 | const explainedTx = await this.explainTransaction({ txHex: rawTx, feeInfo: { fee: '' } }); |
119 | | - if (txParams.recipients !== undefined && explainedTx) { |
120 | | - const filteredRecipients = txParams.recipients.map((recipient) => { |
121 | | - const addressDetails = getMemoIdAndBaseAddressFromAddress(recipient.address); |
122 | | - return { |
123 | | - address: addressDetails.address, |
124 | | - amount: BigInt(recipient.amount), |
125 | | - }; |
126 | | - }); |
127 | | - const filteredOutputs = explainedTx.outputs.map((output) => ({ |
128 | | - address: output.address, |
129 | | - amount: BigInt(output.amount), |
130 | | - })); |
131 | | - if (!_.isEqual(filteredOutputs, filteredRecipients)) { |
| 118 | + const recipient = txParams.recipients?.[0]; |
| 119 | + if (recipient !== undefined && explainedTx) { |
| 120 | + const txOutput = explainedTx.outputs[0]; |
| 121 | + const recipientAddress = getMemoIdAndBaseAddressFromAddress(recipient.address).address; |
| 122 | + if (txOutput?.address !== recipientAddress || BigInt(txOutput?.amount) !== BigInt(recipient.amount)) { |
132 | 123 | throw new Error('Tx outputs does not match with expected txParams recipients'); |
133 | 124 | } |
134 | 125 | // compare memo |
135 | 126 | let memoInput = ''; |
136 | | - let memoOutput = ''; |
137 | 127 | if (memo && memo.value) { |
138 | 128 | memoInput = memo.value; |
139 | | - } else if (txParams.recipients.length) { |
140 | | - const addressDetails = getMemoIdAndBaseAddressFromAddress(txParams.recipients[0].address); |
141 | | - memoInput = addressDetails.memoId ? addressDetails.memoId : ''; |
142 | | - } |
143 | | - if (explainedTx.memo) { |
144 | | - memoOutput = explainedTx.memo; |
| 129 | + } else { |
| 130 | + const addressDetails = getMemoIdAndBaseAddressFromAddress(recipient.address); |
| 131 | + memoInput = addressDetails.memoId ?? ''; |
145 | 132 | } |
146 | | - if (!_.isEqual(memoInput, memoOutput)) { |
| 133 | + const memoOutput = explainedTx.memo ?? ''; |
| 134 | + if (memoInput !== memoOutput) { |
147 | 135 | throw new Error('Tx memo does not match with expected txParams recipient memo'); |
148 | 136 | } |
149 | | - // compare send amount — STX supports only one recipient, validated above |
150 | | - const recipientAmount = txParams.recipients.length ? new BigNumber(txParams.recipients[0].amount) : new BigNumber(0); |
151 | | - if (!recipientAmount.isEqualTo(explainedTx.outputAmount)) { |
| 137 | + // compare amount |
| 138 | + if (!new BigNumber(recipient.amount).isEqualTo(explainedTx.outputAmount)) { |
152 | 139 | throw new Error('Tx total amount does not match with expected total amount field'); |
153 | 140 | } |
154 | 141 | } |
|
0 commit comments