当前位置: 首页>>代码示例>>Java>>正文


Java DeterministicKeyChain.watch方法代码示例

本文整理汇总了Java中org.bitcoinj.wallet.DeterministicKeyChain.watch方法的典型用法代码示例。如果您正苦于以下问题:Java DeterministicKeyChain.watch方法的具体用法?Java DeterministicKeyChain.watch怎么用?Java DeterministicKeyChain.watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.wallet.DeterministicKeyChain的用法示例。


在下文中一共展示了DeterministicKeyChain.watch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: watchingChain

import org.bitcoinj.wallet.DeterministicKeyChain; //导入方法依赖的package包/类
@Test
public void watchingChain() throws UnreadableWalletException {
    Utils.setMockClock();
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    DeterministicKey key4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);

    DeterministicKey watchingKey = chain.getWatchingKey();
    final String pub58 = watchingKey.serializePubB58();
    assertEquals("xpub69KR9epSNBM59KLuasxMU5CyKytMJjBP5HEZ5p8YoGUCpM6cM9hqxB9DDPCpUUtqmw5duTckvPfwpoWGQUFPmRLpxs5jYiTf2u6xRMcdhDf", pub58);
    watchingKey = DeterministicKey.deserializeB58(null, pub58);
    watchingKey.setCreationTimeSeconds(100000);
    chain = DeterministicKeyChain.watch(watchingKey);
    assertEquals(DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS, chain.getEarliestKeyCreationTime());
    chain.setLookaheadSize(10);
    chain.maybeLookAhead();

    assertEquals(key1.getPubKeyPoint(), chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKeyPoint());
    assertEquals(key2.getPubKeyPoint(), chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKeyPoint());
    final DeterministicKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(key3.getPubKeyPoint(), key.getPubKeyPoint());
    try {
        // Can't sign with a key from a watching chain.
        key.sign(Sha256Hash.ZERO_HASH);
        fail();
    } catch (ECKey.MissingPrivateKeyException e) {
        // Ignored.
    }
    // Test we can serialize and deserialize a watching chain OK.
    List<Protos.Key> serialization = chain.serializeToProtobuf();
    checkSerialization(serialization, "watching-wallet-serialization.txt");
    chain = DeterministicKeyChain.fromProtobuf(serialization, null).get(0);
    final DeterministicKey rekey4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(key4.getPubKeyPoint(), rekey4.getPubKeyPoint());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:DeterministicKeyChainTest.java

示例2: bloom2

import org.bitcoinj.wallet.DeterministicKeyChain; //导入方法依赖的package包/类
@Test
public void bloom2() throws Exception {
    // Verify that if when we watch a key, the filter contains at least 100 keys.
    DeterministicKey[] keys = new DeterministicKey[100];
    for (int i = 0; i < keys.length; i++)
        keys[i] = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    chain = DeterministicKeyChain.watch(chain.getWatchingKey());
    int e = chain.numBloomFilterEntries();
    BloomFilter filter = chain.getFilter(e, 0.001, 1);
    for (DeterministicKey key : keys)
        assertTrue("key " + key, filter.contains(key.getPubKeyHash()));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:13,代码来源:DeterministicKeyChainTest.java

示例3: watchingCannotEncrypt

import org.bitcoinj.wallet.DeterministicKeyChain; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void watchingCannotEncrypt() throws Exception {
    final DeterministicKey accountKey = chain.getKeyByPath(DeterministicKeyChain.ACCOUNT_ZERO_PATH);
    chain = DeterministicKeyChain.watch(accountKey.getPubOnly());
    chain = chain.toEncrypted("this doesn't make any sense");
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:7,代码来源:DeterministicKeyChainTest.java


注:本文中的org.bitcoinj.wallet.DeterministicKeyChain.watch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。