Search in sources :

Example 1 with WalletNode

use of com.sparrowwallet.drongo.wallet.WalletNode in project sparrow by sparrowwallet.

the class WalletNodeHistoryChangedEvent method getWalletNode.

public WalletNode getWalletNode(Wallet wallet) {
    WalletNode changedNode = getNode(wallet);
    if (changedNode != null) {
        return changedNode;
    }
    for (Wallet childWallet : wallet.getChildWallets()) {
        if (childWallet.isNested()) {
            changedNode = getNode(childWallet);
            if (changedNode != null) {
                return changedNode;
            }
        }
    }
    Wallet notificationWallet = wallet.getNotificationWallet();
    if (notificationWallet != null) {
        WalletNode notificationNode = notificationWallet.getNode(KeyPurpose.NOTIFICATION);
        if (ElectrumServer.getScriptHash(notificationWallet, notificationNode).equals(scriptHash)) {
            return notificationNode;
        }
    }
    return null;
}
Also used : Wallet(com.sparrowwallet.drongo.wallet.Wallet) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Example 2 with WalletNode

use of com.sparrowwallet.drongo.wallet.WalletNode in project sparrow by sparrowwallet.

the class WalletNodeDao method addWalletNodes.

default void addWalletNodes(Wallet wallet) {
    for (WalletNode purposeNode : wallet.getPurposeNodes()) {
        long purposeNodeId = insertWalletNode(purposeNode.getDerivationPath(), truncate(purposeNode.getLabel()), wallet.getId(), null);
        purposeNode.setId(purposeNodeId);
        addTransactionOutputs(purposeNode);
        List<WalletNode> childNodes = new ArrayList<>(purposeNode.getChildren());
        for (WalletNode addressNode : childNodes) {
            long addressNodeId = insertWalletNode(addressNode.getDerivationPath(), truncate(addressNode.getLabel()), wallet.getId(), purposeNodeId);
            addressNode.setId(addressNodeId);
            addTransactionOutputs(addressNode);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Example 3 with WalletNode

use of com.sparrowwallet.drongo.wallet.WalletNode in project sparrow by sparrowwallet.

the class WalletNodeMapper method map.

@Override
public WalletNode map(ResultSet rs, StatementContext ctx) throws SQLException {
    WalletNode walletNode = new WalletNode(rs.getString("walletNode.derivationPath"));
    walletNode.setId(rs.getLong("walletNode.id"));
    walletNode.setLabel(rs.getString("walletNode.label"));
    return walletNode;
}
Also used : WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Example 4 with WalletNode

use of com.sparrowwallet.drongo.wallet.WalletNode in project sparrow by sparrowwallet.

the class WalletNodeReducer method accumulate.

@Override
public void accumulate(Map<Long, WalletNode> map, RowView rowView) {
    WalletNode walletNode = map.computeIfAbsent(rowView.getColumn("walletNode.id", Long.class), id -> rowView.getRow(WalletNode.class));
    if (rowView.getColumn("walletNode.parent", Long.class) != null) {
        WalletNode parentNode = map.get(rowView.getColumn("walletNode.parent", Long.class));
        parentNode.getChildren().add(walletNode);
    }
    if (rowView.getColumn("blockTransactionHashIndex.node", Long.class) != null) {
        BlockTransactionHashIndex blockTransactionHashIndex = rowView.getRow(BlockTransactionHashIndex.class);
        if (rowView.getColumn("blockTransactionHashIndex.spentBy", Long.class) != null) {
            BlockTransactionHashIndex spentBy = walletNode.getTransactionOutputs().stream().filter(ref -> ref.getId().equals(rowView.getColumn("blockTransactionHashIndex.spentBy", Long.class))).findFirst().orElseThrow();
            blockTransactionHashIndex.setSpentBy(spentBy);
            walletNode.getTransactionOutputs().remove(spentBy);
        }
        walletNode.getTransactionOutputs().add(blockTransactionHashIndex);
    }
}
Also used : BlockTransactionHashIndex(com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Example 5 with WalletNode

use of com.sparrowwallet.drongo.wallet.WalletNode in project sparrow by sparrowwallet.

the class TransactionData method getSigningWalletNodes.

public Set<WalletNode> getSigningWalletNodes() {
    if (getSigningWallet() == null) {
        throw new IllegalStateException("Signing wallet cannot be null");
    }
    Set<WalletNode> signingWalletNodes = new LinkedHashSet<>();
    for (TransactionInput txInput : transaction.getInputs()) {
        Optional<WalletNode> optNode = getSigningWallet().getWalletTxos().entrySet().stream().filter(entry -> entry.getKey().getHash().equals(txInput.getOutpoint().getHash()) && entry.getKey().getIndex() == txInput.getOutpoint().getIndex()).map(Map.Entry::getValue).findFirst();
        optNode.ifPresent(signingWalletNodes::add);
    }
    for (TransactionOutput txOutput : transaction.getOutputs()) {
        WalletNode changeNode = getSigningWallet().getWalletOutputScripts(KeyPurpose.CHANGE).get(txOutput.getScript());
        if (changeNode != null) {
            signingWalletNodes.add(changeNode);
        } else {
            WalletNode receiveNode = getSigningWallet().getWalletOutputScripts(KeyPurpose.RECEIVE).get(txOutput.getScript());
            if (receiveNode != null) {
                signingWalletNodes.add(receiveNode);
            }
        }
    }
    return signingWalletNodes;
}
Also used : ObservableMap(javafx.collections.ObservableMap) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Aggregations

WalletNode (com.sparrowwallet.drongo.wallet.WalletNode)10 BlockTransactionHashIndex (com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex)3 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)2 Wallet (com.sparrowwallet.drongo.wallet.Wallet)2 AppServices (com.sparrowwallet.sparrow.AppServices)2 EventManager (com.sparrowwallet.sparrow.EventManager)2 List (java.util.List)2 Optional (java.util.Optional)2 CsvWriter (com.csvreader.CsvWriter)1 Subscribe (com.google.common.eventbus.Subscribe)1 CahootsContext (com.samourai.soroban.cahoots.CahootsContext)1 OnlineCahootsMessage (com.samourai.soroban.client.cahoots.OnlineCahootsMessage)1 SorobanCahootsService (com.samourai.soroban.client.cahoots.SorobanCahootsService)1 Cahoots (com.samourai.wallet.cahoots.Cahoots)1 MixDestination (com.samourai.whirlpool.client.mix.handler.MixDestination)1 Address (com.sparrowwallet.drongo.address.Address)1 Transaction (com.sparrowwallet.drongo.protocol.Transaction)1 PSBTParseException (com.sparrowwallet.drongo.psbt.PSBTParseException)1 BlockTransaction (com.sparrowwallet.drongo.wallet.BlockTransaction)1 AddressTreeTable (com.sparrowwallet.sparrow.control.AddressTreeTable)1