mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-05 03:26:43 +00:00
prepare address matching
This commit is contained in:
parent
911a54347d
commit
cdf608807f
6 changed files with 33 additions and 14 deletions
|
@ -47,7 +47,7 @@ public class Main {
|
||||||
int walletNumber = 1;
|
int walletNumber = 1;
|
||||||
WatchWallet wallet = getWalletFromProperties(properties, walletNumber);
|
WatchWallet wallet = getWalletFromProperties(properties, walletNumber);
|
||||||
if(wallet == null) {
|
if(wallet == null) {
|
||||||
log.error("Property wallet.name.1 and/or wallet.pubkey.1 not set, provide wallet name and Base58 encoded key starting with xpub or ypub");
|
log.error("Property wallet.name.1 and/or wallet.descriptor.1 not set, provide wallet name and Base58 encoded key starting with xpub or ypub");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
while(wallet != null) {
|
while(wallet != null) {
|
||||||
|
@ -67,9 +67,9 @@ public class Main {
|
||||||
|
|
||||||
private static WatchWallet getWalletFromProperties(Properties properties, int walletNumber) {
|
private static WatchWallet getWalletFromProperties(Properties properties, int walletNumber) {
|
||||||
String walletName = properties.getProperty("wallet.name." + walletNumber);
|
String walletName = properties.getProperty("wallet.name." + walletNumber);
|
||||||
String walletPubKey = properties.getProperty("wallet.pubkey." + walletNumber);
|
String walletDescriptor = properties.getProperty("wallet.descriptor." + walletNumber);
|
||||||
if(walletName != null && walletPubKey != null) {
|
if(walletName != null && walletDescriptor != null) {
|
||||||
return new WatchWallet(walletName, walletPubKey);
|
return new WatchWallet(walletName, walletDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -74,6 +74,6 @@ public class TransactionTask implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(outputJoiner.toString());
|
builder.append(outputJoiner.toString());
|
||||||
log.info(builder.toString());
|
log.info(builder.toString() + " " + transaction.getAllAddresses());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,15 @@ public class WatchWallet {
|
||||||
private static final int LOOK_AHEAD_LIMIT = 500;
|
private static final int LOOK_AHEAD_LIMIT = 500;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String extPubKey;
|
|
||||||
|
|
||||||
private OutputDescriptor outputDescriptor;
|
private OutputDescriptor outputDescriptor;
|
||||||
private DeterministicHierarchy hierarchy;
|
private DeterministicHierarchy hierarchy;
|
||||||
|
|
||||||
private HashMap<String,String> addresses = new HashMap<>(LOOK_AHEAD_LIMIT*2);
|
private HashMap<Address,List<ChildNumber>> addresses = new HashMap<>(LOOK_AHEAD_LIMIT*2);
|
||||||
|
|
||||||
public WatchWallet(String name, String descriptor) {
|
public WatchWallet(String name, String descriptor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.outputDescriptor = OutputDescriptor.getOutputDescriptor(descriptor);
|
this.outputDescriptor = OutputDescriptor.getOutputDescriptor(descriptor);
|
||||||
this.hierarchy = new DeterministicHierarchy(outputDescriptor.getPubKey());
|
this.hierarchy = new DeterministicHierarchy(outputDescriptor.getPubKey());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialiseAddresses() {
|
public void initialiseAddresses() {
|
||||||
|
@ -29,21 +26,29 @@ public class WatchWallet {
|
||||||
for(int index = 0; index <= LOOK_AHEAD_LIMIT; index++) {
|
for(int index = 0; index <= LOOK_AHEAD_LIMIT; index++) {
|
||||||
List<ChildNumber> receivingDerivation = outputDescriptor.getReceivingDerivation(index);
|
List<ChildNumber> receivingDerivation = outputDescriptor.getReceivingDerivation(index);
|
||||||
Address address = getAddress(receivingDerivation);
|
Address address = getAddress(receivingDerivation);
|
||||||
addresses.put(address.toString(), Utils.formatHDPath(receivingDerivation));
|
addresses.put(address, receivingDerivation);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int index = 0; index <= LOOK_AHEAD_LIMIT; index++) {
|
for(int index = 0; index <= LOOK_AHEAD_LIMIT; index++) {
|
||||||
List<ChildNumber> changeDerivation = outputDescriptor.getChangeDerivation(index);
|
List<ChildNumber> changeDerivation = outputDescriptor.getChangeDerivation(index);
|
||||||
Address address = getAddress(changeDerivation);
|
Address address = getAddress(changeDerivation);
|
||||||
addresses.put(address.toString(), Utils.formatHDPath(changeDerivation));
|
addresses.put(address, changeDerivation);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<ChildNumber> derivation = outputDescriptor.getChildDerivation();
|
List<ChildNumber> derivation = outputDescriptor.getChildDerivation();
|
||||||
Address address = getAddress(derivation);
|
Address address = getAddress(derivation);
|
||||||
addresses.put(address.toString(), Utils.formatHDPath(derivation));
|
addresses.put(address, derivation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsAddress(Address address) {
|
||||||
|
return addresses.containsKey(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ChildNumber> getAddressPath(Address address) {
|
||||||
|
return addresses.get(address);
|
||||||
|
}
|
||||||
|
|
||||||
public Address getReceivingAddress(int index) {
|
public Address getReceivingAddress(int index) {
|
||||||
return getAddress(outputDescriptor.getReceivingDerivation(index));
|
return getAddress(outputDescriptor.getReceivingDerivation(index));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -177,6 +178,19 @@ public class Transaction extends TransactionPart {
|
||||||
return Collections.unmodifiableList(outputs);
|
return Collections.unmodifiableList(outputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Address> getAllAddresses() {
|
||||||
|
List<Address> addresses = new ArrayList<>();
|
||||||
|
for(TransactionInput input : getInputs()) {
|
||||||
|
addresses.addAll(Arrays.asList(input.getOutpoint().getAddresses()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(TransactionOutput output : getOutputs()) {
|
||||||
|
addresses.addAll(Arrays.asList(output.getAddresses()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
public static final void main(String[] args) {
|
public static final void main(String[] args) {
|
||||||
String hex = "0100000001e0ea4cd2f1307820d5f33e61aa6b636d8ff94fa7e3b1913f058fb1c8a765fde0340000006a47304402201aa0955638da2902ba972100816d21bde55d0415b98064b7fa511ffefa41397702203f9c93e27557b5b04187784e79f2c1eb74a3202a73085ddfb4509069b90cbbed0121023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ffffffff3510270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac2a91a401000000001976a9141f924ac57c8e44cfbf860fbe0a3ea072b5fb8d0f88ac00000000";
|
String hex = "0100000001e0ea4cd2f1307820d5f33e61aa6b636d8ff94fa7e3b1913f058fb1c8a765fde0340000006a47304402201aa0955638da2902ba972100816d21bde55d0415b98064b7fa511ffefa41397702203f9c93e27557b5b04187784e79f2c1eb74a3202a73085ddfb4509069b90cbbed0121023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ffffffff3510270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac10270000000000002321023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6ac2a91a401000000001976a9141f924ac57c8e44cfbf860fbe0a3ea072b5fb8d0f88ac00000000";
|
||||||
byte[] transactionBytes = Utils.hexToBytes(hex);
|
byte[] transactionBytes = Utils.hexToBytes(hex);
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class TransactionOutPoint extends TransactionPart {
|
||||||
/** Which output of that transaction we are talking about. */
|
/** Which output of that transaction we are talking about. */
|
||||||
private long index;
|
private long index;
|
||||||
|
|
||||||
private Address[] addresses;
|
private Address[] addresses = new Address[0];
|
||||||
|
|
||||||
public TransactionOutPoint(byte[] rawtx, int offset, TransactionPart parent) {
|
public TransactionOutPoint(byte[] rawtx, int offset, TransactionPart parent) {
|
||||||
super(rawtx, offset);
|
super(rawtx, offset);
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class TransactionOutput extends TransactionPart {
|
||||||
|
|
||||||
private int scriptLen;
|
private int scriptLen;
|
||||||
|
|
||||||
private Address[] addresses;
|
private Address[] addresses = new Address[0];
|
||||||
|
|
||||||
public TransactionOutput(Transaction transaction, byte[] rawtx, int offset) {
|
public TransactionOutput(Transaction transaction, byte[] rawtx, int offset) {
|
||||||
super(rawtx, offset);
|
super(rawtx, offset);
|
||||||
|
|
Loading…
Reference in a new issue