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;
}
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);
}
}
}
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;
}
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);
}
}
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;
}
Aggregations