mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-23 20:36:44 +00:00
signature count updating on signed keystores list change
This commit is contained in:
parent
1fd1b28994
commit
7d3aabb050
6 changed files with 96 additions and 72 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
|||
Subproject commit 8bc4e3b3dcf4c826d148aeafd556ecdbe8673939
|
||||
Subproject commit 5cd203d3668d8e720244686433cbd44d614f0343
|
|
@ -3,11 +3,11 @@ package com.sparrowwallet.sparrow.event;
|
|||
import com.sparrowwallet.drongo.psbt.PSBT;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
|
||||
public class FinalizePSBTEvent {
|
||||
public class FinalizeTransactionEvent {
|
||||
private final PSBT psbt;
|
||||
private final Wallet signingWallet;
|
||||
|
||||
public FinalizePSBTEvent(PSBT psbt, Wallet signingWallet) {
|
||||
public FinalizeTransactionEvent(PSBT psbt, Wallet signingWallet) {
|
||||
this.psbt = psbt;
|
||||
this.signingWallet = signingWallet;
|
||||
}
|
||||
|
|
|
@ -430,7 +430,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -554,7 +554,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void finalizePSBT(FinalizePSBTEvent event) {
|
||||
public void finalizeTransaction(FinalizeTransactionEvent event) {
|
||||
if(headersForm.getPsbt() == event.getPsbt()) {
|
||||
version.setDisable(true);
|
||||
locktimeNoneType.setDisable(true);
|
||||
|
|
|
@ -7,9 +7,11 @@ import com.sparrowwallet.drongo.crypto.ECKey;
|
|||
import com.sparrowwallet.drongo.protocol.*;
|
||||
import com.sparrowwallet.drongo.psbt.PSBTInput;
|
||||
import com.sparrowwallet.drongo.wallet.BlockTransaction;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.*;
|
||||
import com.sparrowwallet.sparrow.event.*;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.geometry.Pos;
|
||||
|
@ -130,6 +132,12 @@ public class InputController extends TransactionFormController implements Initia
|
|||
initializeScriptFields(txInput, psbtInput);
|
||||
initializeStatusFields(txInput);
|
||||
initializeLocktimeFields(txInput);
|
||||
|
||||
if(psbtInput != null) {
|
||||
inputForm.getSignedKeystores().addListener((ListChangeListener<Keystore>) c -> {
|
||||
updateSignatures();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeInputFields(TransactionInput txInput, PSBTInput psbtInput) {
|
||||
|
@ -288,28 +296,7 @@ public class InputController extends TransactionFormController implements Initia
|
|||
private void initializeStatusFields(TransactionInput txInput) {
|
||||
Transaction transaction = inputForm.getTransaction();
|
||||
|
||||
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));
|
||||
}
|
||||
updateSignatures();
|
||||
|
||||
rbf.setSelected(txInput.isReplaceByFeeEnabled());
|
||||
rbf.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
|
@ -336,6 +323,31 @@ public class InputController extends TransactionFormController implements Initia
|
|||
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) {
|
||||
Transaction transaction = inputForm.getTransaction();
|
||||
locktimeToggleGroup.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
|
||||
|
@ -496,7 +508,7 @@ public class InputController extends TransactionFormController implements Initia
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void finalizePSBT(FinalizePSBTEvent event) {
|
||||
public void finalizeTransaction(FinalizeTransactionEvent event) {
|
||||
if(inputForm.getPsbt() == event.getPsbt()) {
|
||||
rbf.setDisable(true);
|
||||
locktimeNoneType.setDisable(true);
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.io.IOException;
|
|||
|
||||
public class InputForm extends IndexedTransactionForm {
|
||||
private final TransactionInput transactionInput;
|
||||
private PSBTInput psbtInput;
|
||||
private final PSBTInput psbtInput;
|
||||
|
||||
public InputForm(TransactionData txdata, PSBTInput psbtInput) {
|
||||
super(txdata, txdata.getPsbt().getPsbtInputs().indexOf(psbtInput));
|
||||
|
@ -23,6 +23,7 @@ public class InputForm extends IndexedTransactionForm {
|
|||
public InputForm(TransactionData txdata, TransactionInput transactionInput) {
|
||||
super(txdata, txdata.getTransaction().getInputs().indexOf(transactionInput));
|
||||
this.transactionInput = transactionInput;
|
||||
this.psbtInput = null;
|
||||
}
|
||||
|
||||
public TransactionInput getTransactionInput() {
|
||||
|
|
|
@ -2,13 +2,16 @@ package com.sparrowwallet.sparrow.transaction;
|
|||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.sparrowwallet.drongo.protocol.*;
|
||||
import com.sparrowwallet.drongo.psbt.PSBT;
|
||||
import com.sparrowwallet.drongo.psbt.PSBTInput;
|
||||
import com.sparrowwallet.drongo.wallet.BlockTransaction;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.CoinLabel;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import com.sparrowwallet.sparrow.event.BitcoinUnitChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.BlockTransactionFetchedEvent;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.chart.PieChart;
|
||||
|
@ -51,54 +54,62 @@ public class InputsController extends TransactionFormController implements Initi
|
|||
signatures.setText("Unknown");
|
||||
|
||||
if(inputsForm.getPsbt() != null) {
|
||||
int reqSigs = 0;
|
||||
int foundSigs = 0;
|
||||
boolean showDenominator = true;
|
||||
|
||||
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);
|
||||
updatePSBTInputs(inputsForm.getPsbt());
|
||||
inputsForm.getSignedKeystores().addListener((ListChangeListener<Keystore>) c -> {
|
||||
updatePSBTInputs(inputsForm.getPsbt());
|
||||
});
|
||||
} else if(inputsForm.getInputTransactions() != null) {
|
||||
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) {
|
||||
List<TransactionOutput> outputs = new ArrayList<>();
|
||||
|
||||
|
|
Loading…
Reference in a new issue