mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
various fixes, better non-electrumx support
This commit is contained in:
parent
2b48b4cd6e
commit
c814b8e350
15 changed files with 93 additions and 33 deletions
|
@ -118,7 +118,7 @@ jlink {
|
|||
jpackage {
|
||||
imageName = "Sparrow"
|
||||
installerName = "Sparrow"
|
||||
appVersion = "0.6"
|
||||
appVersion = "0.9.1"
|
||||
skipInstaller = true
|
||||
imageOptions = []
|
||||
installerOptions = [
|
||||
|
|
2
drongo
2
drongo
|
@ -1 +1 @@
|
|||
Subproject commit 5d456a10df1375b41e6159efc540b3d90cfbfc4d
|
||||
Subproject commit 446eac3483229fc4c798e82f367ca9d8f797d16e
|
|
@ -54,7 +54,7 @@ public class ConfirmationProgressIndicator extends StackPane {
|
|||
arcLengthTimeline.getKeyFrames().add(arcLengthFrame);
|
||||
sequence.getChildren().add(arcLengthTimeline);
|
||||
|
||||
if(newValue.intValue() == BlockTransactionHash.BLOCKS_TO_CONFIRM) {
|
||||
if(newValue.intValue() >= BlockTransactionHash.BLOCKS_TO_CONFIRM) {
|
||||
Timeline arcRadiusTimeline = new Timeline();
|
||||
KeyValue arcRadiusXValue = new KeyValue(arc.radiusXProperty(), 0.0);
|
||||
KeyValue arcRadiusYValue = new KeyValue(arc.radiusYProperty(), 0.0);
|
||||
|
|
|
@ -63,7 +63,7 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
|||
}
|
||||
|
||||
public MnemonicKeystoreImportPane(Keystore keystore) {
|
||||
super(keystore.getSeed().getType().getName(), keystore.getSeed().needsPassphrase() ? "Passphrase enabled" : "Passphrase disabled", "", "image/" + WalletModel.SEED + ".png");
|
||||
super(keystore.getSeed().getType().getName(), keystore.getSeed().needsPassphrase() ? "Passphrase enabled" : "Passphrase disabled", "", "image/" + WalletModel.SEED.getType() + ".png");
|
||||
this.wallet = null;
|
||||
this.importer = null;
|
||||
showHideLink.setVisible(false);
|
||||
|
|
|
@ -40,4 +40,8 @@ public class WalletNodeHistoryChangedEvent {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getScriptHash() {
|
||||
return scriptHash;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ public class BatchedElectrumServerRpc implements ElectrumServerRpc {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, VerboseTransaction> getVerboseTransactions(Transport transport, Set<String> txids) {
|
||||
public Map<String, VerboseTransaction> getVerboseTransactions(Transport transport, Set<String> txids, String scriptHash) {
|
||||
JsonRpcClient client = new JsonRpcClient(transport);
|
||||
BatchRequestBuilder<String, VerboseTransaction> batchRequest = client.createBatchRequest().keysType(String.class).returnType(VerboseTransaction.class);
|
||||
for(String txid : txids) {
|
||||
|
|
|
@ -479,13 +479,13 @@ public class ElectrumServer {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<Sha256Hash, BlockTransaction> getReferencedTransactions(Set<Sha256Hash> references) throws ServerException {
|
||||
public Map<Sha256Hash, BlockTransaction> getReferencedTransactions(Set<Sha256Hash> references, String scriptHash) throws ServerException {
|
||||
Set<String> txids = new LinkedHashSet<>(references.size());
|
||||
for(Sha256Hash reference : references) {
|
||||
txids.add(reference.toString());
|
||||
}
|
||||
|
||||
Map<String, VerboseTransaction> result = electrumServerRpc.getVerboseTransactions(getTransport(), txids);
|
||||
Map<String, VerboseTransaction> result = electrumServerRpc.getVerboseTransactions(getTransport(), txids, scriptHash);
|
||||
|
||||
Map<Sha256Hash, BlockTransaction> transactionMap = new HashMap<>();
|
||||
for(String txid : result.keySet()) {
|
||||
|
@ -715,6 +715,7 @@ public class ElectrumServer {
|
|||
|
||||
public static class TransactionReferenceService extends Service<Map<Sha256Hash, BlockTransaction>> {
|
||||
private final Set<Sha256Hash> references;
|
||||
private String scriptHash;
|
||||
|
||||
public TransactionReferenceService(Transaction transaction) {
|
||||
references = new HashSet<>();
|
||||
|
@ -724,6 +725,11 @@ public class ElectrumServer {
|
|||
}
|
||||
}
|
||||
|
||||
public TransactionReferenceService(Set<Sha256Hash> references, String scriptHash) {
|
||||
this(references);
|
||||
this.scriptHash = scriptHash;
|
||||
}
|
||||
|
||||
public TransactionReferenceService(Set<Sha256Hash> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
@ -733,7 +739,7 @@ public class ElectrumServer {
|
|||
return new Task<>() {
|
||||
protected Map<Sha256Hash, BlockTransaction> call() throws ServerException {
|
||||
ElectrumServer electrumServer = new ElectrumServer();
|
||||
return electrumServer.getReferencedTransactions(references);
|
||||
return electrumServer.getReferencedTransactions(references, scriptHash);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public interface ElectrumServerRpc {
|
|||
|
||||
Map<String, String> getTransactions(Transport transport, Set<String> txids);
|
||||
|
||||
Map<String, VerboseTransaction> getVerboseTransactions(Transport transport, Set<String> txids);
|
||||
Map<String, VerboseTransaction> getVerboseTransactions(Transport transport, Set<String> txids, String scriptHash);
|
||||
|
||||
Map<Integer, Double> getFeeEstimates(Transport transport, List<Integer> targetBlocks);
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import com.github.arteam.simplejsonrpc.client.JsonRpcClient;
|
||||
import com.github.arteam.simplejsonrpc.client.Transport;
|
||||
import com.github.arteam.simplejsonrpc.client.exception.JsonRpcException;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.sparrow.AppController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -17,6 +19,7 @@ import static com.sparrowwallet.drongo.protocol.Transaction.DUST_RELAY_TX_FEE;
|
|||
|
||||
public class SimpleElectrumServerRpc implements ElectrumServerRpc {
|
||||
private static final Logger log = LoggerFactory.getLogger(SimpleElectrumServerRpc.class);
|
||||
private static final int MAX_TARGET_BLOCKS = 25;
|
||||
|
||||
@Override
|
||||
public void ping(Transport transport) {
|
||||
|
@ -156,7 +159,7 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, VerboseTransaction> getVerboseTransactions(Transport transport, Set<String> txids) {
|
||||
public Map<String, VerboseTransaction> getVerboseTransactions(Transport transport, Set<String> txids, String scriptHash) {
|
||||
JsonRpcClient client = new JsonRpcClient(transport);
|
||||
|
||||
Map<String, VerboseTransaction> result = new LinkedHashMap<>();
|
||||
|
@ -166,6 +169,27 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc {
|
|||
result.put(txid, verboseTransaction);
|
||||
} catch(IllegalStateException | IllegalArgumentException e) {
|
||||
log.warn("Error retrieving transaction: " + txid + " (" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + ")");
|
||||
String rawTxHex = client.createRequest().returnAs(String.class).method("blockchain.transaction.get").id(txid).params(txid).execute();
|
||||
Transaction tx = new Transaction(Utils.hexToBytes(rawTxHex));
|
||||
String id = tx.getTxId().toString();
|
||||
int height = 0;
|
||||
|
||||
if(scriptHash != null) {
|
||||
ScriptHashTx[] scriptHashTxes = client.createRequest().returnAs(ScriptHashTx[].class).method("blockchain.scripthash.get_history").id(id).params(scriptHash).execute();
|
||||
for(ScriptHashTx scriptHashTx : scriptHashTxes) {
|
||||
if(scriptHashTx.tx_hash.equals(id)) {
|
||||
height = scriptHashTx.height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerboseTransaction verboseTransaction = new VerboseTransaction();
|
||||
verboseTransaction.txid = id;
|
||||
verboseTransaction.hex = rawTxHex;
|
||||
verboseTransaction.confirmations = (height <= 0 ? 0 : AppController.getCurrentBlockHeight() - height + 1);
|
||||
verboseTransaction.blockhash = Sha256Hash.ZERO_HASH.toString();
|
||||
result.put(txid, verboseTransaction);
|
||||
} catch(JsonRpcException e) {
|
||||
log.warn("Error retrieving transaction: " + txid + " (" + e.getErrorMessage() + ")");
|
||||
}
|
||||
|
@ -180,14 +204,18 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc {
|
|||
|
||||
Map<Integer, Double> result = new LinkedHashMap<>();
|
||||
for(Integer targetBlock : targetBlocks) {
|
||||
try {
|
||||
Double targetBlocksFeeRateBtcKb = client.createRequest().returnAs(Double.class).method("blockchain.estimatefee").id(targetBlock).params(targetBlock).execute();
|
||||
result.put(targetBlock, targetBlocksFeeRateBtcKb);
|
||||
} catch(IllegalStateException | IllegalArgumentException e) {
|
||||
log.warn("Failed to retrieve fee rate for target blocks: " + targetBlock + " (" + e.getMessage() + ")");
|
||||
result.put(targetBlock, DUST_RELAY_TX_FEE);
|
||||
} catch(JsonRpcException e) {
|
||||
throw new ElectrumServerRpcException("Failed to retrieve fee rate for target blocks: " + targetBlock, e);
|
||||
if(targetBlock <= MAX_TARGET_BLOCKS) {
|
||||
try {
|
||||
Double targetBlocksFeeRateBtcKb = client.createRequest().returnAs(Double.class).method("blockchain.estimatefee").id(targetBlock).params(targetBlock).execute();
|
||||
result.put(targetBlock, targetBlocksFeeRateBtcKb);
|
||||
} catch(IllegalStateException | IllegalArgumentException e) {
|
||||
log.warn("Failed to retrieve fee rate for target blocks: " + targetBlock + " (" + e.getMessage() + ")");
|
||||
result.put(targetBlock, 1d);
|
||||
} catch(JsonRpcException e) {
|
||||
throw new ElectrumServerRpcException("Failed to retrieve fee rate for target blocks: " + targetBlock, e);
|
||||
}
|
||||
} else {
|
||||
result.put(targetBlock, 1d);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.github.arteam.simplejsonrpc.server.JsonRpcServer;
|
|||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
import java.io.*;
|
||||
|
@ -12,6 +14,8 @@ import java.net.Socket;
|
|||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class TcpTransport implements Transport, Closeable {
|
||||
private static final Logger log = LoggerFactory.getLogger(TcpTransport.class);
|
||||
|
||||
public static final int DEFAULT_PORT = 50001;
|
||||
|
||||
protected final HostAndPort server;
|
||||
|
@ -24,6 +28,7 @@ public class TcpTransport implements Transport, Closeable {
|
|||
private final ReentrantLock clientRequestLock = new ReentrantLock();
|
||||
private boolean running = false;
|
||||
private boolean reading = true;
|
||||
private boolean firstRead = true;
|
||||
|
||||
private final JsonRpcServer jsonRpcServer = new JsonRpcServer();
|
||||
private final SubscriptionService subscriptionService = new SubscriptionService();
|
||||
|
@ -53,6 +58,11 @@ public class TcpTransport implements Transport, Closeable {
|
|||
}
|
||||
|
||||
private synchronized String readResponse() throws IOException {
|
||||
if(firstRead) {
|
||||
notifyAll();
|
||||
firstRead = false;
|
||||
}
|
||||
|
||||
while(reading) {
|
||||
try {
|
||||
wait();
|
||||
|
@ -63,7 +73,7 @@ public class TcpTransport implements Transport, Closeable {
|
|||
}
|
||||
|
||||
if(lastException != null) {
|
||||
throw new IOException("Error reading response", lastException);
|
||||
throw new IOException("Error reading response: " + lastException.getMessage(), lastException);
|
||||
}
|
||||
|
||||
reading = true;
|
||||
|
@ -73,6 +83,13 @@ public class TcpTransport implements Transport, Closeable {
|
|||
}
|
||||
|
||||
public synchronized void readInputLoop() throws ServerException {
|
||||
try {
|
||||
//Don't start reading until first RPC request is sent
|
||||
wait();
|
||||
} catch(InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
while(running) {
|
||||
try {
|
||||
String received = readInputStream();
|
||||
|
@ -95,7 +112,7 @@ public class TcpTransport implements Transport, Closeable {
|
|||
reading = false;
|
||||
notifyAll();
|
||||
//Allow this thread to terminate as we will need to reconnect with a new transport anyway
|
||||
throw new ServerException(e);
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -469,7 +469,10 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
private void updateBlockchainForm(BlockTransaction blockTransaction, Integer currentHeight) {
|
||||
blockchainForm.setVisible(true);
|
||||
|
||||
if(currentHeight == null) {
|
||||
if(Sha256Hash.ZERO_HASH.equals(blockTransaction.getBlockHash()) && blockTransaction.getHeight() == 0 && headersForm.getSigningWallet() == null) {
|
||||
//A zero block hash indicates that this blocktransaction is incomplete and the height is likely incorrect if we are not sending a tx
|
||||
blockStatus.setText("Unknown");
|
||||
} else if(currentHeight == null) {
|
||||
blockStatus.setText(blockTransaction.getHeight() > 0 ? "Confirmed" : "Unconfirmed");
|
||||
} else {
|
||||
int confirmations = blockTransaction.getHeight() > 0 ? currentHeight - blockTransaction.getHeight() + 1 : 0;
|
||||
|
@ -512,7 +515,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
blockTimestampField.setVisible(false);
|
||||
}
|
||||
|
||||
if(blockTransaction.getBlockHash() != null) {
|
||||
if(blockTransaction.getBlockHash() != null && !blockTransaction.getBlockHash().equals(Sha256Hash.ZERO_HASH)) {
|
||||
blockHashField.setVisible(true);
|
||||
blockHash.setText(blockTransaction.getBlockHash().toString());
|
||||
blockHash.setContextMenu(new BlockHeightContextMenu(blockTransaction.getBlockHash()));
|
||||
|
@ -796,7 +799,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
@Subscribe
|
||||
public void blockTransactionFetched(BlockTransactionFetchedEvent event) {
|
||||
if(event.getTxId().equals(headersForm.getTransaction().getTxId())) {
|
||||
if(event.getBlockTransaction() != null) {
|
||||
if(event.getBlockTransaction() != null && (!Sha256Hash.ZERO_HASH.equals(event.getBlockTransaction().getBlockHash()) || headersForm.getBlockTransaction() == null)) {
|
||||
updateBlockchainForm(event.getBlockTransaction(), AppController.getCurrentBlockHeight());
|
||||
}
|
||||
|
||||
|
@ -937,7 +940,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
public void walletNodeHistoryChanged(WalletNodeHistoryChangedEvent event) {
|
||||
if(headersForm.getSigningWallet() != null && event.getWalletNode(headersForm.getSigningWallet()) != null) {
|
||||
Sha256Hash txid = headersForm.getTransaction().getTxId();
|
||||
ElectrumServer.TransactionReferenceService transactionReferenceService = new ElectrumServer.TransactionReferenceService(Set.of(txid));
|
||||
ElectrumServer.TransactionReferenceService transactionReferenceService = new ElectrumServer.TransactionReferenceService(Set.of(txid), event.getScriptHash());
|
||||
transactionReferenceService.setOnSucceeded(successEvent -> {
|
||||
Map<Sha256Hash, BlockTransaction> transactionMap = transactionReferenceService.getValue();
|
||||
BlockTransaction blockTransaction = transactionMap.get(txid);
|
||||
|
|
|
@ -319,9 +319,9 @@ public class TransactionController implements Initializable {
|
|||
Map<Sha256Hash, BlockTransaction> transactionMap = transactionReferenceService.getValue();
|
||||
BlockTransaction thisBlockTx = null;
|
||||
Map<Sha256Hash, BlockTransaction> inputTransactions = new HashMap<>();
|
||||
for (Sha256Hash txid : transactionMap.keySet()) {
|
||||
for(Sha256Hash txid : transactionMap.keySet()) {
|
||||
BlockTransaction blockTx = transactionMap.get(txid);
|
||||
if (txid.equals(getTransaction().getTxId())) {
|
||||
if(txid.equals(getTransaction().getTxId())) {
|
||||
thisBlockTx = blockTx;
|
||||
} else {
|
||||
inputTransactions.put(txid, blockTx);
|
||||
|
@ -456,7 +456,9 @@ public class TransactionController implements Initializable {
|
|||
@Subscribe
|
||||
public void blockTransactionFetched(BlockTransactionFetchedEvent event) {
|
||||
if(event.getTxId().equals(getTransaction().getTxId())) {
|
||||
txdata.setBlockTransaction(event.getBlockTransaction());
|
||||
if(event.getBlockTransaction() != null && (!Sha256Hash.ZERO_HASH.equals(event.getBlockTransaction().getBlockHash()) || txdata.getBlockTransaction() == null)) {
|
||||
txdata.setBlockTransaction(event.getBlockTransaction());
|
||||
}
|
||||
if(txdata.getInputTransactions() == null) {
|
||||
txdata.setInputTransactions(event.getInputTransactions());
|
||||
} else {
|
||||
|
|
|
@ -56,8 +56,8 @@
|
|||
<Separator styleClass="form-separator" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="1" />
|
||||
|
||||
<Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="2">
|
||||
<Fieldset inputGrow="SOMETIMES" text="Required Script">
|
||||
<Field text="ScriptPubKey">
|
||||
<Fieldset inputGrow="SOMETIMES" text="Required ScriptPubKey">
|
||||
<Field text="Script:">
|
||||
<VirtualizedScrollPane>
|
||||
<content>
|
||||
<ScriptArea fx:id="scriptPubKeyArea" editable="false" wrapText="true" prefHeight="42" maxHeight="42" styleClass="uneditable-codearea" />
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
}
|
||||
|
||||
.amount-unit {
|
||||
-fx-min-width: 70px;
|
||||
-fx-max-width: 70px;
|
||||
-fx-min-width: 75px;
|
||||
-fx-max-width: 75px;
|
||||
}
|
||||
|
||||
#feeRatesChart {
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
</Form>
|
||||
<Form GridPane.columnIndex="0" GridPane.rowIndex="1">
|
||||
<Fieldset inputGrow="SOMETIMES" text="Fee">
|
||||
<Field text="Block target:">
|
||||
<Field text="Block target">
|
||||
<Slider fx:id="targetBlocks" snapToTicks="true" showTickLabels="true" showTickMarks="true" />
|
||||
</Field>
|
||||
<Field fx:id="feeRateField" text="Rate:">
|
||||
|
|
Loading…
Reference in a new issue