Skip to content

Commit

Permalink
Delay sending of payment account information during trade by @chimp1984
Browse files Browse the repository at this point in the history
It also removes the op return from the multisig transaction
  • Loading branch information
ripcurlx committed Jun 28, 2021
1 parent d03a472 commit e5765ae
Show file tree
Hide file tree
Showing 37 changed files with 1,192 additions and 130 deletions.
23 changes: 23 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.core.api.model.PaymentAccountForm;
import bisq.core.payment.F2FAccount;
import bisq.core.payment.NationalBankAccount;
import bisq.core.proto.CoreProtoResolver;

import bisq.common.util.Utilities;
Expand Down Expand Up @@ -133,6 +134,28 @@ protected bisq.core.payment.PaymentAccount createDummyF2FAccount(GrpcClient grpc
return f2FAccount;
}


protected bisq.core.payment.PaymentAccount createDummyBRLAccount(GrpcClient grpcClient,
String holderName,
String nationalAccountId,
String holderTaxId) {
String nationalBankAccountJsonString = "{\n" +
" \"_COMMENTS_\": [ \"Dummy Account\" ],\n" +
" \"paymentMethodId\": \"NATIONAL_BANK\",\n" +
" \"accountName\": \"Banco do Brasil\",\n" +
" \"country\": \"BR\",\n" +
" \"bankName\": \"Banco do Brasil\",\n" +
" \"branchId\": \"456789-10\",\n" +
" \"holderName\": \"" + holderName + "\",\n" +
" \"accountNr\": \"456789-87\",\n" +
" \"nationalAccountId\": \"" + nationalAccountId + "\",\n" +
" \"holderTaxId\": \"" + holderTaxId + "\"\n" +
"}\n";
NationalBankAccount nationalBankAccount =
(NationalBankAccount) createPaymentAccount(grpcClient, nationalBankAccountJsonString);
return nationalBankAccount;
}

