diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinLedgerWrapper.java b/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinLedgerWrapper.java index c58a936605..f87d7eabb5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinLedgerWrapper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinLedgerWrapper.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; import org.thoughtcrime.securesms.payments.proto.MobileCoinLedger; import org.whispersystems.signalservice.api.payments.Money; +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -18,8 +19,8 @@ public final class MobileCoinLedgerWrapper { private final Balance balance; public MobileCoinLedgerWrapper(@NonNull MobileCoinLedger ledger) { - Money.MobileCoin fullAmount = Money.picoMobileCoin(ledger.balance); - Money.MobileCoin transferableAmount = Money.picoMobileCoin(ledger.transferableBalance); + Money.MobileCoin fullAmount = ledger.balance.size() > 0 ? Money.picoMobileCoin(new BigInteger(ledger.balance.toByteArray())) : Money.picoMobileCoin(ledger.deprecatedBalance); + Money.MobileCoin transferableAmount = ledger.transferableBalance.size() > 0 ? Money.picoMobileCoin(new BigInteger(ledger.transferableBalance.toByteArray())) : Money.picoMobileCoin(ledger.deprecatedTransferableBalance); this.ledger = ledger; this.balance = new Balance(fullAmount, transferableAmount, ledger.asOfTimeStamp); @@ -54,7 +55,7 @@ public final class MobileCoinLedgerWrapper { } public @NonNull Money.MobileCoin getValue() { - return Money.picoMobileCoin(ownedTXO.amount); + return ownedTXO.amount.size() > 0 ? Money.picoMobileCoin(new BigInteger(ownedTXO.amount.toByteArray())) : Money.picoMobileCoin(ownedTXO.deprecatedAmount); } public @NonNull ByteString getKeyImage() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java b/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java index 9bed32be43..23f35aaf6e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java @@ -165,7 +165,7 @@ public final class Wallet { for (OwnedTxOut txOut : accountSnapshot.getAccountActivity().getAllTokenTxOuts(TokenId.MOB)) { final Amount txOutAmount = txOut.getAmount(); MobileCoinLedger.OwnedTXO.Builder txoBuilder = new MobileCoinLedger.OwnedTXO.Builder() - .amount(Uint64Util.bigIntegerToUInt64(txOutAmount.getValue())) + .amount(ByteString.of(txOutAmount.getValue().toByteArray())) .receivedInBlock(getBlock(txOut.getReceivedBlockIndex(), txOut.getReceivedBlockTimestamp())) .keyImage(ByteString.of(txOut.getKeyImage().getData())) .publicKey(ByteString.of(txOut.getPublicKey().getKeyBytes())); @@ -198,8 +198,8 @@ public final class Wallet { builder.spentTxos(spentTxos) .unspentTxos(unspentTxos) - .balance(Uint64Util.bigIntegerToUInt64(totalUnspent)) - .transferableBalance(Uint64Util.bigIntegerToUInt64(accountSnapshot.getTransferableAmount(minimumTxFee).getValue())) + .balance(ByteString.of(totalUnspent.toByteArray())) + .transferableBalance(ByteString.of(accountSnapshot.getTransferableAmount(minimumTxFee).getValue().toByteArray())) .asOfTimeStamp(asOfTimestamp) .highestBlock(new MobileCoinLedger.Block.Builder() .blockNumber(highestBlockIndex.longValue()) diff --git a/app/src/main/protowire/Payments.proto b/app/src/main/protowire/Payments.proto index 4872263893..2af6146a71 100644 --- a/app/src/main/protowire/Payments.proto +++ b/app/src/main/protowire/Payments.proto @@ -8,11 +8,13 @@ option java_multiple_files = true; message MobileCoinLedger { message OwnedTXO { - uint64 amount = 1; - bytes keyImage = 2; - bytes publicKey = 3; - Block receivedInBlock = 4; - Block spentInBlock = 5; + uint64 deprecatedAmount = 1; + bytes amount = 6; + bytes keyImage = 2; + bytes publicKey = 3; + Block receivedInBlock = 4; + Block spentInBlock = 5; + // Next is 7 } message Block { @@ -20,12 +22,15 @@ message MobileCoinLedger { uint64 timestamp = 2; } - uint64 balance = 1; - uint64 transferableBalance = 2; - Block highestBlock = 3; - uint64 asOfTimeStamp = 4; - repeated OwnedTXO spentTxos = 5; - repeated OwnedTXO unspentTxos = 6; + uint64 deprecatedBalance = 1; + bytes balance = 7; + uint64 deprecatedTransferableBalance = 2; + bytes transferableBalance = 8; + Block highestBlock = 3; + uint64 asOfTimeStamp = 4; + repeated OwnedTXO spentTxos = 5; + repeated OwnedTXO unspentTxos = 6; + // Next is 9 } message PaymentMetaData { diff --git a/app/src/test/java/org/thoughtcrime/securesms/payments/reconciliation/LedgerReconcileTest.java b/app/src/test/java/org/thoughtcrime/securesms/payments/reconciliation/LedgerReconcileTest.java index 8aecadbc01..973d60ee03 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/payments/reconciliation/LedgerReconcileTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/payments/reconciliation/LedgerReconcileTest.java @@ -257,16 +257,11 @@ public final class LedgerReconcileTest { if (mob.isNegative()) { throw new AssertionError(); } - MobileCoinLedger.OwnedTXO.Builder builder = new MobileCoinLedger.OwnedTXO.Builder() - .receivedInBlock(receivedBlock) - .keyImage(keyImage) - .publicKey(publicKey); - try { - builder.amount(Uint64Util.bigIntegerToUInt64(mob.toPicoMobBigInteger())); - } catch (Uint64RangeException e) { - throw new AssertionError(e); - } - return builder; + return new MobileCoinLedger.OwnedTXO.Builder() + .amount(ByteString.of(mob.toPicoMobBigInteger().toByteArray())) + .receivedInBlock(receivedBlock) + .keyImage(keyImage) + .publicKey(publicKey); } private static Payment payment(String note, Money.MobileCoin valueAndDirection, Set keyImages, Set publicKeys) {