show signature status on transaction tab for loaded transactions when offline

This commit is contained in:
Craig Raw 2022-05-19 11:23:40 +02:00
parent 4b2b8f653a
commit 82be3a52dc
4 changed files with 64 additions and 17 deletions

View file

@ -1218,6 +1218,7 @@ public class HeadersController extends TransactionFormController implements Init
}
}
if(!event.getInputTransactions().isEmpty()) {
Long feeAmt = calculateFee(event.getInputTransactions());
if(feeAmt != null) {
updateFee(feeAmt);
@ -1230,6 +1231,7 @@ public class HeadersController extends TransactionFormController implements Init
transactionDiagram.update(getWalletTransaction(allFetchedInputTransactions));
}
}
}
@Subscribe
public void transactionFetchFailed(TransactionFetchFailedEvent event) {

View file

@ -513,7 +513,7 @@ public class InputController extends TransactionFormController implements Initia
@Subscribe
public void blockTransactionFetched(BlockTransactionFetchedEvent event) {
if(event.getTxId().equals(inputForm.getTransaction().getTxId()) && inputForm.getIndex() >= event.getPageStart() && inputForm.getIndex() < event.getPageEnd()) {
if(event.getTxId().equals(inputForm.getTransaction().getTxId()) && !event.getInputTransactions().isEmpty() && inputForm.getIndex() >= event.getPageStart() && inputForm.getIndex() < event.getPageEnd()) {
updateOutpoint(event.getInputTransactions());
if(inputForm.getPsbt() == null) {
updateSpends(event.getInputTransactions());

View file

@ -164,7 +164,7 @@ public class InputsController extends TransactionFormController implements Initi
@Subscribe
public void blockTransactionFetched(BlockTransactionFetchedEvent event) {
if(event.getTxId().equals(inputsForm.getTransaction().getTxId()) && inputsForm.getPsbt() == null) {
if(event.getTxId().equals(inputsForm.getTransaction().getTxId()) && !event.getInputTransactions().isEmpty() && inputsForm.getPsbt() == null) {
updateBlockTransactionInputs(event.getInputTransactions());
}
}

View file

@ -6,6 +6,7 @@ import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTInput;
import com.sparrowwallet.drongo.psbt.PSBTOutput;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.TransactionTabData;
@ -30,6 +31,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
public class TransactionController implements Initializable {
private static final Logger log = LoggerFactory.getLogger(TransactionController.class);
@ -57,6 +59,8 @@ public class TransactionController implements Initializable {
private int selectedInputIndex = -1;
private int selectedOutputIndex = -1;
private boolean transactionsFetched;
@Override
public void initialize(URL location, ResourceBundle resources) {
EventManager.get().register(this);
@ -68,6 +72,16 @@ public class TransactionController implements Initializable {
transactionMasterDetail.setShowDetailNode(Config.get().isShowTransactionHex());
txhex.setTransaction(getTransaction());
highlightTxHex();
fetchTransactions();
transactionMasterDetail.sceneProperty().addListener((observable, oldScene, newScene) -> {
if(oldScene == null && newScene != null) {
transactionMasterDetail.setDividerPosition(AppServices.isReducedWindowHeight(transactionMasterDetail) ? 0.9 : 0.82);
}
});
}
private void fetchTransactions() {
fetchThisAndInputBlockTransactions(0, Math.min(getTransaction().getInputs().size(), PageForm.PAGE_SIZE));
fetchOutputBlockTransactions(0, Math.min(getTransaction().getOutputs().size(), PageForm.PAGE_SIZE));
@ -76,12 +90,6 @@ public class TransactionController implements Initializable {
} else if(TransactionView.OUTPUT.equals(initialView) && initialIndex >= PageForm.PAGE_SIZE) {
fetchOutputBlockTransactions(initialIndex, initialIndex + 1);
}
transactionMasterDetail.sceneProperty().addListener((observable, oldScene, newScene) -> {
if(oldScene == null && newScene != null) {
transactionMasterDetail.setDividerPosition(AppServices.isReducedWindowHeight(transactionMasterDetail) ? 0.9 : 0.82);
}
});
}
private void initializeTxTree() {
@ -353,6 +361,7 @@ public class TransactionController implements Initializable {
ElectrumServer.TransactionReferenceService transactionReferenceService = new ElectrumServer.TransactionReferenceService(references);
transactionReferenceService.setOnSucceeded(successEvent -> {
transactionsFetched = true;
Map<Sha256Hash, BlockTransaction> transactionMap = transactionReferenceService.getValue();
BlockTransaction thisBlockTx = null;
Map<Sha256Hash, BlockTransaction> inputTransactions = new HashMap<>();
@ -387,6 +396,28 @@ public class TransactionController implements Initializable {
});
EventManager.get().post(new TransactionReferencesStartedEvent(getTransaction(), indexStart, maxIndex));
transactionReferenceService.start();
} else if(!AppServices.isConnected()) {
BlockTransaction blockTx = null;
Set<Sha256Hash> inputReferences = getTransaction().getInputs().stream().map(input -> input.getOutpoint().getHash()).collect(Collectors.toSet());
Map<Sha256Hash, BlockTransaction> inputTransactions = new HashMap<>();
for(Wallet wallet : AppServices.get().getOpenWallets().keySet()) {
Map<Sha256Hash, BlockTransaction> walletTransactions = wallet.getWalletTransactions();
if(blockTx == null && walletTransactions.get(getTransaction().getTxId()) != null) {
blockTx = walletTransactions.get(getTransaction().getTxId());
}
for(Sha256Hash inputReference : inputReferences) {
if(inputTransactions.get(inputReference) == null && walletTransactions.get(inputReference) != null) {
inputTransactions.put(inputReference, walletTransactions.get(inputReference));
}
}
}
if(inputTransactions.size() == inputReferences.size()) {
EventManager.get().post(new BlockTransactionFetchedEvent(getTransaction(), blockTx, inputTransactions, 0, getTransaction().getInputs().size()));
} else {
EventManager.get().post(new BlockTransactionFetchedEvent(getTransaction(), blockTx, Collections.emptyMap(), 0, getTransaction().getInputs().size()));
}
}
}
@ -500,7 +531,7 @@ public class TransactionController implements Initializable {
@Subscribe
public void blockTransactionFetched(BlockTransactionFetchedEvent event) {
if(event.getTxId().equals(getTransaction().getTxId())) {
if(event.getTxId().equals(getTransaction().getTxId()) && !event.getInputTransactions().isEmpty()) {
if(event.getBlockTransaction() != null && (!Sha256Hash.ZERO_HASH.equals(event.getBlockTransaction().getBlockHash()) || txdata.getBlockTransaction() == null)) {
txdata.setBlockTransaction(event.getBlockTransaction());
}
@ -547,4 +578,18 @@ public class TransactionController implements Initializable {
}
}
}
@Subscribe
public void newConnection(ConnectionEvent event) {
if(!transactionsFetched) {
fetchTransactions();
}
}
@Subscribe
public void openWallets(OpenWalletsEvent event) {
if(!transactionsFetched) {
fetchTransactions();
}
}
}