Use Byte array instead of hex for pub keys

This commit is contained in:
Manfred Karrer 2015-03-14 19:26:30 +01:00
parent ce3bc26be6
commit 72ded8ad90
43 changed files with 201 additions and 292 deletions

View File

@ -149,7 +149,7 @@ public class BitsquareApp extends Application {
primaryStage.show();
//TODO just temp.
showDebugWindow();
//showDebugWindow();
}
private void showDebugWindow() {

View File

@ -30,6 +30,7 @@ public class Arbitrator implements Serializable {
private String id;
private String pubKeyAsHex;
private byte[] pubKey;
private String messagePubKeyAsHex;
private String name;
private ID_TYPE idType;
@ -46,7 +47,7 @@ public class Arbitrator implements Serializable {
public Arbitrator() {
}
public Arbitrator(String pubKeyAsHex,
public Arbitrator(byte[] pubKey,
String messagePubKeyAsHex,
String name,
ID_TYPE idType,
@ -57,7 +58,7 @@ public class Arbitrator implements Serializable {
List<ID_VERIFICATION> idVerifications,
String webUrl,
String description) {
this.pubKeyAsHex = pubKeyAsHex;
this.pubKey=pubKey;
this.messagePubKeyAsHex = messagePubKeyAsHex;
this.name = name;
this.idType = idType;
@ -121,6 +122,10 @@ public class Arbitrator implements Serializable {
return pubKeyAsHex;
}
public byte[] getPubKey() {
return pubKey;
}
public String getMessagePubKeyAsHex() {
return messagePubKeyAsHex;
}

View File

@ -36,6 +36,7 @@ public class AddressEntry implements Serializable {
private final NetworkParameters params;
private final AddressContext addressContext;
private final String offerId;
private final byte[] pubKey;
private final byte[] pubKeyHash;
@ -49,6 +50,7 @@ public class AddressEntry implements Serializable {
this.addressContext = addressContext;
this.offerId = offerId;
pubKey = key.getPubOnly().getPubKey();
pubKeyHash = key.getPubOnly().getPubKeyHash();
}
@ -64,7 +66,7 @@ public class AddressEntry implements Serializable {
return getAddress().toString();
}
public String getPubKeyAsHexString() {
public String getPubKeyAsHex() {
return Utils.HEX.encode(key.getPubKey());
}
@ -84,6 +86,10 @@ public class AddressEntry implements Serializable {
return pubKeyHash;
}
public byte[] getPubKey() {
return pubKey;
}
public static enum AddressContext {
REGISTRATION_FEE,
TRADE,

View File

@ -92,10 +92,6 @@ import rx.subjects.Subject;
import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
/**
* TODO: use walletextension (with protobuffer) instead of saving addressEntryList via storage
* TODO: break that class up. maybe a bitsquarewallet
*/
public class WalletService {
private static final Logger log = LoggerFactory.getLogger(WalletService.class);
private static final String LOCK_NAME = "lock";
@ -225,8 +221,7 @@ public class WalletService {
if (serializable instanceof List) {
List<AddressEntry> persistedAddressEntryList = (List<AddressEntry>) serializable;
for (AddressEntry persistedAddressEntry : persistedAddressEntryList) {
persistedAddressEntry.setDeterministicKey(
(DeterministicKey) wallet.findKeyFromPubHash(persistedAddressEntry.getPubKeyHash()));
persistedAddressEntry.setDeterministicKey((DeterministicKey) wallet.findKeyFromPubHash(persistedAddressEntry.getPubKeyHash()));
}
addressEntryList = persistedAddressEntryList;
registrationAddressEntry = addressEntryList.get(0);
@ -310,7 +305,7 @@ public class WalletService {
return arbitratorDepositAddressEntry;
}
public AddressEntry getAddressInfoByTradeID(String offerId) {
public AddressEntry getAddressInfo(String offerId) {
Optional<AddressEntry> addressEntry = getAddressEntryList().stream().filter(e ->
offerId.equals(e.getOfferId())).findFirst();
@ -533,7 +528,7 @@ public class WalletService {
sendRequest.shuffleOutputs = false;
// we allow spending of unconfirmed tx (double spend risk is low and usability would suffer if we need to
// wait for 1 confirmation)
AddressEntry addressEntry = getAddressInfoByTradeID(offerId);
AddressEntry addressEntry = getAddressInfo(offerId);
sendRequest.coinSelector = new AddressBasedCoinSelector(params, addressEntry, true);
sendRequest.changeAddress = addressEntry.getAddress();
wallet.completeTx(sendRequest);
@ -547,8 +542,7 @@ public class WalletService {
Futures.addCallback(future, callback);
}
public String payTakeOfferFee(String offerId, FutureCallback<Transaction> callback) throws
InsufficientMoneyException {
public String payTakeOfferFee(String offerId, FutureCallback<Transaction> callback) throws InsufficientMoneyException {
Transaction tx = new Transaction(params);
Coin fee = FeePolicy.TAKE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
log.trace("fee: " + fee.toFriendlyString());
@ -558,8 +552,8 @@ public class WalletService {
sendRequest.shuffleOutputs = false;
// we allow spending of unconfirmed tx (double spend risk is low and usability would suffer if we need to
// wait for 1 confirmation)
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getAddressInfoByTradeID(offerId), true);
sendRequest.changeAddress = getAddressInfoByTradeID(offerId).getAddress();
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getAddressInfo(offerId), true);
sendRequest.changeAddress = getAddressInfo(offerId).getAddress();
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
@ -577,8 +571,7 @@ public class WalletService {
public String sendFunds(String withdrawFromAddress,
String withdrawToAddress,
Coin amount,
FutureCallback<Transaction> callback) throws AddressFormatException,
InsufficientMoneyException, IllegalArgumentException {
FutureCallback<Transaction> callback) throws AddressFormatException, InsufficientMoneyException, IllegalArgumentException {
Transaction tx = new Transaction(params);
tx.addOutput(amount.subtract(FeePolicy.TX_FEE), new Address(params, withdrawToAddress));
@ -603,8 +596,6 @@ public class WalletService {
}
// TODO: Trade process - use P2SH instead and optimize tx creation and data exchange
///////////////////////////////////////////////////////////////////////////////////////////
// Trade process
///////////////////////////////////////////////////////////////////////////////////////////
@ -612,9 +603,9 @@ public class WalletService {
// 1. step: deposit tx
// Offerer creates the 2of3 multiSig deposit tx with his unsigned input and change output
public Transaction offererCreatesMSTxAndAddPayment(Coin offererInputAmount,
String offererPubKey,
String takerPubKey,
String arbitratorPubKey,
byte[] offererPubKey,
byte[] takerPubKey,
byte[] arbitratorPubKey,
String tradeId) throws InsufficientMoneyException {
log.debug("offererCreatesMSTxAndAddPayment");
log.trace("inputs: ");
@ -640,7 +631,7 @@ public class WalletService {
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
sendRequest.shuffleOutputs = false;
AddressEntry addressEntry = getAddressInfoByTradeID(tradeId);
AddressEntry addressEntry = getAddressInfo(tradeId);
// we allow spending of unconfirmed tx (double spend risk is low and usability would suffer if we need to
// wait for 1 confirmation)
sendRequest.coinSelector = new AddressBasedCoinSelector(params, addressEntry, true);
@ -672,9 +663,9 @@ public class WalletService {
public Transaction takerAddPaymentAndSignTx(Coin takerInputAmount,
Coin msOutputAmount,
String offererPubKey,
String takerPubKey,
String arbitratorPubKey,
byte[] offererPubKey,
byte[] takerPubKey,
byte[] arbitratorPubKey,
String offerersPartialDepositTxAsHex,
String tradeId) throws InsufficientMoneyException {
log.debug("takerAddPaymentAndSignTx");
@ -700,7 +691,7 @@ public class WalletService {
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tempTx);
sendRequest.shuffleOutputs = false;
AddressEntry addressEntry = getAddressInfoByTradeID(tradeId);
AddressEntry addressEntry = getAddressInfo(tradeId);
// we allow spending of unconfirmed tx (double spend risk is low and usability would suffer if we need to
// wait for 1 confirmation)
sendRequest.coinSelector = new AddressBasedCoinSelector(params, addressEntry, true);
@ -952,13 +943,13 @@ public class WalletService {
// We create the payout tx
Transaction tx = createPayoutTx(depositTxAsHex, offererPaybackAmount, takerPaybackAmount,
getAddressInfoByTradeID(tradeID).getAddressString(), takerAddress);
getAddressInfo(tradeID).getAddressString(), takerAddress);
// We create the signature for that tx
TransactionOutput multiSigOutput = tx.getInput(0).getConnectedOutput();
Script multiSigScript = multiSigOutput.getScriptPubKey();
Sha256Hash sigHash = tx.hashForSignature(0, multiSigScript, Transaction.SigHash.ALL, false);
ECKey.ECDSASignature offererSignature = getAddressInfoByTradeID(tradeID).getKey().sign(sigHash);
ECKey.ECDSASignature offererSignature = getAddressInfo(tradeID).getKey().sign(sigHash);
TransactionSignature offererTxSig = new TransactionSignature(offererSignature, Transaction.SigHash.ALL, false);
Script inputScript = ScriptBuilder.createMultiSigInputScript(ImmutableList.of(offererTxSig));
@ -989,7 +980,7 @@ public class WalletService {
// We create the payout tx
Transaction tx = createPayoutTx(depositTxAsHex, offererPaybackAmount, takerPaybackAmount, offererAddress,
getAddressInfoByTradeID(tradeID).getAddressString());
getAddressInfo(tradeID).getAddressString());
// We sign that tx with our key and apply the signature form the offerer
TransactionOutput multiSigOutput = tx.getInput(0).getConnectedOutput();
@ -997,7 +988,7 @@ public class WalletService {
Sha256Hash sigHash = tx.hashForSignature(0, multiSigScript, Transaction.SigHash.ALL, false);
log.trace("sigHash=" + sigHash);
ECKey.ECDSASignature takerSignature = getAddressInfoByTradeID(tradeID).getKey().sign(sigHash);
ECKey.ECDSASignature takerSignature = getAddressInfo(tradeID).getKey().sign(sigHash);
TransactionSignature takerTxSig = new TransactionSignature(takerSignature, Transaction.SigHash.ALL, false);
ECKey.ECDSASignature offererSignature =
@ -1040,7 +1031,15 @@ public class WalletService {
}
}
//TODO
private Script getMultiSigScript(byte[] offererPubKey, byte[] takerPubKey, byte[] arbitratorPubKey) {
ECKey offererKey = ECKey.fromPublicOnly(offererPubKey);
ECKey takerKey = ECKey.fromPublicOnly(takerPubKey);
ECKey arbitratorKey = ECKey.fromPublicOnly(arbitratorPubKey);
List<ECKey> keys = ImmutableList.of(offererKey, takerKey, arbitratorKey);
return ScriptBuilder.createMultiSigOutputScript(2, keys);
}
private Script getMultiSigScript(String offererPubKey, String takerPubKey, String arbitratorPubKey) {
ECKey offererKey = ECKey.fromPublicOnly(Utils.parseAsHexOrBase58(offererPubKey));
ECKey takerKey = ECKey.fromPublicOnly(Utils.parseAsHexOrBase58(takerPubKey));

View File

@ -41,7 +41,6 @@ import io.bitsquare.viewfx.model.ViewModel;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Utils;
import com.google.inject.Inject;
@ -232,7 +231,7 @@ class MainViewModel implements ViewModel {
user.setAccountID(walletService.getRegistrationAddressEntry().toString());
persistence.write(user.getClass().getName(), user);
}
tradeManager.onAllServicesInitialized();
}
@ -352,7 +351,7 @@ class MainViewModel implements ViewModel {
private void addMockArbitrator() {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) {
String pubKeyAsHex = Utils.HEX.encode(new ECKey().getPubKey());
byte[] pubKey = new ECKey().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
@ -362,7 +361,7 @@ class MainViewModel implements ViewModel {
idVerifications.add(Arbitrator.ID_VERIFICATION.PASSPORT);
idVerifications.add(Arbitrator.ID_VERIFICATION.GOV_ID);
Arbitrator arbitrator = new Arbitrator(pubKeyAsHex,
Arbitrator arbitrator = new Arbitrator(pubKey,
messagePubKeyAsHex,
"Manfred Karrer",
Arbitrator.ID_TYPE.REAL_LIFE_ID,

View File

@ -369,14 +369,14 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
}
private Arbitrator getEditedArbitrator() {
String pubKeyAsHex = walletService.getArbitratorDepositAddressEntry().getPubKeyAsHexString();
byte[] pubKey = walletService.getArbitratorDepositAddressEntry().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
String name = nameTextField.getText();
Coin fee = formatter.parseToCoin(arbitrationFeeTextField.getText());
String webUrl = webPageTextField.getText();
String description = descriptionTextArea.getText();
return new Arbitrator(pubKeyAsHex,
return new Arbitrator(pubKey,
messagePubKeyAsHex,
name,
idType,

View File

@ -34,7 +34,6 @@ import io.bitsquare.viewfx.model.DataModel;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Utils;
import com.google.inject.Inject;
@ -124,7 +123,7 @@ class IrcAccountDataModel implements Activatable, DataModel {
private void addMockArbitrator() {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) {
String pubKeyAsHex = Utils.HEX.encode(new ECKey().getPubKey());
byte[] pubKey = new ECKey().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
@ -134,7 +133,7 @@ class IrcAccountDataModel implements Activatable, DataModel {
idVerifications.add(Arbitrator.ID_VERIFICATION.PASSPORT);
idVerifications.add(Arbitrator.ID_VERIFICATION.GOV_ID);
Arbitrator arbitrator = new Arbitrator(pubKeyAsHex,
Arbitrator arbitrator = new Arbitrator(pubKey,
messagePubKeyAsHex,
"Manfred Karrer",
Arbitrator.ID_TYPE.REAL_LIFE_ID,

View File

@ -33,7 +33,6 @@ import io.bitsquare.viewfx.model.DataModel;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Utils;
import com.google.inject.Inject;
@ -154,7 +153,7 @@ class RestrictionsDataModel implements Activatable, DataModel {
// TODO Remove mock later
private void addMockArbitrator() {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) {
String pubKeyAsHex = Utils.HEX.encode(new ECKey().getPubKey());
byte[] pubKey = new ECKey().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
@ -166,7 +165,7 @@ class RestrictionsDataModel implements Activatable, DataModel {
// TODO use very small sec. dposit to make testing in testnet less expensive
// Revert later to 0.1 BTC again
Arbitrator arbitrator = new Arbitrator(pubKeyAsHex,
Arbitrator arbitrator = new Arbitrator(pubKey,
messagePubKeyAsHex,
"Manfred Karrer",
Arbitrator.ID_TYPE.REAL_LIFE_ID,

View File

@ -184,7 +184,7 @@ class PendingTradesDataModel implements Activatable, DataModel {
}
};
AddressEntry addressEntry = walletService.getAddressInfoByTradeID(getTrade().getId());
AddressEntry addressEntry = walletService.getAddressInfo(getTrade().getId());
String fromAddress = addressEntry.getAddressString();
try {
walletService.sendFunds(fromAddress, toAddress, getAmountToWithdraw(), callback);
@ -258,7 +258,7 @@ class PendingTradesDataModel implements Activatable, DataModel {
}
Coin getAmountToWithdraw() {
AddressEntry addressEntry = walletService.getAddressInfoByTradeID(getTrade().getId());
AddressEntry addressEntry = walletService.getAddressInfo(getTrade().getId());
log.debug("trade id " + getTrade().getId());
log.debug("getAddressString " + addressEntry.getAddressString());
log.debug("funds " + walletService.getBalanceForAddress(addressEntry.getAddress()).subtract(FeePolicy

View File

@ -125,7 +125,7 @@ class CreateOfferDataModel implements Activatable, DataModel {
networkFeeAsCoin.set(FeePolicy.TX_FEE);
if (walletService != null && walletService.getWallet() != null) {
addressEntry = walletService.getAddressInfoByTradeID(offerId);
addressEntry = walletService.getAddressInfo(offerId);
walletService.addBalanceListener(new BalanceListener(getAddressEntry().getAddress()) {
@Override

View File

@ -121,7 +121,7 @@ class TakeOfferDataModel implements Activatable, DataModel {
calculateVolume();
calculateTotalToPay();
addressEntry = walletService.getAddressInfoByTradeID(offer.getId());
addressEntry = walletService.getAddressInfo(offer.getId());
walletService.addBalanceListener(new BalanceListener(addressEntry.getAddress()) {
@Override
public void onBalanceChanged(@NotNull Coin balance) {
@ -148,6 +148,8 @@ class TakeOfferDataModel implements Activatable, DataModel {
case OFFERER_REJECTED:
requestTakeOfferErrorMessage.set("Take offer request got rejected. Maybe another trader has taken the offer in the meantime.");
break;
case TAKE_OFFER_FEE_PAID:
break;
case DEPOSIT_PUBLISHED:
case DEPOSIT_CONFIRMED:
// TODO Check why DEPOSIT_CONFIRMED can happen, refactor state handling
@ -163,9 +165,12 @@ class TakeOfferDataModel implements Activatable, DataModel {
break;
case FIAT_PAYMENT_STARTED:
break;
case TAKE_OFFER_FEE_PAYMENT_FAILED:
requestTakeOfferErrorMessage.set("An error occurred when paying the trade fee.");
break;
case MESSAGE_SENDING_FAILED:
requestTakeOfferErrorMessage.set("An error occurred when sending a message to the offerer. Maybe there are connection problems. Please " +
"try later again.");
requestTakeOfferErrorMessage.set("An error occurred when sending a message to the offerer. Maybe there are connection problems. " +
"Please try later again.");
break;
case PAYOUT_PUBLISHED:
break;

View File

@ -41,6 +41,7 @@ public class Trade implements Serializable {
OPEN,
OFFERER_ACCEPTED,
OFFERER_REJECTED, /* For taker only*/
TAKE_OFFER_FEE_PAYMENT_FAILED,
TAKE_OFFER_FEE_PAID,
DEPOSIT_PUBLISHED,
DEPOSIT_CONFIRMED,

View File

@ -385,6 +385,7 @@ public class TradeManager {
case OPEN:
break;
case OFFERER_ACCEPTED: // only taker side
case TAKE_OFFER_FEE_PAID:
case DEPOSIT_PUBLISHED:
case DEPOSIT_CONFIRMED:
case FIAT_PAYMENT_STARTED:
@ -393,6 +394,7 @@ public class TradeManager {
persistPendingTrades();
break;
case OFFERER_REJECTED:
case TAKE_OFFER_FEE_PAYMENT_FAILED:
case MESSAGE_SENDING_FAILED:
removeFailedTrade(trade);
buyerAcceptsOfferProtocolMap.get(trade.getId()).cleanup();

View File

@ -48,7 +48,7 @@ public class BroadcastCreateOfferFeeTx extends Task<PlaceOfferModel> {
protected void doRun() {
Coin totalsNeeded = model.getOffer().getSecurityDeposit().add(FeePolicy.CREATE_OFFER_FEE).add(FeePolicy.TX_FEE);
AddressEntry addressEntry = model.getWalletService().getAddressInfoByTradeID(model.getOffer().getId());
AddressEntry addressEntry = model.getWalletService().getAddressInfo(model.getOffer().getId());
Coin balance = model.getWalletService().getBalanceForAddress(addressEntry.getAddress());
if (balance.compareTo(totalsNeeded) >= 0) {

View File

@ -33,8 +33,8 @@ import java.security.PublicKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TradeSharedModel extends SharedModel {
protected static final Logger log = LoggerFactory.getLogger(TradeSharedModel.class);
public class OfferSharedModel extends SharedModel {
protected static final Logger log = LoggerFactory.getLogger(OfferSharedModel.class);
// provided
protected final Offer offer;
@ -44,19 +44,19 @@ public class TradeSharedModel extends SharedModel {
protected final SignatureService signatureService;
// derived
protected final String arbitratorPubKey;
protected final BankAccount bankAccount;
protected final String accountId;
protected final PublicKey messagePublicKey;
protected final ECKey accountKey;
protected final byte[] arbitratorPubKey;
// data written/read by tasks
private TradeMessage tradeMessage;
protected String tradePubKeyAsHex;
protected TradeMessage tradeMessage;
protected byte[] takerPubKey;
protected String peersAccountId;
protected BankAccount peersBankAccount;
public TradeSharedModel(Offer offer,
public OfferSharedModel(Offer offer,
TradeMessageService tradeMessageService,
WalletService walletService,
BlockChainService blockChainService,
@ -69,7 +69,7 @@ public class TradeSharedModel extends SharedModel {
this.signatureService = signatureService;
//TODO use default arbitrator for now
arbitratorPubKey = offer.getArbitrators().get(0).getPubKeyAsHex();
arbitratorPubKey = offer.getArbitrators().get(0).getPubKey();
bankAccount = user.getBankAccount(offer.getBankAccountId());
accountId = user.getAccountId();
messagePublicKey = user.getMessagePublicKey();
@ -98,7 +98,7 @@ public class TradeSharedModel extends SharedModel {
return offer;
}
public String getArbitratorPubKey() {
public byte[] getArbitratorPubKey() {
return arbitratorPubKey;
}
@ -118,27 +118,27 @@ public class TradeSharedModel extends SharedModel {
return accountKey;
}
public String getTradePubKeyAsHex() {
return tradePubKeyAsHex;
public byte[] getTakerPubKey() {
return takerPubKey;
}
public void setTradePubKeyAsHex(String tradePubKeyAsHex) {
this.tradePubKeyAsHex = tradePubKeyAsHex;
public void setTakerPubKey(byte[] takerPubKey) {
this.takerPubKey = takerPubKey;
}
public String getPeersAccountId() {
public String getTakerAccountId() {
return peersAccountId;
}
public void setPeersAccountId(String peersAccountId) {
public void setTakerAccountId(String peersAccountId) {
this.peersAccountId = peersAccountId;
}
public BankAccount getPeersBankAccount() {
public BankAccount getTakerBankAccount() {
return peersBankAccount;
}
public void setPeersBankAccount(BankAccount peersBankAccount) {
public void setTakerBankAccount(BankAccount peersBankAccount) {
this.peersBankAccount = peersBankAccount;
}

View File

@ -25,7 +25,7 @@ import io.bitsquare.network.Peer;
import io.bitsquare.offer.OpenOffer;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.trade.protocol.trade.TradeSharedModel;
import io.bitsquare.trade.protocol.trade.OfferSharedModel;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
@ -35,7 +35,7 @@ import java.security.PublicKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BuyerAsOffererModel extends TradeSharedModel {
public class BuyerAsOffererModel extends OfferSharedModel {
private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class);
@ -48,15 +48,15 @@ public class BuyerAsOffererModel extends TradeSharedModel {
// data written/read by tasks
private Trade trade;
private Peer peer;
private Peer taker;
private String preparedOffererDepositTxAsHex;
private String depositTxAsHex;
private String peersAccountId;
private BankAccount peersBankAccount;
private PublicKey peersMessagePublicKey;
private String peersContractAsJson;
private String takerAccountId;
private BankAccount takerBankAccount;
private PublicKey takerMessagePublicKey;
private String takerContractAsJson;
private String signedTakerDepositTxAsHex;
@ -66,11 +66,10 @@ public class BuyerAsOffererModel extends TradeSharedModel {
private long takerTxOutIndex;
private Coin takerPaybackAmount;
private String takeOfferFeeTxId;
private String tradePubKeyAsHex;
private String takerPayoutAddress;
private long offererTxOutIndex;
private String offererPubKey;
private byte[] offererPubKey;
private String offererSignatureR;
private String offererSignatureS;
private Coin offererPaybackAmount;
@ -94,7 +93,7 @@ public class BuyerAsOffererModel extends TradeSharedModel {
user);
this.openOffer = openOffer;
offererPaybackAddress = walletService.getAddressInfoByTradeID(offer.getId()).getAddressString();
offererPaybackAddress = walletService.getAddressInfo(offer.getId()).getAddressString();
}
//getter/setter
@ -102,8 +101,8 @@ public class BuyerAsOffererModel extends TradeSharedModel {
return openOffer;
}
public Peer getPeer() {
return peer;
public Peer getTaker() {
return taker;
}
public String getOffererPaybackAddress() {
@ -134,16 +133,6 @@ public class BuyerAsOffererModel extends TradeSharedModel {
this.takeOfferFeeTxId = takeOfferFeeTxId;
}
@Override
public String getTradePubKeyAsHex() {
return tradePubKeyAsHex;
}
@Override
public void setTradePubKeyAsHex(String tradePubKeyAsHex) {
this.tradePubKeyAsHex = tradePubKeyAsHex;
}
public String getTakerPayoutAddress() {
return takerPayoutAddress;
}
@ -153,39 +142,39 @@ public class BuyerAsOffererModel extends TradeSharedModel {
}
@Override
public String getPeersAccountId() {
return peersAccountId;
public String getTakerAccountId() {
return takerAccountId;
}
@Override
public void setPeersAccountId(String peersAccountId) {
this.peersAccountId = peersAccountId;
public void setTakerAccountId(String takerAccountId) {
this.takerAccountId = takerAccountId;
}
@Override
public BankAccount getPeersBankAccount() {
return peersBankAccount;
public BankAccount getTakerBankAccount() {
return takerBankAccount;
}
@Override
public void setPeersBankAccount(BankAccount peersBankAccount) {
this.peersBankAccount = peersBankAccount;
public void setTakerBankAccount(BankAccount takerBankAccount) {
this.takerBankAccount = takerBankAccount;
}
public PublicKey getPeersMessagePublicKey() {
return peersMessagePublicKey;
public PublicKey getTakerMessagePublicKey() {
return takerMessagePublicKey;
}
public void setPeersMessagePublicKey(PublicKey peersMessagePublicKey) {
this.peersMessagePublicKey = peersMessagePublicKey;
public void setTakerMessagePublicKey(PublicKey takerMessagePublicKey) {
this.takerMessagePublicKey = takerMessagePublicKey;
}
public String getPeersContractAsJson() {
return peersContractAsJson;
public String getTakerContractAsJson() {
return takerContractAsJson;
}
public void setPeersContractAsJson(String peersContractAsJson) {
this.peersContractAsJson = peersContractAsJson;
public void setTakerContractAsJson(String takerContractAsJson) {
this.takerContractAsJson = takerContractAsJson;
}
public String getSignedTakerDepositTxAsHex() {
@ -220,11 +209,11 @@ public class BuyerAsOffererModel extends TradeSharedModel {
this.takerTxOutIndex = takerTxOutIndex;
}
public String getOffererPubKey() {
public byte[] getOffererPubKey() {
return offererPubKey;
}
public void setOffererPubKey(String offererPubKey) {
public void setOffererPubKey(byte[] offererPubKey) {
this.offererPubKey = offererPubKey;
}
@ -276,7 +265,7 @@ public class BuyerAsOffererModel extends TradeSharedModel {
return trade;
}
public void setPeer(Peer peer) {
this.peer = peer;
public void setTaker(Peer taker) {
this.taker = taker;
}
}

View File

@ -80,7 +80,7 @@ public class BuyerAsOffererProtocol {
private void handleRequestTakeOfferMessage(RequestTakeOfferMessage tradeMessage, Peer peer) {
model.setTradeMessage(tradeMessage);
model.setPeer(peer);
model.setTaker(peer);
BuyerAsOffererTaskRunner<BuyerAsOffererModel> taskRunner = new BuyerAsOffererTaskRunner<>(model,
() -> {

View File

@ -28,12 +28,12 @@ public class TakerDepositPaymentRequestMessage implements Serializable, TradeMes
private final String tradeId;
private final BankAccount bankAccount;
private final String accountID;
private final String offererPubKey;
private final byte[] offererPubKey;
private final String preparedOffererDepositTxAsHex;
private final long offererTxOutIndex;
public TakerDepositPaymentRequestMessage(String tradeId, BankAccount bankAccount, String accountID,
String offererPubKey, String preparedOffererDepositTxAsHex,
byte[] offererPubKey, String preparedOffererDepositTxAsHex,
long offererTxOutIndex) {
this.tradeId = tradeId;
this.bankAccount = bankAccount;
@ -56,7 +56,7 @@ public class TakerDepositPaymentRequestMessage implements Serializable, TradeMes
return accountID;
}
public String getOffererPubKey() {
public byte[] getOffererPubKey() {
return offererPubKey;
}

View File

@ -40,12 +40,13 @@ public class CreateDepositTx extends Task<BuyerAsOffererModel> {
@Override
protected void doRun() {
try {
String offererPubKey = model.getWalletService().getAddressInfoByTradeID(model.getTrade().getId()).getPubKeyAsHexString();
byte[] offererPubKey = model.getWalletService().getAddressInfo(model.getTrade().getId()).getPubKey();
Coin offererInputAmount = model.getTrade().getSecurityDeposit().add(FeePolicy.TX_FEE);
Transaction transaction = model.getWalletService().offererCreatesMSTxAndAddPayment(
offererInputAmount,
offererPubKey,
model.getTradePubKeyAsHex(),
model.getTakerPubKey(),
model.getArbitratorPubKey(),
model.getTrade().getId());

View File

@ -42,10 +42,10 @@ public class ProcessRequestOffererPublishDepositTxMessage extends Task<BuyerAsOf
RequestOffererPublishDepositTxMessage message = (RequestOffererPublishDepositTxMessage) model.getTradeMessage();
model.setTakerPayoutAddress(nonEmptyStringOf(message.getTakerPayoutAddress()));
model.setPeersAccountId(nonEmptyStringOf(message.getTakerAccountId()));
model.setPeersBankAccount(checkNotNull(message.getTakerBankAccount()));
model.setPeersMessagePublicKey(checkNotNull(message.getTakerMessagePublicKey()));
model.setPeersContractAsJson(nonEmptyStringOf(message.getTakerContractAsJson()));
model.setTakerAccountId(nonEmptyStringOf(message.getTakerAccountId()));
model.setTakerBankAccount(checkNotNull(message.getTakerBankAccount()));
model.setTakerMessagePublicKey(checkNotNull(message.getTakerMessagePublicKey()));
model.setTakerContractAsJson(nonEmptyStringOf(message.getTakerContractAsJson()));
model.setSignedTakerDepositTxAsHex(nonEmptyStringOf(message.getSignedTakerDepositTxAsHex()));
model.setTxConnOutAsHex(nonEmptyStringOf(message.getTxConnOutAsHex()));
model.setTxScriptSigAsHex(nonEmptyStringOf(message.getTxScriptSigAsHex()));

View File

@ -36,6 +36,9 @@ public class ProcessRequestTakeOfferMessage extends Task<BuyerAsOffererModel> {
@Override
protected void doRun() {
try {
log.debug("######### " + model.getOffer().getId());
log.debug("######### " + model.getTradeMessage().getTradeId());
checkTradeId(model.getOffer().getId(), model.getTradeMessage());
complete();

View File

@ -26,6 +26,7 @@ import io.bitsquare.util.taskrunner.TaskRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
import static io.bitsquare.util.Validator.*;
public class ProcessTakeOfferFeePayedMessage extends Task<BuyerAsOffererModel> {
@ -45,7 +46,7 @@ public class ProcessTakeOfferFeePayedMessage extends Task<BuyerAsOffererModel> {
trade.setTakeOfferFeeTxID(nonEmptyStringOf(takeOfferFeePayedMessage.getTakeOfferFeeTxId()));
trade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(takeOfferFeePayedMessage.getTradeAmount())));
model.setTakeOfferFeeTxId(nonEmptyStringOf(takeOfferFeePayedMessage.getTakeOfferFeeTxId()));
model.setTradePubKeyAsHex(nonEmptyStringOf(takeOfferFeePayedMessage.getTakerPubKeyAsHex()));
model.setTakerPubKey(checkNotNull(takeOfferFeePayedMessage.getTakerPubKey()));
complete();
} catch (Throwable t) {
@ -55,5 +56,6 @@ public class ProcessTakeOfferFeePayedMessage extends Task<BuyerAsOffererModel> {
@Override
protected void updateStateOnFault() {
// do nothing
}
}

View File

@ -50,7 +50,7 @@ public class RespondToTakeOfferRequest extends Task<BuyerAsOffererModel> {
}
RespondToTakeOfferRequestMessage tradeMessage = new RespondToTakeOfferRequestMessage(model.getOpenOffer().getId(), offerIsAvailable);
model.getTradeMessageService().sendMessage(model.getPeer(), tradeMessage, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
complete();
@ -66,8 +66,8 @@ public class RespondToTakeOfferRequest extends Task<BuyerAsOffererModel> {
@Override
protected void updateStateOnFault() {
if (offerIsAvailable && model.getOpenOffer().getState() == OpenOffer.State.OFFER_ACCEPTED) {
model.getOpenOffer().setState(OpenOffer.State.OPEN);
model.setTrade(null);
model.getOpenOffer().setState(OpenOffer.State.OPEN);
}
}
}

View File

@ -43,7 +43,7 @@ public class SendBankTransferInitedMessage extends Task<BuyerAsOffererModel> {
model.getOffererPaybackAmount(),
model.getTakerPaybackAmount(),
model.getOffererPaybackAddress());
model.getTradeMessageService().sendMessage(model.getPeer(), tradeMessage, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("Sending BankTransferInitedMessage succeeded.");

View File

@ -40,7 +40,7 @@ public class SendDepositTxIdToTaker extends Task<BuyerAsOffererModel> {
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(model.getTrade().getId(),
Utils.HEX.encode(model.getTrade().getDepositTx().bitcoinSerialize()));
model.getTradeMessageService().sendMessage(model.getPeer(), tradeMessage, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("DepositTxPublishedMessage successfully arrived at peer");

View File

@ -43,7 +43,7 @@ public class SendTakerDepositPaymentRequest extends Task<BuyerAsOffererModel> {
model.getPreparedOffererDepositTxAsHex(),
model.getOffererTxOutIndex());
model.getTradeMessageService().sendMessage(model.getPeer(), tradeMessage, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("RequestTakerDepositPaymentMessage successfully arrived at peer");

View File

@ -43,11 +43,11 @@ public class VerifyAndSignContract extends Task<BuyerAsOffererModel> {
trade.getTradeAmount(),
model.getTakeOfferFeeTxId(),
model.getAccountId(),
model.getPeersAccountId(),
model.getTakerAccountId(),
model.getBankAccount(),
model.getPeersBankAccount(),
model.getTakerBankAccount(),
model.getMessagePublicKey(),
model.getPeersMessagePublicKey());
model.getTakerMessagePublicKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = model.getSignatureService().signMessage(model.getAccountKey(), contractAsJson);

View File

@ -35,7 +35,7 @@ public class VerifyTakerAccount extends Task<BuyerAsOffererModel> {
protected void doRun() {
//TODO mocked yet
if (model.getBlockChainService().verifyAccountRegistration()) {
if (model.getBlockChainService().isAccountBlackListed(model.getPeersAccountId(), model.getPeersBankAccount())) {
if (model.getBlockChainService().isAccountBlackListed(model.getTakerAccountId(), model.getTakerBankAccount())) {
log.error("Taker is blacklisted");
failed("Taker is blacklisted");
}

View File

@ -23,41 +23,31 @@ import io.bitsquare.crypto.SignatureService;
import io.bitsquare.network.Peer;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.trade.protocol.trade.TradeSharedModel;
import io.bitsquare.trade.protocol.trade.OfferSharedModel;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import java.security.PublicKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SellerAsTakerModel extends TradeSharedModel {
public class SellerAsTakerModel extends OfferSharedModel {
private static final Logger log = LoggerFactory.getLogger(SellerAsTakerModel.class);
// provided
private final Trade trade;
// derived
private final Coin tradeAmount;
private final Coin securityDeposit;
private final PublicKey offererMessagePublicKey;
// written/read by task
private Peer peer;
private String preparedPeersDepositTxAsHex;
private Peer offerer;
private String preparedOffererDepositTxAsHex;
private String depositTxAsHex;
private Transaction signedTakerDepositTx;
private Transaction payoutTx;
private String payoutTxAsHex;
private Coin takerPaybackAmount;
private String peersPubKey;
private long peersTxOutIndex;
private byte[] offererPubKey;
private long offererTxOutIndex;
private String offererSignatureR;
private String offererSignatureS;
private Coin offererPaybackAmount;
@ -77,10 +67,7 @@ public class SellerAsTakerModel extends TradeSharedModel {
user);
this.trade = trade;
tradeAmount = trade.getTradeAmount();
securityDeposit = trade.getSecurityDeposit();
offererMessagePublicKey = offer.getMessagePublicKey();
tradePubKeyAsHex = walletService.getAddressInfoByTradeID(trade.getId()).getPubKeyAsHexString();
takerPubKey = walletService.getAddressInfo(trade.getId()).getPubKey();
}
// getter/setter
@ -88,24 +75,12 @@ public class SellerAsTakerModel extends TradeSharedModel {
return trade;
}
public Coin getTradeAmount() {
return tradeAmount;
public Peer getOfferer() {
return offerer;
}
public Coin getSecurityDeposit() {
return securityDeposit;
}
public PublicKey getOffererMessagePublicKey() {
return offererMessagePublicKey;
}
public Peer getPeer() {
return peer;
}
public void setPeer(Peer peer) {
this.peer = peer;
public void setOfferer(Peer offerer) {
this.offerer = offerer;
}
public Transaction getPayoutTx() {
@ -124,28 +99,28 @@ public class SellerAsTakerModel extends TradeSharedModel {
this.payoutTxAsHex = payoutTxAsHex;
}
public String getPeersPubKey() {
return peersPubKey;
public byte[] getOffererPubKey() {
return offererPubKey;
}
public void setPeersPubKey(String peersPubKey) {
this.peersPubKey = peersPubKey;
public void setOffererPubKeyAsHex(byte[] offererPubKey) {
this.offererPubKey = offererPubKey;
}
public String getPreparedPeersDepositTxAsHex() {
return preparedPeersDepositTxAsHex;
public String getPreparedOffererDepositTxAsHex() {
return preparedOffererDepositTxAsHex;
}
public void setPreparedPeersDepositTxAsHex(String preparedPeersDepositTxAsHex) {
this.preparedPeersDepositTxAsHex = preparedPeersDepositTxAsHex;
public void setPreparedOffererDepositTxAsHex(String preparedOffererDepositTxAsHex) {
this.preparedOffererDepositTxAsHex = preparedOffererDepositTxAsHex;
}
public long getPeersTxOutIndex() {
return peersTxOutIndex;
public long getOffererTxOutIndex() {
return offererTxOutIndex;
}
public void setPeersTxOutIndex(long peersTxOutIndex) {
this.peersTxOutIndex = peersTxOutIndex;
public void setOffererTxOutIndex(long offererTxOutIndex) {
this.offererTxOutIndex = offererTxOutIndex;
}
public String getDepositTxAsHex() {

View File

@ -23,6 +23,7 @@ import java.io.Serializable;
public class RequestTakeOfferMessage implements Serializable, TradeMessage {
private static final long serialVersionUID = 4660151440192191798L;
private final String tradeId;
public RequestTakeOfferMessage(String tradeId) {

View File

@ -25,17 +25,17 @@ import java.io.Serializable;
public class TakeOfferFeePayedMessage implements Serializable, TradeMessage {
private static final long serialVersionUID = -5057935061275354312L;
private final String tradeId;
private final Coin tradeAmount;
private final String takeOfferFeeTxID;
private final String tradePubKeyAsHex;
private final byte[] takerPubKey;
public TakeOfferFeePayedMessage(String tradeId, String takeOfferFeeTxID, Coin tradeAmount, String tradePubKeyAsHex) {
public TakeOfferFeePayedMessage(String tradeId, String takeOfferFeeTxID, Coin tradeAmount, byte[] takerPubKey) {
this.tradeId = tradeId;
this.takeOfferFeeTxID = takeOfferFeeTxID;
this.tradeAmount = tradeAmount;
this.tradePubKeyAsHex = tradePubKeyAsHex;
this.takerPubKey = takerPubKey;
}
@Override
@ -51,8 +51,8 @@ public class TakeOfferFeePayedMessage implements Serializable, TradeMessage {
return takeOfferFeeTxID;
}
public String getTakerPubKeyAsHex() {
return tradePubKeyAsHex;
public byte[] getTakerPubKey() {
return takerPubKey;
}
}

View File

@ -39,13 +39,13 @@ public class CreateAndSignContract extends Task<SellerAsTakerModel> {
Trade trade = model.getTrade();
Contract contract = new Contract(
model.getOffer(),
model.getTradeAmount(),
model.getTrade().getTradeAmount(),
trade.getTakeOfferFeeTxId(),
model.getPeersAccountId(),
model.getTakerAccountId(),
model.getAccountId(),
model.getPeersBankAccount(),
model.getTakerBankAccount(),
model.getBankAccount(),
model.getOffererMessagePublicKey(),
model.getOffer().getMessagePublicKey(),
model.getMessagePublicKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = model.getSignatureService().signMessage(model.getAccountKey(), contractAsJson);

View File

@ -42,7 +42,7 @@ public class GetPeerAddress extends Task<SellerAsTakerModel> {
public void onResult(Peer peer) {
log.trace("Found peer: " + peer.toString());
model.setPeer(peer);
model.setOfferer(peer);
complete();
}

View File

@ -38,15 +38,15 @@ public class PayDeposit extends Task<SellerAsTakerModel> {
@Override
protected void doRun() {
try {
Coin amountToPay = model.getTradeAmount().add(model.getSecurityDeposit());
Coin msOutputAmount = amountToPay.add(model.getSecurityDeposit());
Coin amountToPay = model.getTrade().getTradeAmount().add(model.getTrade().getSecurityDeposit());
Coin msOutputAmount = amountToPay.add(model.getTrade().getSecurityDeposit());
Transaction signedTakerDepositTx = model.getWalletService().takerAddPaymentAndSignTx(
amountToPay,
msOutputAmount,
model.getPeersPubKey(),
model.getTradePubKeyAsHex(),
model.getOffererPubKey(),
model.getTakerPubKey(),
model.getArbitratorPubKey(),
model.getPreparedPeersDepositTxAsHex(),
model.getPreparedOffererDepositTxAsHex(),
model.getTrade().getId());
model.setSignedTakerDepositTx(signedTakerDepositTx);

View File

@ -58,6 +58,7 @@ public class PayTakeOfferFee extends Task<SellerAsTakerModel> {
}
});
} catch (InsufficientMoneyException e) {
appendToErrorMessage(e.getMessage());
failed(e);
}
}
@ -67,6 +68,7 @@ public class PayTakeOfferFee extends Task<SellerAsTakerModel> {
// As long as the take offer fee was not paid nothing critical happens.
// The take offer process can be repeated so we reset the trade state.
appendToErrorMessage("Take offer fee payment failed. Maybe your network connection was lost. Please try again.");
model.getTrade().setState(Trade.State.OPEN);
model.getTrade().setTakeOfferFeeTxID(null);
model.getTrade().setState(Trade.State.TAKE_OFFER_FEE_PAYMENT_FAILED);
}
}

View File

@ -40,11 +40,11 @@ public class ProcessTakerDepositPaymentRequestMessage extends Task<SellerAsTaker
try {
checkTradeId(model.getTrade().getId(), model.getTradeMessage());
TakerDepositPaymentRequestMessage message = (TakerDepositPaymentRequestMessage) model.getTradeMessage();
model.setPeersAccountId(nonEmptyStringOf(message.getAccountId()));
model.setPeersBankAccount(checkNotNull(message.getBankAccount()));
model.setPeersPubKey(nonEmptyStringOf(message.getOffererPubKey()));
model.setPreparedPeersDepositTxAsHex(nonEmptyStringOf(message.getPreparedOffererDepositTxAsHex()));
model.setPeersTxOutIndex(nonNegativeLongOf(message.getOffererTxOutIndex()));
model.setTakerAccountId(nonEmptyStringOf(message.getAccountId()));
model.setTakerBankAccount(checkNotNull(message.getBankAccount()));
model.setOffererPubKeyAsHex(checkNotNull(message.getOffererPubKey()));
model.setPreparedOffererDepositTxAsHex(nonEmptyStringOf(message.getPreparedOffererDepositTxAsHex()));
model.setOffererTxOutIndex(nonNegativeLongOf(message.getOffererTxOutIndex()));
complete();
} catch (Throwable t) {

View File

@ -21,18 +21,14 @@ import io.bitsquare.offer.Offer;
import io.bitsquare.trade.listeners.SendMessageListener;
import io.bitsquare.trade.protocol.trade.taker.SellerAsTakerModel;
import io.bitsquare.trade.protocol.trade.taker.messages.RequestTakeOfferMessage;
import io.bitsquare.util.Utilities;
import io.bitsquare.util.taskrunner.Task;
import io.bitsquare.util.taskrunner.TaskRunner;
import javafx.animation.AnimationTimer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RequestTakeOffer extends Task<SellerAsTakerModel> {
private static final Logger log = LoggerFactory.getLogger(RequestTakeOffer.class);
private AnimationTimer timeoutTimer;
public RequestTakeOffer(TaskRunner taskHandler, SellerAsTakerModel model) {
super(taskHandler, model);
@ -40,18 +36,11 @@ public class RequestTakeOffer extends Task<SellerAsTakerModel> {
@Override
protected void doRun() {
timeoutTimer = Utilities.setTimeout(10000, animationTimer -> {
failed("Timeout reached. We did not get any response form the offerer.");
model.getOffer().setState(Offer.State.OFFERER_OFFLINE);
return null;
});
timeoutTimer.start();
model.getTradeMessageService().sendMessage(model.getPeer(), new RequestTakeOfferMessage(model.getTrade().getId()),
log.debug("######### " + model.getTrade().getId());
model.getTradeMessageService().sendMessage(model.getOfferer(), new RequestTakeOfferMessage(model.getTrade().getId()),
new SendMessageListener() {
@Override
public void handleResult() {
timeoutTimer.stop();
complete();
}
@ -65,7 +54,6 @@ public class RequestTakeOffer extends Task<SellerAsTakerModel> {
@Override
protected void updateStateOnFault() {
timeoutTimer.stop();
if (model.getOffer().getState() != Offer.State.OFFERER_OFFLINE)
model.getOffer().setState(Offer.State.AVAILABILITY_CHECK_FAILED);
}

View File

@ -36,7 +36,7 @@ public class SendPayoutTxToOfferer extends Task<SellerAsTakerModel> {
@Override
protected void doRun() {
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(model.getTrade().getId(), model.getPayoutTxAsHex());
model.getTradeMessageService().sendMessage(model.getPeer(), tradeMessage, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getOfferer(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("PayoutTxPublishedMessage successfully arrived at peer");

View File

@ -51,11 +51,11 @@ public class SendSignedTakerDepositTxAsHex extends Task<SellerAsTakerModel> {
Utils.HEX.encode(signedTakerDepositTx.getInput(1).getConnectedOutput().getParentTransaction().bitcoinSerialize()),
model.getTrade().getContractAsJson(),
model.getTrade().getTakerContractSignature(),
model.getWalletService().getAddressInfoByTradeID(model.getTrade().getId()).getAddressString(),
model.getWalletService().getAddressInfo(model.getTrade().getId()).getAddressString(),
takerTxOutIndex,
model.getPeersTxOutIndex());
model.getOffererTxOutIndex());
model.getTradeMessageService().sendMessage(model.getPeer(), tradeMessage, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getOfferer(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
complete();

View File

@ -17,6 +17,7 @@
package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.listeners.SendMessageListener;
import io.bitsquare.trade.protocol.trade.taker.SellerAsTakerModel;
import io.bitsquare.trade.protocol.trade.taker.messages.TakeOfferFeePayedMessage;
@ -40,12 +41,11 @@ public class SendTakeOfferFeePayedMessage extends Task<SellerAsTakerModel> {
TakeOfferFeePayedMessage msg = new TakeOfferFeePayedMessage(
model.getTrade().getId(),
model.getTrade().getTakeOfferFeeTxId(),
model.getTradeAmount(),
model.getTradePubKeyAsHex()
model.getTrade().getTradeAmount(),
model.getTakerPubKey()
);
model.getTradeMessageService().sendMessage(model.getPeer(), msg, new SendMessageListener() {
model.getTradeMessageService().sendMessage(model.getOfferer(), msg, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("Sending TakeOfferFeePayedMessage succeeded.");
@ -71,5 +71,6 @@ public class SendTakeOfferFeePayedMessage extends Task<SellerAsTakerModel> {
protected void updateStateOnFault() {
appendToErrorMessage("Sending TakeOfferFeePayedMessage to offerer failed. Maybe the network connection was lost or the offerer lost his connection. " +
"We persisted the state of the trade, please try again later or cancel that trade.");
model.getTrade().setState(Trade.State.MESSAGE_SENDING_FAILED);
}
}

View File

@ -34,7 +34,7 @@ public class VerifyOffererAccount extends Task<SellerAsTakerModel> {
@Override
protected void doRun() {
if (model.getBlockChainService().verifyAccountRegistration()) {
if (model.getBlockChainService().isAccountBlackListed(model.getPeersAccountId(), model.getPeersBankAccount())) {
if (model.getBlockChainService().isAccountBlackListed(model.getTakerAccountId(), model.getTakerBankAccount())) {
failed("Taker is blacklisted.");
}
else {

View File

@ -1,68 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.util;
import org.bitcoinj.core.Utils;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Bytes {
private static final Logger log = LoggerFactory.getLogger(Bytes.class);
public final byte[] bytes;
public final String string;
public Bytes(byte[] bytes) {
this.bytes = Arrays.copyOf(bytes, bytes.length);
this.string = Utils.HEX.encode(bytes);
}
public Bytes(String string) {
this.string = string;
this.bytes = Utils.HEX.decode(string);
}
@Override
public String toString() {
return string;
}
public static class GsonAdapter extends TypeAdapter<Bytes> {
@Override
public Bytes read(JsonReader reader) throws IOException {
return new Bytes(reader.nextString());
}
@Override
public void write(JsonWriter out, Bytes value) throws IOException {
if (value == null)
out.nullValue();
else
out.value(value.string);
}
}
}

View File

@ -145,7 +145,7 @@ public class PlaceOfferProtocolTest {
() -> {
log.trace("wallet completed");
// 1. Use that address for funding the trading wallet
address = walletService.getAddressInfoByTradeID(OFFER_ID).getAddress();
address = walletService.getAddressInfo(OFFER_ID).getAddress();
log.info("address for funding wallet = " + address.toString());//muoTvFHJmQwPKYoA8Fr7t87UCSfZM4fciG
log.info("Balance = " + walletService.getBalanceForAddress(address));
countDownLatch.countDown();