diff --git a/core/src/main/java/io/bitsquare/btc/AddressEntry.java b/core/src/main/java/io/bitsquare/btc/AddressEntry.java index 509403be3f..e670eda34f 100644 --- a/core/src/main/java/io/bitsquare/btc/AddressEntry.java +++ b/core/src/main/java/io/bitsquare/btc/AddressEntry.java @@ -19,7 +19,6 @@ package io.bitsquare.btc; import org.bitcoinj.core.Address; import org.bitcoinj.core.NetworkParameters; -import org.bitcoinj.core.Utils; import org.bitcoinj.crypto.DeterministicKey; import java.io.Serializable; @@ -32,26 +31,25 @@ import java.util.Arrays; */ public class AddressEntry implements Serializable { private static final long serialVersionUID = 5501603992599920416L; - private transient DeterministicKey key; + private transient DeterministicKey keyPair; private final NetworkParameters params; private final AddressContext addressContext; private final String offerId; private final byte[] pubKey; private final byte[] pubKeyHash; - - public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext) { - this(key, params, addressContext, null); + public AddressEntry(DeterministicKey keyPair, NetworkParameters params, AddressContext addressContext) { + this(keyPair, params, addressContext, null); } - public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext, String offerId) { - this.key = key; + public AddressEntry(DeterministicKey keyPair, NetworkParameters params, AddressContext addressContext, String offerId) { + this.keyPair = keyPair; this.params = params; this.addressContext = addressContext; this.offerId = offerId; - pubKey = key.getPubOnly().getPubKey(); - pubKeyHash = key.getPubOnly().getPubKeyHash(); + pubKey = keyPair.getPubOnly().getPubKey(); + pubKeyHash = keyPair.getPubOnly().getPubKeyHash(); } public String getOfferId() { @@ -66,20 +64,16 @@ public class AddressEntry implements Serializable { return getAddress().toString(); } - public String getPubKeyAsHex() { - return Utils.HEX.encode(key.getPubKey()); - } - - public DeterministicKey getKey() { - return key; + public DeterministicKey getKeyPair() { + return keyPair; } public Address getAddress() { - return key.toAddress(params); + return keyPair.toAddress(params); } - public void setDeterministicKey(DeterministicKey key) { - this.key = key; + public void setDeterministicKey(DeterministicKey deterministicKey) { + this.keyPair = deterministicKey; } public byte[] getPubKeyHash() { @@ -100,7 +94,7 @@ public class AddressEntry implements Serializable { public String toString() { return "AddressEntry{" + "addressString=" + getAddress().toString() + - "key=" + key + + "key=" + keyPair + ", params=" + params + ", addressContext=" + addressContext + ", offerId='" + offerId + '\'' + diff --git a/core/src/main/java/io/bitsquare/btc/WalletService.java b/core/src/main/java/io/bitsquare/btc/WalletService.java index c18b5db544..f012f857b1 100644 --- a/core/src/main/java/io/bitsquare/btc/WalletService.java +++ b/core/src/main/java/io/bitsquare/btc/WalletService.java @@ -490,8 +490,7 @@ public class WalletService { Transaction tx = new Transaction(params); - byte[] data = signatureService.digestMessageWithSignature( - getRegistrationAddressEntry().getKey(), stringifiedBankAccounts); + byte[] data = signatureService.digestMessageWithSignature(getRegistrationAddressEntry().getKeyPair(), stringifiedBankAccounts); tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, new ScriptBuilder().op(OP_RETURN).data(data).build()); // We don't take a fee at the moment @@ -615,7 +614,7 @@ public class WalletService { Transaction dummyTX = new Transaction(params); // The output is just used to get the right inputs and change outputs, so we use an anonymous ECKey, as it will never be used for anything. // We don't care about fee calculation differences between the real tx and that dummy tx as we use a static tx fee. - TransactionOutput msOutput = new TransactionOutput(params, dummyTX, dummyOutputAmount, new ECKey()); + TransactionOutput msOutput = new TransactionOutput(params, dummyTX, dummyOutputAmount, new ECKey().toAddress(params)); dummyTX.addOutput(msOutput); // Fin the needed inputs to pay the output, optional add change output. @@ -670,7 +669,7 @@ public class WalletService { TransactionVerificationException, WalletException { // TODO verify amounts, addresses, MS - + Transaction depositTx = new Transaction(params); Script multiSigOutputScript = getMultiSigOutputScript(offererPubKey, takerPubKey, arbitratorPubKey); // We use temporary inputAmount as the value for the output amount to get the correct inputs from the takers side. @@ -719,8 +718,8 @@ public class WalletService { // Taker inputs are the first inputs (0 -n), so the index of takerInputs and depositTx.getInputs() matches for the number of takerInputs. int index = 0; for (TransactionInput input : takerInputs) { - log.debug("signInput input "+input.toString()); - log.debug("signInput index "+index); + log.debug("signInput input " + input.toString()); + log.debug("signInput index " + index); signInput(depositTx, input, index); checkScriptSig(depositTx, input, index); index++; @@ -746,7 +745,7 @@ public class WalletService { FutureCallback callback) throws SigningException, TransactionVerificationException, WalletException { // TODO verify amounts, addresses, MS - + // The outpoints are not available from the serialized takersDepositTx, so we cannot use that tx directly, but we use it to construct a new depositTx Transaction depositTx = new Transaction(params); @@ -782,7 +781,7 @@ public class WalletService { printInputs("depositTx", depositTx); log.debug("depositTx = " + depositTx); - + // Offerer inputs are the first inputs (0 -n), so the index of offererInputs and depositTx.getInputs() matches for the number of offererInputs. int index = 0; for (TransactionInput input : offererInputs) { @@ -797,7 +796,7 @@ public class WalletService { verifyTransaction(depositTx); checkWalletConsistency(); checkScriptSigForAllInputs(depositTx); - + // Broadcast depositTx log.trace("Wallet balance before broadcastTransaction: " + wallet.getBalance()); log.trace("Check if wallet is consistent before broadcastTransaction: result=" + wallet.isConsistent()); @@ -813,9 +812,9 @@ public class WalletService { log.trace("inputs: "); log.trace("depositTx=" + depositTx); // If not recreate the tx we get a null pointer at receivePending - log.debug("tx id "+depositTx.getHashAsString()); + log.debug("tx id " + depositTx.getHashAsString()); depositTx = new Transaction(params, depositTx.bitcoinSerialize()); - log.debug("tx id "+depositTx.getHashAsString()); + log.debug("tx id " + depositTx.getHashAsString()); log.trace("depositTx=" + depositTx); // boolean isAlreadyInWallet = wallet.maybeCommitTx(depositTx); //log.trace("isAlreadyInWallet=" + isAlreadyInWallet); @@ -859,7 +858,7 @@ public class WalletService { TransactionOutput multiSigOutput = tx.getInput(0).getConnectedOutput(); Script multiSigScript = multiSigOutput.getScriptPubKey(); Sha256Hash sigHash = tx.hashForSignature(0, multiSigScript, Transaction.SigHash.ALL, false); - ECKey.ECDSASignature offererSignature = getAddressInfo(tradeID).getKey().sign(sigHash); + ECKey.ECDSASignature offererSignature = getAddressInfo(tradeID).getKeyPair().sign(sigHash); TransactionSignature offererTxSig = new TransactionSignature(offererSignature, Transaction.SigHash.ALL, false); Script inputScript = ScriptBuilder.createMultiSigInputScript(ImmutableList.of(offererTxSig)); @@ -895,7 +894,7 @@ public class WalletService { Sha256Hash sigHash = tx.hashForSignature(0, multiSigScript, Transaction.SigHash.ALL, false); log.trace("sigHash=" + sigHash); - ECKey.ECDSASignature takerSignature = getAddressInfo(tradeID).getKey().sign(sigHash); + ECKey.ECDSASignature takerSignature = getAddressInfo(tradeID).getKeyPair().sign(sigHash); TransactionSignature takerTxSig = new TransactionSignature(takerSignature, Transaction.SigHash.ALL, false); TransactionSignature offererTxSig = new TransactionSignature(offererSignature, Transaction.SigHash.ALL, false); diff --git a/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java b/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java index 1bc18b7aa9..370d7855fc 100644 --- a/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java @@ -157,7 +157,7 @@ class MainViewModel implements ViewModel { error -> log.error(error.toString()), () -> Platform.runLater(() -> setBitcoinNetworkSyncProgress(1.0))); - Observable messageObservable = clientNode.bootstrap(user.getMessageKeyPair(), tradeMessageService); + Observable messageObservable = clientNode.bootstrap(user.getNetworkKeyPair(), tradeMessageService); messageObservable.publish(); messageObservable.subscribe( state -> Platform.runLater(() -> setBootstrapState(state)), @@ -350,9 +350,9 @@ class MainViewModel implements ViewModel { } private void addMockArbitrator() { - if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) { + if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getNetworkKeyPair() != null) { byte[] pubKey = new ECKey().getPubKey(); - String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey()); + String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getNetworkPubKey()); List languages = new ArrayList<>(); languages.add(LanguageUtil.getDefaultLanguageLocale()); List arbitrationMethods = new ArrayList<>(); diff --git a/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java b/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java index 83611383ab..54cf771901 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java @@ -370,7 +370,7 @@ public class ArbitratorRegistrationView extends ActivatableView languages = new ArrayList<>(); languages.add(LanguageUtil.getDefaultLanguageLocale()); List arbitrationMethods = new ArrayList<>(); diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsDataModel.java b/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsDataModel.java index bbc0fc42b3..8415cf76de 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsDataModel.java @@ -152,9 +152,9 @@ class RestrictionsDataModel implements Activatable, DataModel { // TODO Remove mock later private void addMockArbitrator() { - if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) { + if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getNetworkKeyPair() != null) { byte[] pubKey = new ECKey().getPubKey(); - String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey()); + String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getNetworkPubKey()); List languages = new ArrayList<>(); languages.add(LanguageUtil.getDefaultLanguageLocale()); List arbitrationMethods = new ArrayList<>(); diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/closed/ClosedTradesDataModel.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/closed/ClosedTradesDataModel.java index 8fa869453d..94b0181ee3 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/closed/ClosedTradesDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/closed/ClosedTradesDataModel.java @@ -74,7 +74,7 @@ class ClosedTradesDataModel implements Activatable, DataModel { } public Direction getDirection(Offer offer) { - return offer.getMessagePublicKey().equals(user.getMessagePublicKey()) ? + return offer.getMessagePublicKey().equals(user.getNetworkPubKey()) ? offer.getDirection() : offer.getMirroredDirection(); } diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/offer/OffersDataModel.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/offer/OffersDataModel.java index d9fbe5e3d8..c8789e1570 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/offer/OffersDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/offer/OffersDataModel.java @@ -88,7 +88,7 @@ class OffersDataModel implements Activatable, DataModel { public Direction getDirection(OpenOffer openOffer) { Offer offer = openOffer.getOffer(); - return offer.getMessagePublicKey().equals(user.getMessagePublicKey()) ? + return offer.getMessagePublicKey().equals(user.getNetworkPubKey()) ? offer.getDirection() : offer.getMirroredDirection(); } } diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java index f71750af00..6e9ca934e2 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java @@ -130,7 +130,7 @@ class PendingTradesDataModel implements Activatable, DataModel { selectedItem = item; if (selectedItem != null) { - isOfferer = getTrade().getOffer().getMessagePublicKey().equals(user.getMessagePublicKey()); + isOfferer = getTrade().getOffer().getMessagePublicKey().equals(user.getNetworkPubKey()); Trade trade = getTrade(); trade.stateProperty().addListener(stateChangeListener); @@ -253,7 +253,7 @@ class PendingTradesDataModel implements Activatable, DataModel { } public Direction getDirection(Offer offer) { - return offer.getMessagePublicKey().equals(user.getMessagePublicKey()) ? + return offer.getMessagePublicKey().equals(user.getNetworkPubKey()) ? offer.getDirection() : offer.getMirroredDirection(); } diff --git a/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java b/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java index 4d13d23307..bb39df2461 100644 --- a/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java @@ -213,7 +213,7 @@ class OfferBookDataModel implements Activatable, DataModel { } boolean isMyOffer(Offer offer) { - return offer.getMessagePublicKey() != null && offer.getMessagePublicKey().equals(user.getMessagePublicKey()); + return offer.getMessagePublicKey() != null && offer.getMessagePublicKey().equals(user.getNetworkPubKey()); } Coin getAmountAsCoin() { diff --git a/core/src/main/java/io/bitsquare/trade/TradeManager.java b/core/src/main/java/io/bitsquare/trade/TradeManager.java index d4f5a45bfb..9db6cbd408 100644 --- a/core/src/main/java/io/bitsquare/trade/TradeManager.java +++ b/core/src/main/java/io/bitsquare/trade/TradeManager.java @@ -167,7 +167,7 @@ public class TradeManager { BankAccount currentBankAccount = user.getCurrentBankAccount().get(); Offer offer = new Offer(id, - user.getMessagePublicKey(), + user.getNetworkPubKey(), direction, price.getValue(), amount, diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/OfferSharedModel.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/OfferSharedModel.java index 3859ee7958..02385a5adb 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/OfferSharedModel.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/OfferSharedModel.java @@ -27,7 +27,7 @@ import io.bitsquare.trade.TradeMessageService; import io.bitsquare.user.User; import io.bitsquare.util.taskrunner.SharedModel; -import org.bitcoinj.core.ECKey; +import org.bitcoinj.crypto.DeterministicKey; import java.security.PublicKey; @@ -47,18 +47,15 @@ public class OfferSharedModel extends SharedModel { // derived protected final BankAccount bankAccount; protected final String accountId; - protected final PublicKey messagePublicKey; - protected final ECKey accountKey; - protected final byte[] arbitratorPubKey; + protected final PublicKey networkPubKey; + protected final byte[] registrationPubKey; - // lazy initialized at first read access, as we don't want to create an entry before it is really needed - protected AddressEntry addressInfo; + protected final DeterministicKey registrationKeyPair; + protected final byte[] arbitratorPubKey; + protected final AddressEntry addressInfo; // data written/read by tasks protected TradeMessage tradeMessage; - protected byte[] takerPubKey; - protected String peersAccountId; - protected BankAccount peersBankAccount; public OfferSharedModel(Offer offer, TradeMessageService tradeMessageService, @@ -74,34 +71,26 @@ public class OfferSharedModel extends SharedModel { //TODO use default arbitrator for now arbitratorPubKey = offer.getArbitrators().get(0).getPubKey(); + registrationPubKey = walletService.getRegistrationAddressEntry().getPubKey(); + registrationKeyPair = walletService.getRegistrationAddressEntry().getKeyPair(); + addressInfo = walletService.getAddressInfo(offer.getId()); bankAccount = user.getBankAccount(offer.getBankAccountId()); accountId = user.getAccountId(); - messagePublicKey = user.getMessagePublicKey(); - accountKey = walletService.getRegistrationAddressEntry().getKey(); + networkPubKey = user.getNetworkPubKey(); } // getter/setter - public AddressEntry getAddressInfo() { - if (addressInfo == null) - addressInfo = getWalletService().getAddressInfo(offer.getId()); - return addressInfo; + public TradeMessage getTradeMessage() { + return tradeMessage; } - public String getPeersAccountId() { - return peersAccountId; + public void setTradeMessage(TradeMessage tradeMessage) { + this.tradeMessage = tradeMessage; } - public void setPeersAccountId(String peersAccountId) { - this.peersAccountId = peersAccountId; - } - - public BankAccount getPeersBankAccount() { - return peersBankAccount; - } - - public void setPeersBankAccount(BankAccount peersBankAccount) { - this.peersBankAccount = peersBankAccount; + public Offer getOffer() { + return offer; } public TradeMessageService getTradeMessageService() { @@ -120,14 +109,6 @@ public class OfferSharedModel extends SharedModel { return signatureService; } - public Offer getOffer() { - return offer; - } - - public byte[] getArbitratorPubKey() { - return arbitratorPubKey; - } - public BankAccount getBankAccount() { return bankAccount; } @@ -136,44 +117,24 @@ public class OfferSharedModel extends SharedModel { return accountId; } - public PublicKey getMessagePublicKey() { - return messagePublicKey; + public PublicKey getNetworkPubKey() { + return networkPubKey; } - public ECKey getAccountKey() { - return accountKey; + public byte[] getRegistrationPubKey() { + return registrationPubKey; } - public byte[] getTakerPubKey() { - return takerPubKey; + public DeterministicKey getRegistrationKeyPair() { + return registrationKeyPair; } - public void setTakerPubKey(byte[] takerPubKey) { - this.takerPubKey = takerPubKey; + public byte[] getArbitratorPubKey() { + return arbitratorPubKey; } - public String getTakerAccountId() { - return peersAccountId; - } - - public void setTakerAccountId(String peersAccountId) { - this.peersAccountId = peersAccountId; - } - - public BankAccount getTakerBankAccount() { - return peersBankAccount; - } - - public void setTakerBankAccount(BankAccount peersBankAccount) { - this.peersBankAccount = peersBankAccount; - } - - public TradeMessage getTradeMessage() { - return tradeMessage; - } - - public void setTradeMessage(TradeMessage tradeMessage) { - this.tradeMessage = tradeMessage; + public AddressEntry getAddressInfo() { + return addressInfo; } } diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/BuyerAsOffererModel.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/BuyerAsOffererModel.java index b8180dda3a..2043512074 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/BuyerAsOffererModel.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/BuyerAsOffererModel.java @@ -44,12 +44,11 @@ public class BuyerAsOffererModel extends OfferSharedModel { private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class); - // provided private final OpenOffer openOffer; // derived - private final String offererPaybackAddress; + private final byte[] offererPubKey; // data written/read by tasks private Trade trade; @@ -63,7 +62,7 @@ public class BuyerAsOffererModel extends OfferSharedModel { private Coin takerPaybackAmount; private String takeOfferFeeTxId; - private byte[] offererPubKey; + private ECKey.ECDSASignature offererSignature; private Coin offererPaybackAmount; private List offererConnectedOutputsForAllInputs; @@ -74,6 +73,7 @@ public class BuyerAsOffererModel extends OfferSharedModel { private String takerPayoutAddress; private Transaction offererPayoutTx; private Transaction publishedDepositTx; + private byte[] takerPubKey; /////////////////////////////////////////////////////////////////////////////////////////// @@ -93,11 +93,28 @@ public class BuyerAsOffererModel extends OfferSharedModel { signatureService, user); this.openOffer = openOffer; - - offererPaybackAddress = walletService.getAddressInfo(offer.getId()).getAddressString(); + + offererPubKey = getAddressInfo().getPubKey(); } //getter/setter + public List getOffererConnectedOutputsForAllInputs() { + return offererConnectedOutputsForAllInputs; + } + + public void setOffererConnectedOutputsForAllInputs(List offererConnectedOutputsForAllInputs) { + this.offererConnectedOutputsForAllInputs = offererConnectedOutputsForAllInputs; + } + + public List getOffererOutputs() { + return offererOutputs; + } + + public void setOffererOutputs(List offererOutputs) { + this.offererOutputs = offererOutputs; + } + + public OpenOffer getOpenOffer() { return openOffer; } @@ -106,10 +123,6 @@ public class BuyerAsOffererModel extends OfferSharedModel { return taker; } - public String getOffererPaybackAddress() { - return offererPaybackAddress; - } - public String getTakeOfferFeeTxId() { return takeOfferFeeTxId; @@ -119,22 +132,18 @@ public class BuyerAsOffererModel extends OfferSharedModel { this.takeOfferFeeTxId = takeOfferFeeTxId; } - @Override public String getTakerAccountId() { return takerAccountId; } - @Override public void setTakerAccountId(String takerAccountId) { this.takerAccountId = takerAccountId; } - @Override public BankAccount getTakerBankAccount() { return takerBankAccount; } - @Override public void setTakerBankAccount(BankAccount takerBankAccount) { this.takerBankAccount = takerBankAccount; } @@ -155,16 +164,10 @@ public class BuyerAsOffererModel extends OfferSharedModel { this.takerContractAsJson = takerContractAsJson; } - public byte[] getOffererPubKey() { return offererPubKey; } - public void setOffererPubKey(byte[] offererPubKey) { - this.offererPubKey = offererPubKey; - } - - public ECKey.ECDSASignature getOffererSignature() { return offererSignature; } @@ -201,21 +204,6 @@ public class BuyerAsOffererModel extends OfferSharedModel { this.taker = taker; } - public List getOffererConnectedOutputsForAllInputs() { - return offererConnectedOutputsForAllInputs; - } - - public void setOffererConnectedOutputsForAllInputs(List offererConnectedOutputsForAllInputs) { - this.offererConnectedOutputsForAllInputs = offererConnectedOutputsForAllInputs; - } - - public List getOffererOutputs() { - return offererOutputs; - } - - public void setOffererOutputs(List offererOutputs) { - this.offererOutputs = offererOutputs; - } public void setTakerDepositTx(Transaction takerDepositTx) { this.takerDepositTx = takerDepositTx; @@ -264,4 +252,12 @@ public class BuyerAsOffererModel extends OfferSharedModel { public Transaction getPublishedDepositTx() { return publishedDepositTx; } + + public byte[] getTakerPubKey() { + return takerPubKey; + } + + public void setTakerPubKey(byte[] takerPubKey) { + this.takerPubKey = takerPubKey; + } } diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/RequestDepositPayment.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/RequestDepositPayment.java index 36e8665bda..8a19202499 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/RequestDepositPayment.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/RequestDepositPayment.java @@ -35,12 +35,12 @@ public class RequestDepositPayment extends Task { @Override protected void doRun() { - byte[] offererPubKey = model.getWalletService().getAddressInfo(model.getTrade().getId()).getPubKey(); + model.getOffererPubKey(); RequestDepositPaymentMessage tradeMessage = new RequestDepositPaymentMessage( model.getTrade().getId(), model.getOffererConnectedOutputsForAllInputs(), model.getOffererOutputs(), - offererPubKey, + model.getOffererPubKey(), model.getBankAccount(), model.getAccountId()); diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/SendBankTransferStartedMessage.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/SendBankTransferStartedMessage.java index c05cea2f28..fdf4f69145 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/SendBankTransferStartedMessage.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/SendBankTransferStartedMessage.java @@ -41,7 +41,7 @@ public class SendBankTransferStartedMessage extends Task { model.getOffererSignature().encodeToDER(), model.getOffererPaybackAmount(), model.getTakerPaybackAmount(), - model.getOffererPaybackAddress()); + model.getAddressInfo().getAddressString()); model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() { @Override public void handleResult() { diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/VerifyAndSignContract.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/VerifyAndSignContract.java index d7f0dbc914..9becfe67af 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/VerifyAndSignContract.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/offerer/tasks/VerifyAndSignContract.java @@ -46,10 +46,10 @@ public class VerifyAndSignContract extends Task { model.getTakerAccountId(), model.getBankAccount(), model.getTakerBankAccount(), - model.getMessagePublicKey(), + model.getNetworkPubKey(), model.getTakerMessagePublicKey()); String contractAsJson = Utilities.objectToJson(contract); - String signature = model.getSignatureService().signMessage(model.getAccountKey(), contractAsJson); + String signature = model.getSignatureService().signMessage(model.getRegistrationKeyPair(), contractAsJson); trade.setContract(contract); trade.setContractAsJson(contractAsJson); diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerAsTakerModel.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerAsTakerModel.java index 172e632655..27c5149a6a 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerAsTakerModel.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerAsTakerModel.java @@ -17,6 +17,7 @@ package io.bitsquare.trade.protocol.trade.taker; +import io.bitsquare.bank.BankAccount; import io.bitsquare.btc.BlockChainService; import io.bitsquare.btc.WalletService; import io.bitsquare.crypto.SignatureService; @@ -27,7 +28,6 @@ import io.bitsquare.trade.protocol.trade.OfferSharedModel; import io.bitsquare.user.User; import org.bitcoinj.core.Coin; -import org.bitcoinj.core.ECKey; import org.bitcoinj.core.Transaction; import org.bitcoinj.core.TransactionOutput; @@ -41,7 +41,10 @@ public class SellerAsTakerModel extends OfferSharedModel { // provided private final Trade trade; - + + + // derived + private final byte[] takerPubKey; // written/read by task private Peer offerer; @@ -53,15 +56,16 @@ public class SellerAsTakerModel extends OfferSharedModel { private Coin takerPaybackAmount; private byte[] offererPubKey; private long offererTxOutIndex; - private ECKey.ECDSASignature offererSignature; private Coin offererPaybackAmount; private String offererPayoutAddress; - private List offererConnectedOutputsForAllInputs; - private List offererOutputs; + private List offererConnectedOutputsForAllInputs; + private List offererOutputs; private List takerConnectedOutputsForAllInputs; private List takerOutputs; private Transaction takerDepositTx; private Transaction publishedDepositTx; + private BankAccount takerBankAccount; + private String takerAccountId; public SellerAsTakerModel(Trade trade, TradeMessageService tradeMessageService, @@ -77,11 +81,14 @@ public class SellerAsTakerModel extends OfferSharedModel { user); this.trade = trade; - takerPubKey = walletService.getAddressInfo(trade.getId()).getPubKey(); - + takerPubKey = getAddressInfo().getPubKey(); } // getter/setter + public byte[] getTakerPubKey() { + return takerPubKey; + } + public void setOffererPubKey(byte[] offererPubKey) { this.offererPubKey = offererPubKey; } @@ -101,6 +108,7 @@ public class SellerAsTakerModel extends OfferSharedModel { public void setOffererOutputs(List offererOutputs) { this.offererOutputs = offererOutputs; } + public Trade getTrade() { return trade; } @@ -158,14 +166,6 @@ public class SellerAsTakerModel extends OfferSharedModel { this.depositTx = depositTx; } - public ECKey.ECDSASignature getOffererSignature() { - return offererSignature; - } - - public void setOffererSignature(ECKey.ECDSASignature offererSignature) { - this.offererSignature = offererSignature; - } - public Coin getOffererPaybackAmount() { return offererPaybackAmount; } @@ -230,4 +230,20 @@ public class SellerAsTakerModel extends OfferSharedModel { public Transaction getPublishedDepositTx() { return publishedDepositTx; } + + public void setTakerBankAccount(BankAccount takerBankAccount) { + this.takerBankAccount = takerBankAccount; + } + + public BankAccount getTakerBankAccount() { + return takerBankAccount; + } + + public void setTakerAccountId(String takerAccountId) { + this.takerAccountId = takerAccountId; + } + + public String getTakerAccountId() { + return takerAccountId; + } } diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/CreateAndSignContract.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/CreateAndSignContract.java index 5aa49dc6af..7cc61092c8 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/CreateAndSignContract.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/CreateAndSignContract.java @@ -46,9 +46,9 @@ public class CreateAndSignContract extends Task { model.getTakerBankAccount(), model.getBankAccount(), model.getOffer().getMessagePublicKey(), - model.getMessagePublicKey()); + model.getNetworkPubKey()); String contractAsJson = Utilities.objectToJson(contract); - String signature = model.getSignatureService().signMessage(model.getAccountKey(), contractAsJson); + String signature = model.getSignatureService().signMessage(model.getRegistrationKeyPair(), contractAsJson); trade.setContract(contract); trade.setContractAsJson(contractAsJson); diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessBankTransferStartedMessage.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessBankTransferStartedMessage.java index c8c11934f3..ac0e2e6a97 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessBankTransferStartedMessage.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessBankTransferStartedMessage.java @@ -22,12 +22,9 @@ import io.bitsquare.trade.protocol.trade.taker.SellerAsTakerModel; import io.bitsquare.util.taskrunner.Task; import io.bitsquare.util.taskrunner.TaskRunner; -import org.bitcoinj.core.ECKey; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.google.common.base.Preconditions.checkNotNull; import static io.bitsquare.util.Validator.*; public class ProcessBankTransferStartedMessage extends Task { @@ -44,7 +41,7 @@ public class ProcessBankTransferStartedMessage extends Task BankTransferStartedMessage message = (BankTransferStartedMessage) model.getTradeMessage(); //model.setDepositTx(checkNotNull(message.getDepositTx())); - model.setOffererSignature(checkNotNull(ECKey.ECDSASignature.decodeFromDER(message.getOffererSignature()))); + //model.setOffererSignature(checkNotNull(ECKey.ECDSASignature.decodeFromDER(message.getOffererSignature()))); model.setOffererPaybackAmount(positiveCoinOf(nonZeroCoinOf(message.getOffererPaybackAmount()))); model.setTakerPaybackAmount(positiveCoinOf(nonZeroCoinOf(message.getTakerPaybackAmount()))); model.setOffererPayoutAddress(nonEmptyStringOf(message.getOffererPayoutAddress())); diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessRequestDepositPaymentMessage.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessRequestDepositPaymentMessage.java index 780d4a1488..b32a2e6928 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessRequestDepositPaymentMessage.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/ProcessRequestDepositPaymentMessage.java @@ -45,6 +45,7 @@ public class ProcessRequestDepositPaymentMessage extends Task 0); model.setOffererOutputs(checkNotNull(message.getOffererOutputs())); model.setOffererPubKey(checkNotNull(message.getOffererPubKey())); + model.setTakerBankAccount(checkNotNull(message.getBankAccount())); model.setTakerAccountId(nonEmptyStringOf(message.getAccountId())); diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SendSignedTakerDepositTx.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SendSignedTakerDepositTx.java index 2ab1be93fa..a90405fcd2 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SendSignedTakerDepositTx.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SendSignedTakerDepositTx.java @@ -39,7 +39,7 @@ public class SendSignedTakerDepositTx extends Task { model.getTrade().getId(), model.getBankAccount(), model.getAccountId(), - model.getMessagePublicKey(), + model.getNetworkPubKey(), model.getTrade().getContractAsJson(), model.getTrade().getTakerContractSignature(), model.getTakerDepositTx(), diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SignAndPublishPayoutTx.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SignAndPublishPayoutTx.java index 706a0a8240..68bec0e8f8 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SignAndPublishPayoutTx.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/taker/tasks/SignAndPublishPayoutTx.java @@ -44,7 +44,7 @@ public class SignAndPublishPayoutTx extends Task { protected void doRun() { try { model.getWalletService().takerSignsAndSendsTx(model.getPublishedDepositTx(), - model.getOffererSignature(), + null, model.getOffererPaybackAmount(), model.getTakerPaybackAmount(), model.getOffererPayoutAddress(), diff --git a/core/src/main/java/io/bitsquare/user/User.java b/core/src/main/java/io/bitsquare/user/User.java index 02e76d9942..312d094d9d 100644 --- a/core/src/main/java/io/bitsquare/user/User.java +++ b/core/src/main/java/io/bitsquare/user/User.java @@ -43,7 +43,7 @@ import javafx.collections.ObservableList; public class User implements Serializable { private static final long serialVersionUID = 7409078808248518638L; - private KeyPair messageKeyPair; + private KeyPair networkKeyPair; private String accountID; // Used for serialisation (ObservableList cannot be serialized) -> serialisation will change anyway so that is @@ -57,8 +57,7 @@ public class User implements Serializable { public User() { // Used for serialisation (ObservableList cannot be serialized) -> serialisation will change anyway so that is // only temporary - bankAccounts.addListener((ListChangeListener) change -> - _bankAccounts = new ArrayList<>(bankAccounts)); + bankAccounts.addListener((ListChangeListener) change -> _bankAccounts = new ArrayList<>(bankAccounts)); currentBankAccount.addListener((ov) -> _currentBankAccount = currentBankAccount.get()); } @@ -72,13 +71,13 @@ public class User implements Serializable { if (persistedUser != null) { bankAccounts.setAll(persistedUser.getSerializedBankAccounts()); setCurrentBankAccount(persistedUser.getSerializedCurrentBankAccount()); - messageKeyPair = persistedUser.getMessageKeyPair(); + networkKeyPair = persistedUser.getNetworkKeyPair(); accountID = persistedUser.getAccountId(); } else { // First time // TODO use separate thread. DSAKeyUtil.getKeyPair() runs in same thread now - messageKeyPair = DSAKeyUtil.generateKeyPair(); + networkKeyPair = DSAKeyUtil.generateKeyPair(); } } @@ -153,7 +152,6 @@ public class User implements Serializable { } public BankAccount getBankAccount(String bankAccountId) { - // TODO use steam API for (final BankAccount bankAccount : bankAccounts) { if (bankAccount.getUid().equals(bankAccountId)) { return bankAccount; @@ -162,24 +160,19 @@ public class User implements Serializable { return null; } - public KeyPair getMessageKeyPair() { - return messageKeyPair; + public KeyPair getNetworkKeyPair() { + return networkKeyPair; } - public PublicKey getMessagePublicKey() { - return messageKeyPair.getPublic(); - } - - public String getMessagePublicKeyAsString() { - return DSAKeyUtil.getHexStringFromPublicKey(getMessagePublicKey()); + public PublicKey getNetworkPubKey() { + return networkKeyPair.getPublic(); } public ObjectProperty currentBankAccountProperty() { return currentBankAccount; } - // Used for serialisation (ObservableList cannot be serialized) -> serialisation will change anyway so that is - // only temporary + // Used for serialisation (ObservableList cannot be serialized) List getSerializedBankAccounts() { return _bankAccounts; } diff --git a/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/PlaceOfferProtocolTest.java b/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/PlaceOfferProtocolTest.java index 84095e31c8..8605fe358a 100644 --- a/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/PlaceOfferProtocolTest.java +++ b/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/PlaceOfferProtocolTest.java @@ -98,7 +98,7 @@ public class PlaceOfferProtocolTest { tomP2PNode = new TomP2PNode(bootstrappedPeerBuilder); tradeMessageService = new TomP2PTradeMessageService(user, tomP2PNode); - Observable messageObservable = tomP2PNode.bootstrap(user.getMessageKeyPair(), tradeMessageService); + Observable messageObservable = tomP2PNode.bootstrap(user.getNetworkKeyPair(), tradeMessageService); messageObservable.publish(); messageObservable.subscribe( state -> log.trace("state changed: " + state),