CW-702: fix mismatched amounts in multDest transactions (#1653)

* CW-702: fix mismatched amounts in multDest transactions * separate txkeys in multdest transactions * update monero_c dependency

cyan committed Sep 5, 2024 at 04:54 UTC 0b06ad3a0700296c626bbadb91db81f789be2a95
7 files changed +46 -10
cw_monero/lib/api/transaction_history.dart
+36 -3
@@ -138,11 +138,17 @@ PendingTransactionDescription createTransactionMultDestSync(
138 int accountIndex = 0,
139 List<String> preferredInputs = const []}) {
140
141 + final dstAddrs = outputs.map((e) => e.address).toList();
142 + final amounts = outputs.map((e) => monero.Wallet_amountFromString(e.amount)).toList();
143 +
144 + // print("multDest: dstAddrs: $dstAddrs");
145 + // print("multDest: amounts: $amounts");
146 +
147 final txptr = monero.Wallet_createTransactionMultDest(
148 wptr!,
143 - dstAddr: outputs.map((e) => e.address).toList(),
149 + dstAddr: dstAddrs,
150 isSweepAll: false,
145 - amounts: outputs.map((e) => monero.Wallet_amountFromString(e.amount)).toList(),
151 + amounts: amounts,
152 mixinCount: 0,
153 pendingTransactionPriority: priorityRaw,
154 subaddr_account: accountIndex,
@@ -307,7 +313,34 @@ class Transaction {
313 confirmations = monero.TransactionInfo_confirmations(txInfo),
314 fee = monero.TransactionInfo_fee(txInfo),
315 description = monero.TransactionInfo_description(txInfo),
310 - key = monero.Wallet_getTxKey(wptr!, txid: monero.TransactionInfo_hash(txInfo));
316 + key = getTxKey(txInfo);
317 +
318 + static String getTxKey(monero.TransactionInfo txInfo) {
319 + final txKey = monero.Wallet_getTxKey(wptr!, txid: monero.TransactionInfo_hash(txInfo));
320 + final status = monero.Wallet_status(wptr!);
321 + if (status != 0) {
322 + return monero.Wallet_errorString(wptr!);
323 + }
324 + return breakTxKey(txKey);
325 + }
326 +
327 + static String breakTxKey(String input) {
328 + final x = 64;
329 + StringBuffer buffer = StringBuffer();
330 +
331 + for (int i = 0; i < input.length; i += x) {
332 + int endIndex = i + x;
333 + if (endIndex > input.length) {
334 + endIndex = input.length;
335 + }
336 + buffer.write(input.substring(i, endIndex));
337 + if (endIndex != input.length) {
338 + buffer.write('\n\n');
339 + }
340 + }
341 +
342 + return buffer.toString().trim();
343 + }
344
345 Transaction.dummy({
346 required this.displayLabel,
cw_monero/pubspec.lock
+2 -2
@@ -463,8 +463,8 @@ packages:
463 dependency: "direct main"
464 description:
465 path: "impls/monero.dart"
466 - ref: bcb328a4956105dc182afd0ce2e48fe263f5f20b
467 - resolved-ref: bcb328a4956105dc182afd0ce2e48fe263f5f20b
466 + ref: 3cb38bee9385faf46b03fd73aab85f3ac4115bf7
467 + resolved-ref: 3cb38bee9385faf46b03fd73aab85f3ac4115bf7
468 url: "https://github.com/mrcyjanek/monero_c"
469 source: git
470 version: "0.0.0"
cw_monero/pubspec.yaml
+1 -1
@@ -25,7 +25,7 @@ dependencies:
25 monero:
26 git:
27 url: https://github.com/mrcyjanek/monero_c
28 - ref: bcb328a4956105dc182afd0ce2e48fe263f5f20b # monero_c hash
28 + ref: 3cb38bee9385faf46b03fd73aab85f3ac4115bf7 # monero_c hash
29 path: impls/monero.dart
30 mutex: ^3.1.0
31
cw_wownero/pubspec.lock
+2 -2
@@ -463,8 +463,8 @@ packages:
463 dependency: "direct main"
464 description:
465 path: "impls/monero.dart"
466 - ref: bcb328a4956105dc182afd0ce2e48fe263f5f20b
467 - resolved-ref: bcb328a4956105dc182afd0ce2e48fe263f5f20b
466 + ref: 3cb38bee9385faf46b03fd73aab85f3ac4115bf7
467 + resolved-ref: 3cb38bee9385faf46b03fd73aab85f3ac4115bf7
468 url: "https://github.com/mrcyjanek/monero_c"
469 source: git
470 version: "0.0.0"
cw_wownero/pubspec.yaml
+1 -1
@@ -25,7 +25,7 @@ dependencies:
25 monero:
26 git:
27 url: https://github.com/mrcyjanek/monero_c
28 - ref: bcb328a4956105dc182afd0ce2e48fe263f5f20b # monero_c hash
28 + ref: 3cb38bee9385faf46b03fd73aab85f3ac4115bf7 # monero_c hash
29 path: impls/monero.dart
30 mutex: ^3.1.0
31
lib/src/screens/send/send_page.dart
+3
@@ -273,6 +273,7 @@ class SendPage extends BasePage {
273 ? template.cryptoCurrency
274 : template.fiatCurrency,
275 onTap: () async {
276 + sendViewModel.state = IsExecutingState();
277 if (template.additionalRecipients?.isNotEmpty ?? false) {
278 sendViewModel.clearOutputs();
279
@@ -301,6 +302,7 @@ class SendPage extends BasePage {
302 template: template,
303 );
304 }
305 + sendViewModel.state = InitialExecutionState();
306 },
307 onRemove: () {
308 showPopUp<void>(
@@ -368,6 +370,7 @@ class SendPage extends BasePage {
370 builder: (_) {
371 return LoadingPrimaryButton(
372 onPressed: () async {
373 + if (sendViewModel.state is IsExecutingState) return;
374 if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
375 if (sendViewModel.outputs.length > 1) {
376 showErrorValidationAlert(context);
scripts/prepare_moneroc.sh
+1 -1
@@ -8,7 +8,7 @@ if [[ ! -d "monero_c" ]];
8 then
9 git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip
10 cd monero_c
11 - git checkout 5de323b1ba7387cf73973042f06383d4dbe619f5
11 + git checkout 3cb38bee9385faf46b03fd73aab85f3ac4115bf7
12 git reset --hard
13 git submodule update --init --force --recursive
14 ./apply_patches.sh monero