Support offerer offline at payout tx with mailbox

This commit is contained in:
Manfred Karrer 2015-03-21 12:10:40 +01:00
parent 12bea799f3
commit 02c9035af5
18 changed files with 51 additions and 27 deletions

View File

@ -583,11 +583,11 @@ public class TradeManager {
mailboxMessages.put(tradeId, mailboxMessage);
log.trace("mailboxMessage with tradeID " + tradeId);
if (takerAsSellerProtocolMap.containsKey(tradeId)) {
takerAsSellerProtocolMap.get(tradeId).setMailboxMessage(encrypted);
takerAsSellerProtocolMap.get(tradeId).setMailboxMessage(mailboxMessage);
log.trace("sellerAsTakerProtocolMap exist with tradeID " + tradeId);
}
if (offererAsBuyerProtocolMap.containsKey(tradeId)) {
offererAsBuyerProtocolMap.get(tradeId).setMailboxMessage(encrypted);
offererAsBuyerProtocolMap.get(tradeId).setMailboxMessage(mailboxMessage);
log.trace("buyerAcceptsOfferProtocolMap exist with tradeID " + tradeId);
}
}

View File

@ -26,12 +26,12 @@ public class RequestDepositTxInputsMessage extends TradeMessage implements Seria
public final Coin tradeAmount;
public final String takeOfferFeeTxId;
public final byte[] takerPubKey;
public final byte[] takerTradeWalletPubKey;
public RequestDepositTxInputsMessage(String tradeId, String takeOfferFeeTxId, Coin tradeAmount, byte[] takerPubKey) {
public RequestDepositTxInputsMessage(String tradeId, String takeOfferFeeTxId, Coin tradeAmount, byte[] takerTradeWalletPubKey) {
this.tradeId = tradeId;
this.takeOfferFeeTxId = takeOfferFeeTxId;
this.tradeAmount = tradeAmount;
this.takerPubKey = takerPubKey;
this.takerTradeWalletPubKey = takerTradeWalletPubKey;
}
}

View File

