mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-20 21:04:28 -04:00
payment to MS fund
This commit is contained in:
parent
7d0676a995
commit
a4efa29bcd
37 changed files with 1081 additions and 546 deletions
|
@ -1,8 +1,11 @@
|
|||
package io.bitsquare.trade;
|
||||
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.btc.BlockChainFacade;
|
||||
import io.bitsquare.btc.Fees;
|
||||
import io.bitsquare.btc.KeyPair;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
|
@ -18,8 +21,9 @@ import java.util.HashMap;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Main facade for operating with trade domain between GUI and services (msg, btc)
|
||||
* Represents trade domain. Keeps complexity of process apart from view controller
|
||||
*/
|
||||
//TODO use scheduler/process pattern with tasks for every async job
|
||||
public class Trading
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(Trading.class);
|
||||
|
@ -34,6 +38,11 @@ public class Trading
|
|||
private CryptoFacade cryptoFacade;
|
||||
private Settings settings;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public Trading(User user,
|
||||
Settings settings,
|
||||
|
@ -50,64 +59,21 @@ public class Trading
|
|||
this.cryptoFacade = cryptoFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offer
|
||||
*/
|
||||
public String placeNewOffer(Offer offer) throws InsufficientMoneyException
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void placeNewOffer(Offer offer, FutureCallback<Transaction> callback) throws InsufficientMoneyException
|
||||
{
|
||||
log.info("place New Offer");
|
||||
offers.put(offer.getUid().toString(), offer);
|
||||
String txID = walletFacade.payOfferFee();
|
||||
offer.setOfferPaymentTxID(txID);
|
||||
walletFacade.payFee(Fees.OFFER_CREATION_FEE, callback);
|
||||
|
||||
messageFacade.broadcast(new Message(Message.BROADCAST_NEW_OFFER, offer));
|
||||
return txID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taker requests offerer to take the offer
|
||||
*
|
||||
* @param trade
|
||||
*/
|
||||
public void sendTakeOfferRequest(Trade trade)
|
||||
{
|
||||
log.info("Taker asks offerer to take his offer");
|
||||
//messageFacade.send(new Message(Message.REQUEST_TAKE_OFFER, trade), trade.getOffer().getOfferer().getMessageID());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param trade
|
||||
* @return
|
||||
*/
|
||||
public Contract createNewContract(Trade trade)
|
||||
{
|
||||
log.info("create new contract");
|
||||
KeyPair address = walletFacade.createNewAddress();
|
||||
|
||||
Contract contract = new Contract(user, trade, address.getPubKey());
|
||||
contracts.put(trade.getUid().toString(), contract);
|
||||
return contract;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contract
|
||||
*/
|
||||
public void signContract(Contract contract)
|
||||
{
|
||||
log.info("sign Contract");
|
||||
|
||||
String contractAsJson = Utils.convertToJson(contract);
|
||||
|
||||
contract.getTrade().setJsonRepresentation(contractAsJson);
|
||||
contract.getTrade().setSignature(cryptoFacade.signContract(contractAsJson));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offer
|
||||
* @return
|
||||
*/
|
||||
public Trade createNewTrade(Offer offer)
|
||||
public Trade createTrade(Offer offer)
|
||||
{
|
||||
log.info("create New Trade");
|
||||
Trade trade = new Trade(offer);
|
||||
|
@ -115,55 +81,63 @@ public class Trading
|
|||
return trade;
|
||||
}
|
||||
|
||||
|
||||
public HashMap<String, Trade> getTrades()
|
||||
public Contract createContract(Trade trade)
|
||||
{
|
||||
return trades;
|
||||
log.info("create new contract");
|
||||
KeyPair address = new KeyPair(UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
||||
//TODO
|
||||
Contract contract = new Contract(user, trade, address.getPubKey());
|
||||
contracts.put(trade.getUid().toString(), contract);
|
||||
return contract;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trade
|
||||
*/
|
||||
public void payOfferFee(Trade trade)
|
||||
|
||||
// trade process
|
||||
// 1
|
||||
public void sendTakeOfferRequest(Trade trade)
|
||||
{
|
||||
log.info("Taker asks offerer to take his offer");
|
||||
//messageFacade.send(new Message(Message.REQUEST_TAKE_OFFER, trade), trade.getOffer().getOfferer().getMessageID());
|
||||
}
|
||||
|
||||
// 2
|
||||
public void payOfferFee(Trade trade, FutureCallback<Transaction> callback) throws InsufficientMoneyException
|
||||
{
|
||||
log.info("Pay offer fee");
|
||||
|
||||
trade.setTakeOfferFeePayed(true);
|
||||
walletFacade.payFee(Fees.OFFER_TAKER_FEE, callback);
|
||||
|
||||
String txID = UUID.randomUUID().toString();
|
||||
trade.setTakeOfferFeePayed(true);
|
||||
trade.setTakeOfferFeeTxID(txID);
|
||||
|
||||
log.info("Taker asks offerer for confirmation for his fee payment. txID=" + txID);
|
||||
log.info("Taker asks offerer for confirmation for his fee payment.");
|
||||
// messageFacade.send(new Message(Message.REQUEST_OFFER_FEE_PAYMENT_CONFIRM, trade), trade.getOffer().getOfferer().getMessageID());
|
||||
}
|
||||
|
||||
|
||||
// 3
|
||||
public void requestOffererDetailData()
|
||||
{
|
||||
log.info("Request offerer detail data");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trade
|
||||
*/
|
||||
// 4
|
||||
public void signContract(Contract contract)
|
||||
{
|
||||
log.info("sign Contract");
|
||||
|
||||
String contractAsJson = Utils.objectToJson(contract);
|
||||
|
||||
contract.getTrade().setJsonRepresentation(contractAsJson);
|
||||
contract.getTrade().setSignature(cryptoFacade.signContract(walletFacade.getAccountKey(), contractAsJson));
|
||||
}
|
||||
|
||||
// 5
|
||||
public void payToDepositTx(Trade trade)
|
||||
{
|
||||
log.info("create MultiSig address");
|
||||
|
||||
log.info("Create deposit tx");
|
||||
|
||||
log.info("Sign deposit tx");
|
||||
|
||||
log.info("Send deposit Tx");
|
||||
//walletFacade.takerAddPaymentAndSign();
|
||||
// messageFacade.send(new Message(Message.REQUEST_OFFER_FEE_PAYMENT_CONFIRM, trade), trade.getOffer().getOfferer().getMessageID());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param trade
|
||||
*/
|
||||
// 6
|
||||
public void releaseBTC(Trade trade)
|
||||
{
|
||||
log.info("Sign payment tx");
|
||||
|
@ -174,5 +148,13 @@ public class Trading
|
|||
// messageFacade.send(new Message(Message.REQUEST_OFFER_FEE_PAYMENT_CONFIRM, trade), trade.getOffer().getOfferer().getMessageID());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public HashMap<String, Trade> getTrades()
|
||||
{
|
||||
return trades;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue