signature count updating on signed keystores list change

This commit is contained in:
Craig Raw 2020-07-23 14:15:22 +02:00
parent 1fd1b28994
commit 7d3aabb050
6 changed files with 96 additions and 72 deletions

2
drongo

@ -1 +1 @@
Subproject commit 8bc4e3b3dcf4c826d148aeafd556ecdbe8673939 Subproject commit 5cd203d3668d8e720244686433cbd44d614f0343

View file

@ -3,11 +3,11 @@ package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
public class FinalizePSBTEvent { public class FinalizeTransactionEvent {
private final PSBT psbt; private final PSBT psbt;
private final Wallet signingWallet; private final Wallet signingWallet;
public FinalizePSBTEvent(PSBT psbt, Wallet signingWallet) { public FinalizeTransactionEvent(PSBT psbt, Wallet signingWallet) {
this.psbt = psbt; this.psbt = psbt;
this.signingWallet = signingWallet; this.signingWallet = signingWallet;
} }

View file

@ -430,7 +430,7 @@ public class HeadersController extends TransactionFormController implements Init
} }
public void finalizeTransaction(ActionEvent event) { public void finalizeTransaction(ActionEvent event) {
EventManager.get().post(new FinalizePSBTEvent(headersForm.getPsbt(), signingWallet.getValue())); EventManager.get().post(new FinalizeTransactionEvent(headersForm.getPsbt(), signingWallet.getValue()));
} }
public void showPSBT(ActionEvent event) { public void showPSBT(ActionEvent event) {
@ -554,7 +554,7 @@ public class HeadersController extends TransactionFormController implements Init
} }
@Subscribe @Subscribe
public void finalizePSBT(FinalizePSBTEvent event) { public void finalizeTransaction(FinalizeTransactionEvent event) {
if(headersForm.getPsbt() == event.getPsbt()) { if(headersForm.getPsbt() == event.getPsbt()) {
version.setDisable(true); version.setDisable(true);
locktimeNoneType.setDisable(true); locktimeNoneType.setDisable(true);

View file

@ -7,9 +7,11 @@ import com.sparrowwallet.drongo.crypto.ECKey;
import com.sparrowwallet.drongo.protocol.*; import com.sparrowwallet.drongo.protocol.*;
import com.sparrowwallet.drongo.psbt.PSBTInput; import com.sparrowwallet.drongo.psbt.PSBTInput;
import com.sparrowwallet.drongo.wallet.BlockTransaction; import com.sparrowwallet.drongo.wallet.BlockTransaction;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.event.*;
import javafx.collections.ListChangeListener;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@ -130,6 +132,12 @@ public class InputController extends TransactionFormController implements Initia
initializeScriptFields(txInput, psbtInput); initializeScriptFields(txInput, psbtInput);
initializeStatusFields(txInput); initializeStatusFields(txInput);
initializeLocktimeFields(txInput); initializeLocktimeFields(txInput);
if(psbtInput != null) {
inputForm.getSignedKeystores().addListener((ListChangeListener<Keystore>) c -> {
updateSignatures();
});
}
} }
private void initializeInputFields(TransactionInput txInput, PSBTInput psbtInput) { private void initializeInputFields(TransactionInput txInput, PSBTInput psbtInput) {
@ -288,28 +296,7 @@ public class InputController extends TransactionFormController implements Initia
private void initializeStatusFields(TransactionInput txInput) { private void initializeStatusFields(TransactionInput txInput) {
Transaction transaction = inputForm.getTransaction(); Transaction transaction = inputForm.getTransaction();
signatures.setText("Unknown"); updateSignatures();
if(inputForm.getPsbtInput() != null) {
PSBTInput psbtInput = inputForm.getPsbtInput();
int reqSigs = -1;
if(psbtInput.getUtxo() != null && psbtInput.getSigningScript() != null) {
try {
reqSigs = psbtInput.getSigningScript().getNumRequiredSignatures();
} catch (NonStandardScriptException e) {
//TODO: Handle unusual transaction sig
}
}
int foundSigs = psbtInput.getPartialSignatures().size();
if(psbtInput.getFinalScriptWitness() != null) {
foundSigs = psbtInput.getFinalScriptWitness().getSignatures().size();
} else if(psbtInput.getFinalScriptSig() != null) {
foundSigs = psbtInput.getFinalScriptSig().getSignatures().size();
}
signatures.setText(foundSigs + "/" + (reqSigs < 0 ? "?" : reqSigs));
}
rbf.setSelected(txInput.isReplaceByFeeEnabled()); rbf.setSelected(txInput.isReplaceByFeeEnabled());
rbf.selectedProperty().addListener((observable, oldValue, newValue) -> { rbf.selectedProperty().addListener((observable, oldValue, newValue) -> {
@ -336,6 +323,31 @@ public class InputController extends TransactionFormController implements Initia
rbf.setDisable(!inputForm.isEditable()); rbf.setDisable(!inputForm.isEditable());
} }
private void updateSignatures() {
signatures.setText("Unknown");
if(inputForm.getPsbtInput() != null) {
PSBTInput psbtInput = inputForm.getPsbtInput();
int reqSigs = -1;
if(psbtInput.getUtxo() != null && psbtInput.getSigningScript() != null) {
try {
reqSigs = psbtInput.getSigningScript().getNumRequiredSignatures();
} catch (NonStandardScriptException e) {
//TODO: Handle unusual transaction sig
}
}
int foundSigs = psbtInput.getPartialSignatures().size();
if(psbtInput.getFinalScriptWitness() != null) {
foundSigs = psbtInput.getFinalScriptWitness().getSignatures().size();
} else if(psbtInput.getFinalScriptSig() != null) {
foundSigs = psbtInput.getFinalScriptSig().getSignatures().size();
}
signatures.setText(foundSigs + "/" + (reqSigs < 0 ? "?" : reqSigs));
}
}
private void initializeLocktimeFields(TransactionInput txInput) { private void initializeLocktimeFields(TransactionInput txInput) {
Transaction transaction = inputForm.getTransaction(); Transaction transaction = inputForm.getTransaction();
locktimeToggleGroup.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> { locktimeToggleGroup.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
@ -496,7 +508,7 @@ public class InputController extends TransactionFormController implements Initia
} }
@Subscribe @Subscribe
public void finalizePSBT(FinalizePSBTEvent event) { public void finalizeTransaction(FinalizeTransactionEvent event) {
if(inputForm.getPsbt() == event.getPsbt()) { if(inputForm.getPsbt() == event.getPsbt()) {
rbf.setDisable(true); rbf.setDisable(true);
locktimeNoneType.setDisable(true); locktimeNoneType.setDisable(true);

View file

@ -12,7 +12,7 @@ import java.io.IOException;
public class InputForm extends IndexedTransactionForm { public class InputForm extends IndexedTransactionForm {
private final TransactionInput transactionInput; private final TransactionInput transactionInput;
private PSBTInput psbtInput; private final PSBTInput psbtInput;
public InputForm(TransactionData txdata, PSBTInput psbtInput) { public InputForm(TransactionData txdata, PSBTInput psbtInput) {
super(txdata, txdata.getPsbt().getPsbtInputs().indexOf(psbtInput)); super(txdata, txdata.getPsbt().getPsbtInputs().indexOf(psbtInput));
@ -23,6 +23,7 @@ public class InputForm extends IndexedTransactionForm {
public InputForm(TransactionData txdata, TransactionInput transactionInput) { public InputForm(TransactionData txdata, TransactionInput transactionInput) {
super(txdata, txdata.getTransaction().getInputs().indexOf(transactionInput)); super(txdata, txdata.getTransaction().getInputs().indexOf(transactionInput));
this.transactionInput = transactionInput; this.transactionInput = transactionInput;
this.psbtInput = null;
} }
public TransactionInput getTransactionInput() { public TransactionInput getTransactionInput() {

View file

@ -2,13 +2,16 @@ package com.sparrowwallet.sparrow.transaction;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.protocol.*; import com.sparrowwallet.drongo.protocol.*;
import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTInput; import com.sparrowwallet.drongo.psbt.PSBTInput;
import com.sparrowwallet.drongo.wallet.BlockTransaction; import com.sparrowwallet.drongo.wallet.BlockTransaction;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CoinLabel; import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.event.BitcoinUnitChangedEvent; import com.sparrowwallet.sparrow.event.BitcoinUnitChangedEvent;
import com.sparrowwallet.sparrow.event.BlockTransactionFetchedEvent; import com.sparrowwallet.sparrow.event.BlockTransactionFetchedEvent;
import javafx.collections.ListChangeListener;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.chart.PieChart; import javafx.scene.chart.PieChart;
@ -51,54 +54,62 @@ public class InputsController extends TransactionFormController implements Initi
signatures.setText("Unknown"); signatures.setText("Unknown");
if(inputsForm.getPsbt() != null) { if(inputsForm.getPsbt() != null) {
int reqSigs = 0; updatePSBTInputs(inputsForm.getPsbt());
int foundSigs = 0; inputsForm.getSignedKeystores().addListener((ListChangeListener<Keystore>) c -> {
boolean showDenominator = true; updatePSBTInputs(inputsForm.getPsbt());
});
List<TransactionOutput> outputs = new ArrayList<>();
for(PSBTInput psbtInput : inputsForm.getPsbt().getPsbtInputs()) {
TransactionOutput output = psbtInput.getUtxo();
if(output != null) {
outputs.add(output);
}
if(psbtInput.getUtxo() != null && psbtInput.getSigningScript() != null) {
try {
reqSigs += psbtInput.getSigningScript().getNumRequiredSignatures();
} catch (NonStandardScriptException e) {
showDenominator = false;
//TODO: Handle unusual transaction sig
}
} else {
showDenominator = false;
}
if(psbtInput.getFinalScriptWitness() != null) {
foundSigs += psbtInput.getFinalScriptWitness().getSignatures().size();
} else if(psbtInput.getFinalScriptSig() != null) {
foundSigs += psbtInput.getFinalScriptSig().getSignatures().size();
} else {
foundSigs += psbtInput.getPartialSignatures().size();
}
}
long totalAmt = 0;
for(TransactionOutput output : outputs) {
totalAmt += output.getValue();
}
total.setValue(totalAmt);
if(showDenominator) {
signatures.setText(foundSigs + "/" + reqSigs);
} else {
signatures.setText(foundSigs + "/?");
}
addPieData(inputsPie, outputs);
} else if(inputsForm.getInputTransactions() != null) { } else if(inputsForm.getInputTransactions() != null) {
updateBlockTransactionInputs(inputsForm.getInputTransactions()); updateBlockTransactionInputs(inputsForm.getInputTransactions());
} }
} }
private void updatePSBTInputs(PSBT psbt) {
int reqSigs = 0;
int foundSigs = 0;
boolean showDenominator = true;
List<TransactionOutput> outputs = new ArrayList<>();
for(PSBTInput psbtInput : psbt.getPsbtInputs()) {
TransactionOutput output = psbtInput.getUtxo();
if(output != null) {
outputs.add(output);
}
if(psbtInput.getUtxo() != null && psbtInput.getSigningScript() != null) {
try {
reqSigs += psbtInput.getSigningScript().getNumRequiredSignatures();
} catch (NonStandardScriptException e) {
showDenominator = false;
//TODO: Handle unusual transaction sig
}
} else {
showDenominator = false;
}
if(psbtInput.getFinalScriptWitness() != null) {
foundSigs += psbtInput.getFinalScriptWitness().getSignatures().size();
} else if(psbtInput.getFinalScriptSig() != null) {
foundSigs += psbtInput.getFinalScriptSig().getSignatures().size();
} else {
foundSigs += psbtInput.getPartialSignatures().size();
}
}
long totalAmt = 0;
for(TransactionOutput output : outputs) {
totalAmt += output.getValue();
}
total.setValue(totalAmt);
if(showDenominator) {
signatures.setText(foundSigs + "/" + reqSigs);
} else {
signatures.setText(foundSigs + "/?");
}
addPieData(inputsPie, outputs);
}
private void updateBlockTransactionInputs(Map<Sha256Hash, BlockTransaction> inputTransactions) { private void updateBlockTransactionInputs(Map<Sha256Hash, BlockTransaction> inputTransactions) {
List<TransactionOutput> outputs = new ArrayList<>(); List<TransactionOutput> outputs = new ArrayList<>();