Class MarriedKeyChain
- java.lang.Object
-
- org.bitcoinj.wallet.DeterministicKeyChain
-
- org.bitcoinj.wallet.MarriedKeyChain
-
- All Implemented Interfaces:
EncryptableKeyChain
,KeyChain
public class MarriedKeyChain extends DeterministicKeyChain
A multi-signature keychain using synchronized HD keys (a.k.a HDM)
This keychain keeps track of following keychains that follow the account key of this keychain. You can get P2SH addresses to receive coins to from this chain. The threshold - sigsRequiredToSpend specifies how many signatures required to spend transactions for this married keychain. This value should not exceed total number of keys involved (one followed key plus number of following keys), otherwise IllegalArgumentException will be thrown.
IMPORTANT: As of Bitcoin Core 0.9 all bare (non-P2SH) multisig transactions which require more than 3 public keys are non-standard and such spends won't be processed by peers with default settings, essentially making such transactions almost nonspendable
This method will throw an IllegalStateException, if the keychain is already married or already has leaf keys issued.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MarriedKeyChain.Builder<T extends MarriedKeyChain.Builder<T>>
Builds aMarriedKeyChain
-
Nested classes/interfaces inherited from interface org.bitcoinj.wallet.KeyChain
KeyChain.KeyPurpose
-
-
Field Summary
-
Fields inherited from class org.bitcoinj.wallet.DeterministicKeyChain
ACCOUNT_ONE_PATH, ACCOUNT_ZERO_PATH, BIP44_ACCOUNT_ZERO_PATH, DEFAULT_PASSPHRASE_FOR_MNEMONIC, EXTERNAL_SUBPATH, INTERNAL_SUBPATH, lock, lookaheadSize, lookaheadThreshold, sigsRequiredToSpend
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MarriedKeyChain(DeterministicKey accountKey, ScriptType outputScriptType)
This constructor is not stable across releases! If you need a stable API, usebuilder()
to use aMarriedKeyChain.Builder
.protected
MarriedKeyChain(DeterministicSeed seed, KeyCrypter crypter, ScriptType outputScriptType, java.util.List<ChildNumber> accountPath)
This constructor is not stable across releases! If you need a stable API, usebuilder()
to use aMarriedKeyChain.Builder
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MarriedKeyChain.Builder<?>
builder()
RedeemData
findRedeemDataByScriptHash(com.google.protobuf.ByteString bytes)
Returns the redeem script by its hash or null if this keychain did not generate the script.protected void
formatAddresses(boolean includeLookahead, boolean includePrivateKeys, AesKey aesKey, NetworkParameters params, java.lang.StringBuilder builder)
Script
freshOutputScript(KeyChain.KeyPurpose purpose)
Create a new married key and return the matching output scriptBloomFilter
getFilter(int size, double falsePositiveRate, int tweak)
Gets a bloom filter that contains all of the public keys from this chain, and which will provide the given false-positive rate if it has size elements.RedeemData
getRedeemData(DeterministicKey followedKey)
Get the redeem data for a key in this married chainboolean
isMarried()
Whether the keychain is married.void
maybeLookAheadScripts()
Housekeeping call to call when lookahead might be needed.int
numBloomFilterEntries()
Returns the number of elements this chain wishes to insert into the Bloom filter.java.util.List<Protos.Key>
serializeToProtobuf()
Serialize to list of keysvoid
setLookaheadSize(int lookaheadSize)
Sets a new lookahead size.-
Methods inherited from class org.bitcoinj.wallet.DeterministicKeyChain
addEventListener, addEventListener, checkAESKey, checkPassword, earliestKeyCreationTime, findKeyFromPubHash, findKeyFromPubKey, fromProtobuf, getAccountPath, getIssuedExternalKeys, getIssuedInternalKeys, getIssuedReceiveKeys, getKey, getKeyByPath, getKeyByPath, getKeyByPath, getKeyCrypter, getKeyLookaheadEpoch, getKeys, getLeafKeys, getLookaheadSize, getLookaheadThreshold, getMnemonicCode, getOutputScriptType, getRootKey, getSeed, getSigsRequiredToSpend, getWatchingKey, hasKey, isFollowing, isWatching, makeKeyChainFromSeed, markKeyAsUsed, markPubHashAsUsed, markPubKeyAsUsed, maybeLookAhead, numKeys, numLeafKeysIssued, removeEventListener, serializeMyselfToProtobuf, setLookaheadThreshold, setSigsRequiredToSpend, toDecrypted, toDecrypted, toEncrypted, toEncrypted, toString, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.bitcoinj.wallet.KeyChain
getEarliestKeyCreationTime
-
-
-
-
Constructor Detail
-
MarriedKeyChain
protected MarriedKeyChain(DeterministicKey accountKey, ScriptType outputScriptType)
This constructor is not stable across releases! If you need a stable API, usebuilder()
to use aMarriedKeyChain.Builder
.
-
MarriedKeyChain
protected MarriedKeyChain(DeterministicSeed seed, KeyCrypter crypter, ScriptType outputScriptType, java.util.List<ChildNumber> accountPath)
This constructor is not stable across releases! If you need a stable API, usebuilder()
to use aMarriedKeyChain.Builder
.
-
-
Method Detail
-
builder
public static MarriedKeyChain.Builder<?> builder()
-
isMarried
public boolean isMarried()
Description copied from class:DeterministicKeyChain
Whether the keychain is married. A keychain is married when it vends P2SH addresses from multiple keychains in a multisig relationship.- Overrides:
isMarried
in classDeterministicKeyChain
- See Also:
MarriedKeyChain
-
freshOutputScript
public Script freshOutputScript(KeyChain.KeyPurpose purpose)
Create a new married key and return the matching output script- Overrides:
freshOutputScript
in classDeterministicKeyChain
-
getRedeemData
public RedeemData getRedeemData(DeterministicKey followedKey)
Get the redeem data for a key in this married chain- Overrides:
getRedeemData
in classDeterministicKeyChain
-
setLookaheadSize
public void setLookaheadSize(int lookaheadSize)
Description copied from class:DeterministicKeyChain
Sets a new lookahead size. SeeDeterministicKeyChain.getLookaheadSize()
for details on what this is. Setting a new size that's larger than the current size will return immediately and the new size will only take effect next time a fresh filter is requested (e.g. due to a new peer being connected). So you should set this before starting to sync the chain, if you want to modify it. If you haven't modified the lookahead threshold manually then it will be automatically set to be a third of the new size.- Overrides:
setLookaheadSize
in classDeterministicKeyChain
-
serializeToProtobuf
public java.util.List<Protos.Key> serializeToProtobuf()
Serialize to list of keys- Specified by:
serializeToProtobuf
in interfaceKeyChain
- Overrides:
serializeToProtobuf
in classDeterministicKeyChain
- Returns:
- a list of keys (treat as unmodifiable list, will change in future release)
-
formatAddresses
protected void formatAddresses(boolean includeLookahead, boolean includePrivateKeys, @Nullable AesKey aesKey, NetworkParameters params, java.lang.StringBuilder builder)
- Overrides:
formatAddresses
in classDeterministicKeyChain
-
maybeLookAheadScripts
public void maybeLookAheadScripts()
Description copied from class:DeterministicKeyChain
Housekeeping call to call when lookahead might be needed. Normally called automatically by KeychainGroup.- Overrides:
maybeLookAheadScripts
in classDeterministicKeyChain
-
findRedeemDataByScriptHash
@Nullable public RedeemData findRedeemDataByScriptHash(com.google.protobuf.ByteString bytes)
Description copied from class:DeterministicKeyChain
Returns the redeem script by its hash or null if this keychain did not generate the script.- Overrides:
findRedeemDataByScriptHash
in classDeterministicKeyChain
-
getFilter
public BloomFilter getFilter(int size, double falsePositiveRate, int tweak)
Description copied from interface:KeyChain
Gets a bloom filter that contains all of the public keys from this chain, and which will provide the given false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for each key in the key chain, for the public key and the hash of the public key (address form). For this reason size should be at least 2x the result of
KeyChain.numKeys()
.This is used to generate a
BloomFilter
which can beBloomFilter.merge(BloomFilter)
d with another. It could also be used if you have a specific target for the filter's size.See the docs for
BloomFilter(int, double, int)
for a brief explanation of anonymity when using bloom filters, and for the meaning of these parameters.- Specified by:
getFilter
in interfaceKeyChain
- Overrides:
getFilter
in classDeterministicKeyChain
-
numBloomFilterEntries
public int numBloomFilterEntries()
Description copied from interface:KeyChain
Returns the number of elements this chain wishes to insert into the Bloom filter. The size passed toKeyChain.getFilter(int, double, int)
should be at least this large.- Specified by:
numBloomFilterEntries
in interfaceKeyChain
- Overrides:
numBloomFilterEntries
in classDeterministicKeyChain
-
-