checking in and pushing the isSpendable and public key generation for testing again

This commit is contained in:
kennycud
2023-12-03 12:45:31 -08:00
parent 9671c2da61
commit deaef4fc4a
8 changed files with 75 additions and 6 deletions

View File

@@ -21,15 +21,18 @@ public class AddressInfo {
private int transactionCount;
private boolean isSpendable;
public AddressInfo() {
}
public AddressInfo(String address, List<Integer> path, long value, String pathAsString, int transactionCount) {
public AddressInfo(String address, List<Integer> path, long value, String pathAsString, int transactionCount, boolean isSpendable) {
this.address = address;
this.path = path;
this.value = value;
this.pathAsString = pathAsString;
this.transactionCount = transactionCount;
this.isSpendable = isSpendable;
}
public String getAddress() {
@@ -52,17 +55,21 @@ public class AddressInfo {
return transactionCount;
}
public boolean isSpendable() {
return isSpendable;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AddressInfo that = (AddressInfo) o;
return value == that.value && transactionCount == that.transactionCount && Objects.equals(address, that.address) && Objects.equals(path, that.path) && Objects.equals(pathAsString, that.pathAsString);
return value == that.value && transactionCount == that.transactionCount && isSpendable == that.isSpendable && address.equals(that.address) && path.equals(that.path) && pathAsString.equals(that.pathAsString);
}
@Override
public int hashCode() {
return Objects.hash(address, path, value, pathAsString, transactionCount);
return Objects.hash(address, path, value, pathAsString, transactionCount, isSpendable);
}
@Override
@@ -73,6 +80,7 @@ public class AddressInfo {
", value=" + value +
", pathAsString='" + pathAsString + '\'' +
", transactionCount=" + transactionCount +
", isSpendable=" + isSpendable +
'}';
}
}

View File

@@ -335,6 +335,30 @@ public abstract class Bitcoiny implements ForeignBlockchain {
}
}
/**
* Get Spending Candidate Addresses
*
* @param key58 public master key
* @return the addresses this instance will look at when building a spend
* @throws ForeignBlockchainException
*/
public List<String> getSpendingCandidateAddresses(String key58) throws ForeignBlockchainException {
Wallet wallet = Wallet.fromWatchingKeyB58(this.params, key58, DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS);
wallet.setUTXOProvider(new WalletAwareUTXOProvider(this, wallet));
// from Wallet.getStoredOutputsFromUTXOProvider()
List<ECKey> spendingKeys = wallet.getImportedKeys();
spendingKeys.addAll(wallet.getActiveKeyChain().getLeafKeys());
List<String> spendingCandidateAddresses
= spendingKeys.stream()
.map(spendingKey -> Address.fromKey(this.params, spendingKey, ScriptType.P2PKH ).toString())
.collect(Collectors.toList());
return spendingCandidateAddresses;
}
/**
* Returns bitcoinj transaction sending <tt>amount</tt> to <tt>recipient</tt> using default fees.
*
@@ -478,8 +502,10 @@ public abstract class Bitcoiny implements ForeignBlockchain {
public List<AddressInfo> getWalletAddressInfos(String key58) throws ForeignBlockchainException {
List<AddressInfo> infos = new ArrayList<>();
List<String> candidates = this.getSpendingCandidateAddresses(key58);
for(DeterministicKey key : getWalletKeys(key58)) {
infos.add(buildAddressInfo(key));
infos.add(buildAddressInfo(key, candidates));
}
return infos.stream()
@@ -487,7 +513,7 @@ public abstract class Bitcoiny implements ForeignBlockchain {
.collect(Collectors.toList());
}
public AddressInfo buildAddressInfo(DeterministicKey key) throws ForeignBlockchainException {
public AddressInfo buildAddressInfo(DeterministicKey key, List<String> candidates) throws ForeignBlockchainException {
Address address = Address.fromKey(this.params, key, ScriptType.P2PKH);
@@ -498,7 +524,8 @@ public abstract class Bitcoiny implements ForeignBlockchain {
toIntegerList( key.getPath()),
summingUnspentOutputs(address.toString()),
key.getPathAsString(),
transactionCount);
transactionCount,
candidates.contains(address.toString()));
}
private static List<Integer> toIntegerList(ImmutableList<ChildNumber> path) {