Search in sources :

Example 1 with SorobanCahootsService

use of com.samourai.soroban.client.cahoots.SorobanCahootsService in project sparrow by sparrowwallet.

the class Soroban method getSorobanCahootsService.

public SorobanCahootsService getSorobanCahootsService(CahootsWallet cahootsWallet) {
    IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST);
    RpcClient rpcClient = new RpcClient(httpClient, httpClientService.getTorProxy() != null, sorobanServer.getParams());
    return new SorobanCahootsService(bip47Util, PROVIDER_JAVA, cahootsWallet, rpcClient);
}
Also used : IHttpClient(com.samourai.http.client.IHttpClient) SorobanCahootsService(com.samourai.soroban.client.cahoots.SorobanCahootsService) RpcClient(com.samourai.soroban.client.rpc.RpcClient)

Example 2 with SorobanCahootsService

use of com.samourai.soroban.client.cahoots.SorobanCahootsService in project sparrow by sparrowwallet.

the class CounterpartyController method startCounterpartyMeetingReceive.

private void startCounterpartyMeetingReceive() {
    Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId);
    SparrowCahootsWallet counterpartyCahootsWallet = soroban.getCahootsWallet(wallet, 1);
    try {
        SorobanCahootsService sorobanMeetingService = soroban.getSorobanCahootsService(counterpartyCahootsWallet);
        sorobanMeetingService.receiveMeetingRequest(TIMEOUT_MS).subscribeOn(Schedulers.io()).observeOn(JavaFxScheduler.platform()).subscribe(requestMessage -> {
            String code = requestMessage.getSender();
            CahootsType cahootsType = requestMessage.getType();
            PaymentCode paymentCodeInitiator = new PaymentCode(code);
            updateMixPartner(paymentCodeInitiator, cahootsType);
            Boolean accepted = (Boolean) Platform.enterNestedEventLoop(meetingAccepted);
            sorobanMeetingService.sendMeetingResponse(paymentCodeInitiator, requestMessage, accepted).subscribeOn(Schedulers.io()).observeOn(JavaFxScheduler.platform()).subscribe(responseMessage -> {
                if (accepted) {
                    startCounterpartyCollaboration(counterpartyCahootsWallet, paymentCodeInitiator, cahootsType);
                    followPaymentCode(paymentCodeInitiator);
                }
            }, error -> {
                log.error("Error sending meeting response", error);
                mixingPartner.setVisible(false);
            });
        }, error -> {
            log.error("Failed to receive meeting request", error);
            mixingPartner.setVisible(false);
        });
    } catch (Exception e) {
        log.error("Error sending meeting response", e);
    }
}
Also used : PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) CahootsType(com.samourai.wallet.cahoots.CahootsType) SorobanCahootsService(com.samourai.soroban.client.cahoots.SorobanCahootsService) PSBTParseException(com.sparrowwallet.drongo.psbt.PSBTParseException)

Example 3 with SorobanCahootsService

use of com.samourai.soroban.client.cahoots.SorobanCahootsService in project sparrow by sparrowwallet.

the class CounterpartyController method startCounterpartyCollaboration.

private void startCounterpartyCollaboration(SparrowCahootsWallet counterpartyCahootsWallet, PaymentCode initiatorPaymentCode, CahootsType cahootsType) {
    sorobanProgressLabel.setText("Creating mix transaction...");
    Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId);
    Map<BlockTransactionHashIndex, WalletNode> walletUtxos = wallet.getWalletUtxos();
    for (Map.Entry<BlockTransactionHashIndex, WalletNode> entry : walletUtxos.entrySet()) {
        if (entry.getKey().getStatus() != Status.FROZEN) {
            counterpartyCahootsWallet.addUtxo(entry.getValue(), wallet.getWalletTransaction(entry.getKey().getHash()), (int) entry.getKey().getIndex());
        }
    }
    try {
        SorobanCahootsService sorobanCahootsService = soroban.getSorobanCahootsService(counterpartyCahootsWallet);
        CahootsContext cahootsContext = cahootsType == CahootsType.STONEWALLX2 ? CahootsContext.newCounterpartyStonewallx2() : CahootsContext.newCounterpartyStowaway();
        sorobanCahootsService.contributor(counterpartyCahootsWallet.getAccount(), cahootsContext, initiatorPaymentCode, TIMEOUT_MS).subscribeOn(Schedulers.io()).observeOn(JavaFxScheduler.platform()).subscribe(sorobanMessage -> {
            OnlineCahootsMessage cahootsMessage = (OnlineCahootsMessage) sorobanMessage;
            if (cahootsMessage != null) {
                Cahoots cahoots = cahootsMessage.getCahoots();
                sorobanProgressBar.setProgress((double) (cahoots.getStep() + 1) / 5);
                if (cahoots.getStep() == 3) {
                    sorobanProgressLabel.setText("Your mix partner is reviewing the transaction...");
                    step3Timer.start();
                } else if (cahoots.getStep() >= 4) {
                    try {
                        Transaction transaction = getTransaction(cahoots);
                        if (transaction != null) {
                            transactionProperty.set(transaction);
                            updateTransactionDiagram(transactionDiagram, wallet, null, transaction);
                            next();
                        }
                    } catch (PSBTParseException e) {
                        log.error("Invalid collaborative PSBT created", e);
                        step3Desc.setText("Invalid transaction created.");
                        sorobanProgressLabel.setVisible(false);
                    }
                }
            }
        }, error -> {
            log.error("Error creating mix transaction", error);
            String cutFrom = "Exception: ";
            int index = error.getMessage().lastIndexOf(cutFrom);
            String msg = index < 0 ? error.getMessage() : error.getMessage().substring(index + cutFrom.length());
            msg = msg.replace("#Cahoots", "mix transaction");
            step3Desc.setText(msg);
            sorobanProgressLabel.setVisible(false);
        });
    } catch (Exception e) {
        log.error("Error creating mix transaction", e);
        sorobanProgressLabel.setText(e.getMessage());
    }
}
Also used : BlockTransactionHashIndex(com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex) PSBTParseException(com.sparrowwallet.drongo.psbt.PSBTParseException) CahootsContext(com.samourai.soroban.cahoots.CahootsContext) Transaction(com.sparrowwallet.drongo.protocol.Transaction) OnlineCahootsMessage(com.samourai.soroban.client.cahoots.OnlineCahootsMessage) SorobanCahootsService(com.samourai.soroban.client.cahoots.SorobanCahootsService) PSBTParseException(com.sparrowwallet.drongo.psbt.PSBTParseException) Cahoots(com.samourai.wallet.cahoots.Cahoots) HashMap(java.util.HashMap) Map(java.util.Map) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Aggregations

SorobanCahootsService (com.samourai.soroban.client.cahoots.SorobanCahootsService)3 PSBTParseException (com.sparrowwallet.drongo.psbt.PSBTParseException)2 IHttpClient (com.samourai.http.client.IHttpClient)1 CahootsContext (com.samourai.soroban.cahoots.CahootsContext)1 OnlineCahootsMessage (com.samourai.soroban.client.cahoots.OnlineCahootsMessage)1 RpcClient (com.samourai.soroban.client.rpc.RpcClient)1 PaymentCode (com.samourai.wallet.bip47.rpc.PaymentCode)1 Cahoots (com.samourai.wallet.cahoots.Cahoots)1 CahootsType (com.samourai.wallet.cahoots.CahootsType)1 Transaction (com.sparrowwallet.drongo.protocol.Transaction)1 BlockTransactionHashIndex (com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex)1 WalletNode (com.sparrowwallet.drongo.wallet.WalletNode)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1