diff --git a/cw_decred/lib/wallet.dart b/cw_decred/lib/wallet.dart index 0be881b06e..01bc034a6b 100644 --- a/cw_decred/lib/wallet.dart +++ b/cw_decred/lib/wallet.dart @@ -128,7 +128,7 @@ abstract class DecredWalletBase syncTimer = Timer.periodic( Duration(seconds: syncIntervalSynced), (Timer t) => performBackgroundTasks()); } - updateTransactionHistory(); + await updateTransactionHistory(); } Future updateTransactionHistory() async { @@ -292,30 +292,29 @@ abstract class DecredWalletBase throw "unable to send with watching only wallet"; }); } + var totalIn = 0; final ignoreInputs = []; this.unspentCoinsInfo.values.forEach((unspent) { if (unspent.isFrozen || !unspent.isSending) { final input = {"txid": unspent.hash, "vout": unspent.vout}; ignoreInputs.add(input); + return; } + totalIn += unspent.value; }); final creds = credentials as DecredTransactionCredentials; var totalAmt = 0; + var sendAll = false; final outputs = []; for (final out in creds.outputs) { var amt = 0; if (out.sendAll) { - // get all spendable inputs amount - totalAmt = unspentCoinsInfo.values.fold(0, (sum, unspent) { - if (unspent.isFrozen || !unspent.isSending) { - return sum; - } - - return sum + unspent.value; - }); - break; - } - if (out.cryptoAmount != null) { + if (creds.outputs.length != 1) { + throw "can only send all to one output"; + } + sendAll = true; + totalAmt = totalIn; + } else if (out.cryptoAmount != null) { final coins = double.parse(out.cryptoAmount!); amt = (coins * 1e8).toInt(); } @@ -328,26 +327,28 @@ abstract class DecredWalletBase } // The inputs are always used. Currently we don't have use for this - // argument. + // argument. sendall ingores output value and sends everything. final signReq = { // "inputs": inputs, "ignoreInputs": ignoreInputs, "outputs": outputs, "feerate": creds.feeRate ?? defaultFeeRate, "password": _password, + "sendall": sendAll, }; final res = libdcrwallet.createSignedTransaction(walletInfo.name, jsonEncode(signReq)); final decoded = json.decode(res); final signedHex = decoded["signedhex"]; final send = () async { libdcrwallet.sendRawTransaction(walletInfo.name, signedHex); + await updateBalance(); }; + final fee = decoded["fee"] ?? 0; + if (sendAll) { + totalAmt = (totalAmt - fee).toInt() ?? totalAmt; + } return DecredPendingTransaction( - txid: decoded["txid"] ?? "", - amount: totalAmt, - fee: decoded["fee"] ?? 0, - rawHex: signedHex, - send: send); + txid: decoded["txid"] ?? "", amount: totalAmt, fee: fee, rawHex: signedHex, send: send); } int feeRate(TransactionPriority priority) { diff --git a/scripts/android/build_decred.sh b/scripts/android/build_decred.sh index d384613aba..493880a774 100755 --- a/scripts/android/build_decred.sh +++ b/scripts/android/build_decred.sh @@ -7,7 +7,7 @@ cd "$(dirname "$0")" CW_DECRED_DIR=$(realpath ../..)/cw_decred LIBWALLET_PATH="${PWD}/decred/libwallet" LIBWALLET_URL="https://github.com/decred/libwallet.git" -LIBWALLET_VERSION="10344df786c8d488d46ebf38f259efddd7094913" +LIBWALLET_VERSION="82ed8a80ae9fa3b15a2d5609bc748fc663be7e37" # v2.2.1 if [ -e $LIBWALLET_PATH ]; then rm -fr $LIBWALLET_PATH/{*,.*} || true @@ -62,4 +62,4 @@ done HEADER_DIR=$CW_DECRED_DIR/lib/api cp ${LIBWALLET_PATH}/build/${TRIPLET}-libdcrwallet.h $HEADER_DIR/libdcrwallet.h cd $CW_DECRED_DIR -dart run ffigen \ No newline at end of file +dart run ffigen diff --git a/scripts/ios/build_decred.sh b/scripts/ios/build_decred.sh index 502a6b04a9..0387dca0c8 100755 --- a/scripts/ios/build_decred.sh +++ b/scripts/ios/build_decred.sh @@ -3,7 +3,7 @@ set -e . ./config.sh LIBWALLET_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libwallet" LIBWALLET_URL="https://github.com/decred/libwallet.git" -LIBWALLET_VERSION="10344df786c8d488d46ebf38f259efddd7094913" +LIBWALLET_VERSION="82ed8a80ae9fa3b15a2d5609bc748fc663be7e37" # v2.2.1 if [ -e $LIBWALLET_PATH ]; then rm -fr $LIBWALLET_PATH diff --git a/scripts/macos/build_decred.sh b/scripts/macos/build_decred.sh index a783829af1..6f2b4eceff 100755 --- a/scripts/macos/build_decred.sh +++ b/scripts/macos/build_decred.sh @@ -4,7 +4,7 @@ LIBWALLET_PATH="${EXTERNAL_MACOS_SOURCE_DIR}/libwallet" LIBWALLET_URL="https://github.com/decred/libwallet.git" -LIBWALLET_VERSION="v2.1.0" +LIBWALLET_VERSION="82ed8a80ae9fa3b15a2d5609bc748fc663be7e37" # v2.2.1 echo "======================= DECRED LIBWALLET ========================="