use of com.sparrowwallet.drongo.wallet.BlockTransaction in project sparrow by sparrowwallet.
the class InputController method updateSpends.
private void updateSpends(Map<Sha256Hash, BlockTransaction> inputTransactions) {
TransactionInput txInput = inputForm.getTransactionInput();
if (!txInput.isCoinBase()) {
BlockTransaction blockTransaction = inputTransactions.get(txInput.getOutpoint().getHash());
if (blockTransaction == null) {
if (inputForm.getIndex() < inputForm.getMaxInputFetched()) {
throw new IllegalStateException("Could not retrieve block transaction for input #" + inputForm.getIndex());
} else {
// Still paging
return;
}
}
TransactionOutput output = blockTransaction.getTransaction().getOutputs().get((int) txInput.getOutpoint().getIndex());
updateSpends(output);
}
}
use of com.sparrowwallet.drongo.wallet.BlockTransaction in project sparrow by sparrowwallet.
the class InputController method updateOutpoint.
private void updateOutpoint(Map<Sha256Hash, BlockTransaction> inputTransactions) {
outpoint.setVisible(false);
linkedOutpoint.setVisible(true);
TransactionInput txInput = inputForm.getTransactionInput();
linkedOutpoint.setText(txInput.getOutpoint().getHash().toString() + ":" + txInput.getOutpoint().getIndex());
linkedOutpoint.setOnAction(event -> {
BlockTransaction linkedTransaction = inputTransactions.get(txInput.getOutpoint().getHash());
EventManager.get().post(new ViewTransactionEvent(linkedOutpoint.getScene().getWindow(), linkedTransaction, TransactionView.OUTPUT, (int) txInput.getOutpoint().getIndex()));
});
linkedOutpoint.setContextMenu(new TransactionReferenceContextMenu(linkedOutpoint.getText()));
}
use of com.sparrowwallet.drongo.wallet.BlockTransaction in project sparrow by sparrowwallet.
the class OutputController method updateSpent.
private void updateSpent(List<BlockTransaction> outputTransactions) {
int outputIndex = outputForm.getIndex();
if (outputIndex < outputForm.getMaxOutputFetched()) {
spent.setText("Unspent");
} else {
spent.setText("Unknown");
}
if (outputIndex >= 0 && outputIndex < outputTransactions.size()) {
BlockTransaction outputBlockTransaction = outputTransactions.get(outputIndex);
if (outputBlockTransaction != null) {
spent.setText("Spent");
if (outputBlockTransaction == ElectrumServer.UNFETCHABLE_BLOCK_TRANSACTION) {
spent.setText("Spent (Spending transaction history too large to fetch)");
return;
}
for (int i = 0; i < outputBlockTransaction.getTransaction().getInputs().size(); i++) {
TransactionInput input = outputBlockTransaction.getTransaction().getInputs().get(i);
if (input.getOutpoint().getHash().equals(outputForm.getTransaction().getTxId()) && input.getOutpoint().getIndex() == outputIndex) {
spentField.setVisible(false);
spentByField.setVisible(true);
final Integer inputIndex = i;
spentBy.setText(outputBlockTransaction.getHash().toString() + ":" + inputIndex);
spentBy.setOnAction(event -> {
EventManager.get().post(new ViewTransactionEvent(spentBy.getScene().getWindow(), outputBlockTransaction, TransactionView.INPUT, inputIndex));
});
spentBy.setContextMenu(new TransactionReferenceContextMenu(spentBy.getText()));
}
}
}
}
}
use of com.sparrowwallet.drongo.wallet.BlockTransaction in project sparrow by sparrowwallet.
the class InputsController method updateBlockTransactionInputs.
private void updateBlockTransactionInputs(Map<Sha256Hash, BlockTransaction> inputTransactions) {
List<TransactionOutput> outputs = new ArrayList<>();
int foundSigs = 0;
for (TransactionInput input : inputsForm.getTransaction().getInputs()) {
if (input.hasWitness()) {
foundSigs += input.getWitness().getSignatures().size();
} else {
foundSigs += input.getScriptSig().getSignatures().size();
}
if (input.isCoinBase()) {
long totalAmt = 0;
for (TransactionOutput output : inputsForm.getTransaction().getOutputs()) {
totalAmt += output.getValue();
}
total.setValue(totalAmt);
signatures.setText("N/A");
addCoinbasePieData(inputsPie, totalAmt);
return;
} else {
BlockTransaction inputTx = inputTransactions.get(input.getOutpoint().getHash());
if (inputTx == null) {
inputTx = inputsForm.getInputTransactions().get(input.getOutpoint().getHash());
}
if (inputTx == null) {
if (inputsForm.allInputsFetched()) {
throw new IllegalStateException("Cannot find transaction for hash " + input.getOutpoint().getHash());
} else {
// Still paging
total.setText("Unknown (" + inputsForm.getMaxInputFetched() + " of " + inputsForm.getTransaction().getInputs().size() + " inputs fetched)");
return;
}
}
TransactionOutput output = inputTx.getTransaction().getOutputs().get((int) input.getOutpoint().getIndex());
outputs.add(output);
}
}
long totalAmt = 0;
for (TransactionOutput output : outputs) {
totalAmt += output.getValue();
}
total.setValue(totalAmt);
// TODO: Find signing script and get required num sigs
signatures.setText(foundSigs + "/" + foundSigs);
addPieData(inputsPie, outputs);
}
use of com.sparrowwallet.drongo.wallet.BlockTransaction in project sparrow by sparrowwallet.
the class TransactionController method fetchThisAndInputBlockTransactions.
private void fetchThisAndInputBlockTransactions(int indexStart, int indexEnd) {
if (AppServices.isConnected() && indexStart < getTransaction().getInputs().size()) {
Set<Sha256Hash> references = new HashSet<>();
if (getPSBT() == null) {
references.add(getTransaction().getTxId());
}
int maxIndex = Math.min(getTransaction().getInputs().size(), indexEnd);
for (int i = indexStart; i < maxIndex; i++) {
TransactionInput input = getTransaction().getInputs().get(i);
if (!input.isCoinBase()) {
references.add(input.getOutpoint().getHash());
}
}
if (references.isEmpty()) {
return;
}
ElectrumServer.TransactionReferenceService transactionReferenceService = new ElectrumServer.TransactionReferenceService(references);
transactionReferenceService.setOnSucceeded(successEvent -> {
Map<Sha256Hash, BlockTransaction> transactionMap = transactionReferenceService.getValue();
BlockTransaction thisBlockTx = null;
Map<Sha256Hash, BlockTransaction> inputTransactions = new HashMap<>();
for (Sha256Hash txid : transactionMap.keySet()) {
BlockTransaction blockTx = transactionMap.get(txid);
if (txid.equals(getTransaction().getTxId())) {
thisBlockTx = blockTx;
} else {
inputTransactions.put(txid, blockTx);
references.remove(txid);
}
}
references.remove(getTransaction().getTxId());
if (!references.isEmpty()) {
log.warn("Failed to retrieve all referenced input transactions, aborting transaction fetch");
return;
}
final BlockTransaction blockTx = thisBlockTx;
Platform.runLater(() -> {
EventManager.get().post(new BlockTransactionFetchedEvent(getTransaction(), blockTx, inputTransactions, indexStart, maxIndex));
});
});
transactionReferenceService.setOnFailed(failedEvent -> {
log.error("Error fetching transaction or input references", failedEvent.getSource().getException());
EventManager.get().post(new TransactionReferencesFailedEvent(getTransaction(), failedEvent.getSource().getException(), indexStart, maxIndex));
});
EventManager.get().post(new TransactionReferencesStartedEvent(getTransaction(), indexStart, maxIndex));
transactionReferenceService.start();
}
}
Aggregations