3

Bitcoinj generates receiving addresses on demand and change addresses after each transaction. So how do I list all receiving addresses ? I guess I have to deal with KeyChainGroup and BasicKeyChain. I know how to get all issued receive keys

wallet.getActiveKeyChain().getIssuedReceiveKeys();

but cannot find change keys. So where is getIssuedChangeKeys() method or if there is not such method whta is the reason. I'm trying to imagine how recovery would work if the wallet is restored from seed.

2

This seems to get change addresses:

public List<String> getChangeAddresses() {
    List<String> ret = new ArrayList<>();
    int issuedKeys = wallet.getActiveKeyChain().getIssuedInternalKeys();

    for (int i = 0; i < issuedKeys; i++) {
        ChildNumber childNumber = new ChildNumber(i, false);
        List<ChildNumber> childNumbers = new ArrayList<>();
        childNumbers.add(ChildNumber.ZERO_HARDENED);
        childNumbers.add(ChildNumber.ONE);
        childNumbers.add(childNumber);
        ECKey key = wallet.getKeyByPath(childNumbers);
        ret.add(new Address(params, key.getPubKeyHash()).toBase58());
    }
    return ret;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.