mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
cormorant: support transaction.get without txindex, use step function to add bip47 addresses
This commit is contained in:
parent
e7ed82699c
commit
276cb8aecb
3 changed files with 57 additions and 13 deletions
|
@ -133,7 +133,12 @@ public class BitcoindClient {
|
|||
try {
|
||||
getBitcoindService().loadWallet(CORE_WALLET_NAME, false);
|
||||
} catch(JsonRpcException e) {
|
||||
try {
|
||||
getBitcoindService().unloadWallet(CORE_WALLET_NAME, false);
|
||||
} catch(JsonRpcException ex) {
|
||||
//ignore
|
||||
}
|
||||
|
||||
getBitcoindService().loadWallet(CORE_WALLET_NAME, false);
|
||||
}
|
||||
}
|
||||
|
@ -188,10 +193,15 @@ public class BitcoindClient {
|
|||
|
||||
for(Wallet childWallet : wallet.getChildWallets()) {
|
||||
if(childWallet.isNested()) {
|
||||
Wallet copyChildWallet = childWallet.copy();
|
||||
for(KeyPurpose keyPurpose : KeyPurpose.DEFAULT_PURPOSES) {
|
||||
for(WalletNode addressNode : childWallet.getNode(keyPurpose).getChildren()) {
|
||||
WalletNode purposeNode = copyChildWallet.getNode(keyPurpose);
|
||||
int addressCount = purposeNode.getChildren().size();
|
||||
int gapLimit = ((int)Math.floor(addressCount / 10.0) * 10) + 10;
|
||||
purposeNode.fillToIndex(gapLimit - 1);
|
||||
for(WalletNode addressNode : purposeNode.getChildren()) {
|
||||
String addressOutputDescriptor = OutputDescriptor.toDescriptorString(addressNode.getAddress());
|
||||
addOutputDescriptor(outputDescriptors, addressOutputDescriptor, childWallet, null, earliestBirthDate);
|
||||
addOutputDescriptor(outputDescriptors, addressOutputDescriptor, copyChildWallet, null, earliestBirthDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ public interface BitcoindClientService {
|
|||
@JsonRpcMethod("getrawtransaction")
|
||||
Object getRawTransaction(@JsonRpcParam("txid") String txid, @JsonRpcParam("verbose") boolean verbose);
|
||||
|
||||
@JsonRpcMethod("gettransaction")
|
||||
Map<String, Object> getTransaction(@JsonRpcParam("txid") String txid, @JsonRpcParam("verbose") boolean verbose);
|
||||
|
||||
@JsonRpcMethod("getmempoolentry")
|
||||
MempoolEntry getMempoolEntry(@JsonRpcParam("txid") String txid);
|
||||
|
||||
|
|
|
@ -13,10 +13,7 @@ import com.sparrowwallet.sparrow.net.cormorant.index.TxEntry;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@JsonRpcService
|
||||
public class ElectrumServerService {
|
||||
|
@ -146,14 +143,48 @@ public class ElectrumServerService {
|
|||
}
|
||||
|
||||
@JsonRpcMethod("blockchain.transaction.get")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getTransaction(@JsonRpcParam("tx_hash") String tx_hash, @JsonRpcParam("verbose") @JsonRpcOptional boolean verbose) throws BitcoindIOException, TransactionNotFoundException {
|
||||
if(verbose) {
|
||||
try {
|
||||
return bitcoindClient.getBitcoindService().getRawTransaction(tx_hash, verbose);
|
||||
return bitcoindClient.getBitcoindService().getRawTransaction(tx_hash, true);
|
||||
} catch(JsonRpcException e) {
|
||||
try {
|
||||
Map<String, Object> txInfo = bitcoindClient.getBitcoindService().getTransaction(tx_hash, true);
|
||||
Object decoded = txInfo.get("decoded");
|
||||
if(decoded instanceof Map<?, ?>) {
|
||||
Map<String, Object> decodedMap = (Map<String, Object>)decoded;
|
||||
decodedMap.put("hex", txInfo.get("hex"));
|
||||
decodedMap.put("confirmations", txInfo.get("confirmations"));
|
||||
decodedMap.put("blockhash", txInfo.get("blockhash"));
|
||||
decodedMap.put("time", txInfo.get("time"));
|
||||
decodedMap.put("blocktime", txInfo.get("blocktime"));
|
||||
return decoded;
|
||||
}
|
||||
throw new TransactionNotFoundException(e.getErrorMessage());
|
||||
} catch(JsonRpcException ex) {
|
||||
throw new TransactionNotFoundException(ex.getErrorMessage());
|
||||
} catch(IllegalStateException ex) {
|
||||
throw new BitcoindIOException(ex);
|
||||
}
|
||||
} catch(IllegalStateException e) {
|
||||
throw new BitcoindIOException(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return bitcoindClient.getBitcoindService().getTransaction(tx_hash, false).get("hex");
|
||||
} catch(JsonRpcException e) {
|
||||
try {
|
||||
return bitcoindClient.getBitcoindService().getRawTransaction(tx_hash, false);
|
||||
} catch(JsonRpcException ex) {
|
||||
throw new TransactionNotFoundException(ex.getErrorMessage());
|
||||
} catch(IllegalStateException ex) {
|
||||
throw new BitcoindIOException(e);
|
||||
}
|
||||
} catch(IllegalStateException e) {
|
||||
throw new BitcoindIOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JsonRpcMethod("blockchain.transaction.broadcast")
|
||||
|
|
Loading…
Reference in a new issue