use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.
the class ArbitratorRegistrationViewModel method onRegister.
void onRegister(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
updateDisableStates();
if (allDataValid) {
AddressEntry arbitratorDepositAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.ARBITRATOR);
String registrationSignature = arbitratorManager.signStorageSignaturePubKey(registrationKey);
Arbitrator arbitrator = new Arbitrator(p2PService.getAddress(), arbitratorDepositAddressEntry.getPubKey(), arbitratorDepositAddressEntry.getAddressString(), keyRing.getPubKeyRing(), new ArrayList<>(languageCodes), new Date(), registrationKey.getPubKey(), registrationSignature);
arbitratorManager.addArbitrator(arbitrator, () -> {
updateDisableStates();
resultHandler.handleResult();
}, (errorMessage) -> {
updateDisableStates();
errorMessageHandler.handleErrorMessage(errorMessage);
});
}
}
use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.
the class SignAndFinalizePayoutTx method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
Coin sellerPayoutAmount = FeePolicy.getSecurityDeposit(trade.getOffer());
Coin buyerPayoutAmount = sellerPayoutAmount.add(trade.getTradeAmount());
WalletService walletService = processModel.getWalletService();
AddressEntry buyerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
AddressEntry multiSigAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
Transaction transaction = processModel.getTradeWalletService().buyerSignsAndFinalizesPayoutTx(trade.getDepositTx(), processModel.tradingPeer.getSignature(), buyerPayoutAmount, sellerPayoutAmount, buyerAddressEntry.getAddressString(), processModel.tradingPeer.getPayoutAddressString(), multiSigAddressEntry.getKeyPair(), trade.getLockTimeAsBlockHeight(), multiSigAddressEntry.getPubKey(), processModel.tradingPeer.getMultiSigPubKey(), trade.getArbitratorPubKey());
trade.setPayoutTx(transaction);
trade.setState(Trade.State.BUYER_COMMITTED_PAYOUT_TX);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.
the class TakerCreatesDepositTxInputsAsBuyer method run.
@Override
protected void run() {
try {
runInterceptHook();
Offer offer = trade.getOffer();
Coin takerInputAmount = FeePolicy.getSecurityDeposit(offer).add(FeePolicy.getFixedTxFeeForTrades(offer));
WalletService walletService = processModel.getWalletService();
AddressEntry takersAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositsTxInputs(takerInputAmount, takersAddressEntry.getAddress(), changeAddress);
processModel.setRawTransactionInputs(result.rawTransactionInputs);
processModel.setChangeOutputValue(result.changeOutputValue);
processModel.setChangeOutputAddress(result.changeOutputAddress);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.
the class CreateAndSignContract method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTakeOfferFeeTxId(), "trade.getTakeOfferFeeTxId() must not be null");
TradingPeer taker = processModel.tradingPeer;
PaymentAccountContractData offererPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
checkNotNull(offererPaymentAccountContractData, "offererPaymentAccountContractData must not be null");
PaymentAccountContractData takerPaymentAccountContractData = taker.getPaymentAccountContractData();
boolean isBuyerOffererAndSellerTaker = trade instanceof BuyerAsOffererTrade;
NodeAddress buyerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
NodeAddress sellerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
log.debug("buyerAddress " + buyerNodeAddress);
log.debug("sellerAddress " + sellerNodeAddress);
WalletService walletService = processModel.getWalletService();
AddressEntry takerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
AddressEntry offererAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
Contract contract = new Contract(processModel.getOffer(), trade.getTradeAmount(), trade.getTradePrice(), trade.getTakeOfferFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), isBuyerOffererAndSellerTaker, processModel.getAccountId(), taker.getAccountId(), offererPaymentAccountContractData, takerPaymentAccountContractData, processModel.getPubKeyRing(), taker.getPubKeyRing(), takerAddressEntry.getAddressString(), taker.getPayoutAddressString(), offererAddressEntry.getPubKey(), taker.getMultiSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);
trade.setOffererContractSignature(signature);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.
the class SendFinalizePayoutTxRequest method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getTradingPeerNodeAddress() != null) {
WalletService walletService = processModel.getWalletService();
AddressEntry sellerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
FinalizePayoutTxRequest message = new FinalizePayoutTxRequest(processModel.getId(), processModel.getPayoutTxSignature(), sellerPayoutAddressEntry.getAddressString(), trade.getLockTimeAsBlockHeight(), processModel.getMyNodeAddress());
processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), message, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.trace("Message arrived at peer.");
trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
complete();
}
@Override
public void onStoredInMailbox() {
log.trace("Message stored in mailbox.");
trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
complete();
}
@Override
public void onFault(String errorMessage) {
appendToErrorMessage("FinalizePayoutTxRequest sending failed. errorMessage=" + errorMessage);
failed(errorMessage);
}
});
} else {
log.error("trade.getTradingPeerAddress() = " + trade.getTradingPeerNodeAddress());
failed("A needed dependency is null");
}
} catch (Throwable t) {
failed(t);
}
}
Aggregations