@ -23,6 +23,8 @@ import org.bitcoinj.core.TransactionOutput;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.List;
public class RequestTakerDepositPaymentMessage extends TradeMessage implements Serializable {
@ -30,20 +32,28 @@ public class RequestTakerDepositPaymentMessage extends TradeMessage implements S
public final List<TransactionOutput> offererConnectedOutputsForAllInputs;
public final List<TransactionOutput> offererOutputs;
public final byte[] offererPubKey;
public final byte[] offererTradeWalletPubKey;
public final PublicKey offererP2PSigPublicKey;
public final PublicKey offererP2PEncryptPublicKey;
public final FiatAccount offererFiatAccount;
public final String offererAccountId;
public RequestTakerDepositPaymentMessage(String tradeId,
List<TransactionOutput> offererConnectedOutputsForAllInputs,
List<TransactionOutput> offererOutputs,
byte[] offererPubKey,
byte[] offererTradeWalletPubKey,
PublicKey offererP2PSigPublicKey,
PublicKey offererP2PEncryptPublicKey,
FiatAccount offererFiatAccount,
String offererAccountId) {
this.offererP2PSigPublicKey = offererP2PSigPublicKey;
this.offererP2PEncryptPublicKey = offererP2PEncryptPublicKey;
this.tradeId = tradeId;
this.offererConnectedOutputsForAllInputs = offererConnectedOutputsForAllInputs;
this.offererOutputs = offererOutputs;
this.offererPubKey = offererPubKey;
this.offererTradeWalletPubKey = offererTradeWalletPubKey;
this.offererFiatAccount = offererFiatAccount;
this.offererAccountId = offererAccountId;
}

View File

@ -38,10 +38,11 @@ public class Offerer implements Serializable {
transient public FiatAccount fiatAccount;
transient public String accountId;
transient public PublicKey p2pSigPubKey;
transient public PublicKey p2pEncryptPubKey;
transient public byte[] registrationPubKey;
transient public DeterministicKey registrationKeyPair;
transient public AddressEntry addressEntry;
transient public byte[] pubKey;
transient public byte[] tradeWalletPubKey;
// written by tasks
public byte[] payoutTxSignature;

View File

@ -82,7 +82,8 @@ public class OffererAsBuyerModel extends SharedTradeModel implements Serializabl
offerer.fiatAccount = user.getBankAccount(offer.getBankAccountId());
offerer.accountId = user.getAccountId();
offerer.p2pSigPubKey = user.getP2PSigPubKey();
offerer.pubKey = offerer.addressEntry.getPubKey();
offerer.p2pEncryptPubKey = user.getP2PEncryptPubKey();
offerer.tradeWalletPubKey = offerer.addressEntry.getPubKey();
log.debug("BuyerAsOffererModel addressEntry " + offerer.addressEntry);
}

View File

@ -45,5 +45,5 @@ public class Taker implements Serializable {
public Transaction preparedDepositTx;
public List<TransactionOutput> connectedOutputsForAllInputs;
public String payoutAddressString;
public byte[] pubKey;
public byte[] tradeWalletPubKey;
}

View File

@ -48,8 +48,8 @@ public class CreateAndSignPayoutTx extends Task<OffererAsBuyerModel> {
takerPayoutAmount,
model.offerer.addressEntry,
model.taker.payoutAddressString,
model.offerer.pubKey,
model.taker.pubKey,
model.offerer.tradeWalletPubKey,
model.taker.tradeWalletPubKey,
model.arbitratorPubKey);
model.offerer.payoutTxSignature = offererPayoutTxSignature;

View File

@ -45,7 +45,7 @@ public class ProcessRequestDepositTxInputsMessage extends Task<OffererAsBuyerMod
trade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(requestDepositTxInputsMessage.tradeAmount)));
model.setTakeOfferFeeTxId(nonEmptyStringOf(requestDepositTxInputsMessage.takeOfferFeeTxId));
model.taker.pubKey = checkNotNull(requestDepositTxInputsMessage.takerPubKey);
model.taker.tradeWalletPubKey = checkNotNull(requestDepositTxInputsMessage.takerTradeWalletPubKey);
complete();
} catch (Throwable t) {

View File

@ -39,7 +39,9 @@ public class RequestTakerDepositPayment extends Task<OffererAsBuyerModel> {
model.id,
model.offerer.connectedOutputsForAllInputs,
model.offerer.outputs,
model.offerer.pubKey,
model.offerer.tradeWalletPubKey,
model.offerer.p2pSigPubKey,
model.offerer.p2pEncryptPubKey,
model.offerer.fiatAccount,
model.offerer.accountId);

View File

@ -50,8 +50,8 @@ public class SignAndPublishDepositTx extends Task<OffererAsBuyerModel> {
model.taker.connectedOutputsForAllInputs,
model.offerer.outputs,
offererInputAmount,
model.offerer.pubKey,
model.taker.pubKey,
model.offerer.tradeWalletPubKey,
model.taker.tradeWalletPubKey,
model.arbitratorPubKey,
new FutureCallback<Transaction>() {
@Override

View File

@ -25,6 +25,8 @@ import org.bitcoinj.core.TransactionOutput;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.List;
public class Offerer implements Serializable {
@ -35,7 +37,7 @@ public class Offerer implements Serializable {
public Peer peer;
// written by tasks
public byte[] pubKey;
public byte[] tradeWalletPubKey;
public Coin payoutAmount;
public String payoutAddressString;
public List<TransactionOutput> connectedOutputsForAllInputs;
@ -43,5 +45,7 @@ public class Offerer implements Serializable {
public byte[] signature;
public FiatAccount fiatAccount;
public String accountId;
public PublicKey p2pSigPublicKey;
public PublicKey p2pEncryptPubKey;
}

View File

@ -43,7 +43,7 @@ public class Taker implements Serializable {
transient public byte[] registrationPubKey; // TODO not read yet, missing impl.
transient public DeterministicKey registrationKeyPair;
transient public AddressEntry addressEntry;
transient public byte[] pubKey;
transient public byte[] tradeWalletPubKey;
// written by tasks
public List<TransactionOutput> connectedOutputsForAllInputs;

View File

@ -91,7 +91,7 @@ public class TakerAsSellerModel extends SharedTradeModel implements Serializable
taker.accountId = user.getAccountId();
taker.p2pSigPubKey = user.getP2PSigPubKey();
taker.p2pEncryptPublicKey = user.getP2PEncryptPubKey();
taker.pubKey = taker.addressEntry.getPubKey();
taker.tradeWalletPubKey = taker.addressEntry.getPubKey();
}
// Get called form taskRunner after each completed task

View File

@ -44,7 +44,9 @@ public class ProcessRequestTakerDepositPaymentMessage extends Task<TakerAsSeller
model.offerer.connectedOutputsForAllInputs = checkNotNull(message.offererConnectedOutputsForAllInputs);
checkArgument(message.offererConnectedOutputsForAllInputs.size() > 0);
model.offerer.outputs = checkNotNull(message.offererOutputs);
model.offerer.pubKey = checkNotNull(message.offererPubKey);
model.offerer.tradeWalletPubKey = checkNotNull(message.offererTradeWalletPubKey);
model.offerer.p2pSigPublicKey = checkNotNull(message.offererP2PSigPublicKey);
model.offerer.p2pEncryptPubKey = checkNotNull(message.offererP2PEncryptPublicKey);
model.offerer.fiatAccount = checkNotNull(message.offererFiatAccount);
model.offerer.accountId = nonEmptyStringOf(message.offererAccountId);

View File

@ -36,7 +36,11 @@ public class SendPayoutTxToOfferer extends Task<TakerAsSellerModel> {
@Override
protected void doRun() {
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(model.id, model.getPayoutTx());
model.messageService.sendMessage(model.offerer.peer, tradeMessage, new SendMessageListener() {
model.messageService.sendMessage(model.offerer.peer,
tradeMessage,
model.offerer.p2pSigPublicKey,
model.offerer.p2pEncryptPubKey,
new SendMessageListener() {
@Override
public void handleResult() {
log.trace("PayoutTxPublishedMessage successfully arrived at peer");

View File

@ -44,7 +44,7 @@ public class SendRequestDepositTxInputsMessage extends Task<TakerAsSellerModel>
model.id,
model.getTakeOfferFeeTx().getHashAsString(),
model.trade.getTradeAmount(),
model.taker.pubKey
model.taker.tradeWalletPubKey
);
model.messageService.sendMessage(model.offerer.peer, msg, new SendMessageListener() {

View File

@ -48,8 +48,8 @@ public class SignAndPublishPayoutTx extends Task<TakerAsSellerModel> {
model.taker.payoutAmount,
model.offerer.payoutAddressString,
model.taker.addressEntry,
model.offerer.pubKey,
model.taker.pubKey,
model.offerer.tradeWalletPubKey,
model.taker.tradeWalletPubKey,
model.arbitratorPubKey,
new FutureCallback<Transaction>() {
@Override

View File

@ -48,8 +48,8 @@ public class TakerCreatesAndSignsDepositTx extends Task<TakerAsSellerModel> {
model.offerer.connectedOutputsForAllInputs,
model.offerer.outputs,
model.taker.addressEntry,
model.offerer.pubKey,
model.taker.pubKey,
model.offerer.tradeWalletPubKey,
model.taker.tradeWalletPubKey,
model.arbitratorPubKey);