protected final bisq.core.payment.PaymentAccount createPaymentAccount(GrpcClient grpcClient, String jsonString) {
// Normally, we do asserts on the protos from the gRPC service, but in this
// case we need a bisq.core.payment.PaymentAccount so it can be cast to its
Expand Down

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions apitest/src/test/java/bisq/apitest/scenario/TradeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import bisq.apitest.method.trade.AbstractTradeTest;
import bisq.apitest.method.trade.TakeBuyBSQOfferTest;
import bisq.apitest.method.trade.TakeBuyBTCOfferTest;
import bisq.apitest.method.trade.TakeBuyBTCOfferWithNationalBankAcctTest;
import bisq.apitest.method.trade.TakeSellBSQOfferTest;
import bisq.apitest.method.trade.TakeSellBTCOfferTest;

Expand Down Expand Up @@ -77,6 +78,17 @@ public void testTakeBuyBSQOffer(final TestInfo testInfo) {

@Test
@Order(4)
public void testTakeBuyBTCOfferWithNationalBankAcct(final TestInfo testInfo) {
TakeBuyBTCOfferWithNationalBankAcctTest test = new TakeBuyBTCOfferWithNationalBankAcctTest();
test.testTakeAlicesBuyOffer(testInfo);
test.testBankAcctDetailsIncludedInContracts(testInfo);
test.testAlicesConfirmPaymentStarted(testInfo);
test.testBobsConfirmPaymentReceived(testInfo);
test.testAlicesKeepFunds(testInfo);
}

@Test
@Order(5)
public void testTakeSellBSQOffer(final TestInfo testInfo) {
TakeSellBSQOfferTest test = new TakeSellBSQOfferTest();
TakeSellBSQOfferTest.createBsqPaymentAccounts();
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/bisq/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private static int getSubVersion(String version, int index) {
// VERSION = 0.5.0 -> TRADE_PROTOCOL_VERSION = 1
// Version 1.2.2 -> TRADE_PROTOCOL_VERSION = 2
// Version 1.5.0 -> TRADE_PROTOCOL_VERSION = 3
public static final int TRADE_PROTOCOL_VERSION = 3;
// Version 1.7.0 -> TRADE_PROTOCOL_VERSION = 4
public static final int TRADE_PROTOCOL_VERSION = 4;
private static int p2pMessageVersion;

public static final String BSQ_TX_VERSION = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public PaymentAccountPayloadInfo(String id,
this.address = address;
}

public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(PaymentAccountPayload paymentAccountPayload) {
public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(
@Nullable PaymentAccountPayload paymentAccountPayload) {
if (paymentAccountPayload == null)
return emptyPaymentAccountPayload.get();

Optional<String> address = Optional.empty();
if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload)
address = Optional.of(((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress());
Expand All @@ -58,7 +62,7 @@ else if (paymentAccountPayload instanceof InstantCryptoCurrencyPayload)
address.orElse(""));
}

// For transmitting TradeInfo messages when no contract & payloads are available.
// For transmitting TradeInfo messages when the contract or the contract's payload is not yet available.
public static Supplier<PaymentAccountPayloadInfo> emptyPaymentAccountPayload = () ->
new PaymentAccountPayloadInfo("", "", "");

Expand Down
27 changes: 2 additions & 25 deletions core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ OUT[0] dummyOutputAmount (inputAmount - tx fee)
return new InputsAndChangeOutput(new ArrayList<>(rawTransactionInputList), 0, null);
}

public PreparedDepositTxAndMakerInputs sellerAsMakerCreatesDepositTx(byte[] contractHash,
Coin makerInputAmount,
public PreparedDepositTxAndMakerInputs sellerAsMakerCreatesDepositTx(Coin makerInputAmount,
Coin msOutputAmount,
List<RawTransactionInput> takerRawTransactionInputs,
long takerChangeOutputValue,
Expand All @@ -388,7 +387,6 @@ public PreparedDepositTxAndMakerInputs sellerAsMakerCreatesDepositTx(byte[] cont
byte[] sellerPubKey)
throws SigningException, TransactionVerificationException, WalletException, AddressFormatException {
return makerCreatesDepositTx(false,
contractHash,
makerInputAmount,
msOutputAmount,
takerRawTransactionInputs,
Expand All @@ -400,8 +398,7 @@ public PreparedDepositTxAndMakerInputs sellerAsMakerCreatesDepositTx(byte[] cont
sellerPubKey);
}

public PreparedDepositTxAndMakerInputs buyerAsMakerCreatesAndSignsDepositTx(byte[] contractHash,
Coin makerInputAmount,
public PreparedDepositTxAndMakerInputs buyerAsMakerCreatesAndSignsDepositTx(Coin makerInputAmount,
Coin msOutputAmount,
List<RawTransactionInput> takerRawTransactionInputs,
long takerChangeOutputValue,
Expand All @@ -412,7 +409,6 @@ public PreparedDepositTxAndMakerInputs buyerAsMakerCreatesAndSignsDepositTx(byte
byte[] sellerPubKey)
throws SigningException, TransactionVerificationException, WalletException, AddressFormatException {
return makerCreatesDepositTx(true,
contractHash,
makerInputAmount,
msOutputAmount,
takerRawTransactionInputs,
Expand All @@ -428,7 +424,6 @@ public PreparedDepositTxAndMakerInputs buyerAsMakerCreatesAndSignsDepositTx(byte
* The maker creates the deposit transaction using the takers input(s) and optional output and signs his input(s).
*
* @param makerIsBuyer the flag indicating if we are in the maker as buyer role or the opposite
* @param contractHash the hash of the contract to be added to the OP_RETURN output
* @param makerInputAmount the input amount of the maker
* @param msOutputAmount the output amount to our MS output
* @param takerRawTransactionInputs raw data for the connected outputs for all inputs of the taker (normally 1 input)
Expand All @@ -445,7 +440,6 @@ public PreparedDepositTxAndMakerInputs buyerAsMakerCreatesAndSignsDepositTx(byte
* @throws WalletException if the maker's wallet is null or there was an error choosing deposit tx input(s) from it
*/
private PreparedDepositTxAndMakerInputs makerCreatesDepositTx(boolean makerIsBuyer,
byte[] contractHash,
Coin makerInputAmount,
Coin msOutputAmount,
List<RawTransactionInput> takerRawTransactionInputs,
Expand Down Expand Up @@ -515,11 +509,6 @@ private PreparedDepositTxAndMakerInputs makerCreatesDepositTx(boolean makerIsBuy
hashedMultiSigOutputScript.getProgram());
preparedDepositTx.addOutput(hashedMultiSigOutput);

// We add the hash ot OP_RETURN with a 0 amount output
TransactionOutput contractHashOutput = new TransactionOutput(params, preparedDepositTx, Coin.ZERO,
ScriptBuilder.createOpReturnScript(contractHash).getProgram());
preparedDepositTx.addOutput(contractHashOutput);

TransactionOutput takerTransactionOutput = null;
if (takerChangeOutputValue > 0 && takerChangeAddressString != null) {
takerTransactionOutput = new TransactionOutput(params, preparedDepositTx, Coin.valueOf(takerChangeOutputValue),
Expand Down Expand Up @@ -568,7 +557,6 @@ private PreparedDepositTxAndMakerInputs makerCreatesDepositTx(boolean makerIsBuy
* The taker signs the deposit transaction he received from the maker and publishes it.
*
* @param takerIsSeller the flag indicating if we are in the taker as seller role or the opposite
* @param contractHash the hash of the contract to be added to the OP_RETURN output
* @param makersDepositTxSerialized the prepared deposit transaction signed by the maker
* @param msOutputAmount the MultiSig output amount, as determined by the taker
* @param buyerInputs the connected outputs for all inputs of the buyer
Expand All @@ -582,7 +570,6 @@ private PreparedDepositTxAndMakerInputs makerCreatesDepositTx(boolean makerIsBuy
* @throws WalletException if the taker's wallet is null or structurally inconsistent
*/
public Transaction takerSignsDepositTx(boolean takerIsSeller,
byte[] contractHash,
byte[] makersDepositTxSerialized,
Coin msOutputAmount,
List<RawTransactionInput> buyerInputs,
Expand Down Expand Up @@ -647,16 +634,6 @@ public Transaction takerSignsDepositTx(boolean takerIsSeller,
}
}

// Check if OP_RETURN output with contract hash matches the one from the maker
TransactionOutput contractHashOutput = new TransactionOutput(params, makersDepositTx, Coin.ZERO,
ScriptBuilder.createOpReturnScript(contractHash).getProgram());
log.debug("contractHashOutput {}", contractHashOutput);
TransactionOutput makersContractHashOutput = makersDepositTx.getOutputs().get(1);
log.debug("makersContractHashOutput {}", makersContractHashOutput);
if (!makersContractHashOutput.getScriptPubKey().equals(contractHashOutput.getScriptPubKey())) {
throw new TransactionVerificationException("Maker's transaction output for the contract hash is not matching taker's version.");
}

// Add all outputs from makersDepositTx to depositTx
makersDepositTx.getOutputs().forEach(depositTx::addOutput);
WalletService.printTx("makersDepositTx", makersDepositTx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import bisq.core.trade.messages.PayoutTxPublishedMessage;
import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage;
import bisq.core.trade.messages.RefreshTradeStateRequest;
import bisq.core.trade.messages.ShareBuyerPaymentAccountMessage;
import bisq.core.trade.messages.TraderSignedWitnessMessage;

import bisq.network.p2p.AckMessage;
Expand Down Expand Up @@ -158,7 +159,9 @@ public NetworkEnvelope fromProto(protobuf.NetworkEnvelope proto) throws Protobuf
case DELAYED_PAYOUT_TX_SIGNATURE_RESPONSE:
return DelayedPayoutTxSignatureResponse.fromProto(proto.getDelayedPayoutTxSignatureResponse(), messageVersion);
case DEPOSIT_TX_AND_DELAYED_PAYOUT_TX_MESSAGE:
return DepositTxAndDelayedPayoutTxMessage.fromProto(proto.getDepositTxAndDelayedPayoutTxMessage(), messageVersion);
return DepositTxAndDelayedPayoutTxMessage.fromProto(proto.getDepositTxAndDelayedPayoutTxMessage(), this, messageVersion);
case SHARE_BUYER_PAYMENT_ACCOUNT_MESSAGE:
return ShareBuyerPaymentAccountMessage.fromProto(proto.getShareBuyerPaymentAccountMessage(), this, messageVersion);

case COUNTER_CURRENCY_TRANSFER_STARTED_MESSAGE:
return CounterCurrencyTransferStartedMessage.fromProto(proto.getCounterCurrencyTransferStartedMessage(), messageVersion);
Expand Down
Loading

0 comments on commit e5765ae

Please sign in to comment.