• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MemoryBlockStore类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bitcoinj.store.MemoryBlockStore的典型用法代码示例。如果您正苦于以下问题:Java MemoryBlockStore类的具体用法?Java MemoryBlockStore怎么用?Java MemoryBlockStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MemoryBlockStore类属于org.bitcoinj.store包,在下文中一共展示了MemoryBlockStore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testInitialize

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Test
public void testInitialize() throws BlockStoreException {
    final BlockStore blockStore = new MemoryBlockStore(PARAMS);
    final BlockChain chain = new BlockChain(PARAMS, blockStore);

    // Build a historical chain of version 2 blocks
    long timeSeconds = 1231006505;
    StoredBlock chainHead = null;
    for (int height = 0; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock;
        assertEquals(2, chainHead.getHeader().getVersion());
        timeSeconds += 60;
    }

    VersionTally instance = new VersionTally(PARAMS);
    instance.initialize(blockStore, chainHead);
    assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:19,代码来源:VersionTallyTest.java


示例2: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    BriefLogFormatter.initVerbose();
    Context.propagate(new Context(testNet, 100, Coin.ZERO, false));
    testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
    wallet = new Wallet(PARAMS) {
        @Override
        public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
                                     int relativityOffset) throws VerificationException {
            super.receiveFromBlock(tx, block, blockType, relativityOffset);
            BlockChainTest.this.block[0] = block;
            if (isTransactionRelevant(tx) && tx.isCoinBase()) {
                BlockChainTest.this.coinbaseTransaction = tx;
            }
        }
    };
    wallet.freshReceiveKey();

    resetBlockStore();
    chain = new BlockChain(PARAMS, wallet, blockStore);

    coinbaseTo = wallet.currentReceiveKey().toAddress(PARAMS);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:25,代码来源:BlockChainTest.java


示例3: main

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAsync();
    peerGroup.awaitRunning();
    PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
    peerGroup.addAddress(addr);
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash blockHash = new Sha256Hash(args[0]);
    Future<Block> future = peer.getBlock(blockHash);
    System.out.println("Waiting for node to send us the requested block: " + blockHash);
    Block block = future.get();
    System.out.println(block);
    peerGroup.stopAsync();
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:23,代码来源:FetchBlock.java


示例4: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    BriefLogFormatter.initVerbose();
    testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
    Wallet.SendRequest.DEFAULT_FEE_PER_KB = Coin.ZERO;

    unitTestParams = UnitTestParams.get();
    wallet = new Wallet(unitTestParams) {
        @Override
        public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
                                     int relativityOffset) throws VerificationException {
            super.receiveFromBlock(tx, block, blockType, relativityOffset);
            BlockChainTest.this.block[0] = block;
            if (tx.isCoinBase()) {
                BlockChainTest.this.coinbaseTransaction = tx;
            }
        }
    };
    wallet.freshReceiveKey();

    resetBlockStore();
    chain = new BlockChain(unitTestParams, wallet, blockStore);

    coinbaseTo = wallet.currentReceiveKey().toAddress(unitTestParams);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:26,代码来源:BlockChainTest.java


示例5: createMarriedWallet

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
private void createMarriedWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException {
    wallet = new Wallet(params);
    blockStore = new MemoryBlockStore(params);
    chain = new BlockChain(params, wallet, blockStore);

    List<DeterministicKey> followingKeys = Lists.newArrayList();
    for (int i = 0; i < numKeys - 1; i++) {
        final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
        DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58());
        followingKeys.add(partnerKey);
        if (addSigners && i < threshold - 1)
            wallet.addTransactionSigner(new KeyChainTransactionSigner(keyChain));
    }

    wallet.addFollowingAccountKeys(followingKeys, threshold);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:17,代码来源:WalletTest.java


示例6: createMarriedWallet

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
private void createMarriedWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException {
    wallet = new Wallet(params);
    blockStore = new MemoryBlockStore(params);
    chain = new BlockChain(params, wallet, blockStore);

    List<DeterministicKey> followingKeys = Lists.newArrayList();
    for (int i = 0; i < numKeys - 1; i++) {
        final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
        DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58(params), params);
        followingKeys.add(partnerKey);
        if (addSigners && i < threshold - 1)
            wallet.addTransactionSigner(new KeyChainTransactionSigner(keyChain));
    }

    MarriedKeyChain chain = MarriedKeyChain.builder()
            .random(new SecureRandom())
            .followingKeys(followingKeys)
            .threshold(threshold).build();
    wallet.addAndActivateHDChain(chain);
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:21,代码来源:WalletTest.java


示例7: createMultiSigWallet

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
private void createMultiSigWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException {
        wallet = new Wallet(params);
        blockStore = new MemoryBlockStore(params);
        chain = new BlockChain(params, wallet, blockStore);

        List<DeterministicKey> followingKeys = Lists.newArrayList();
        for (int i = 0; i < numKeys - 1; i++) {
            final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
            DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58());
            followingKeys.add(partnerKey);
            if (addSigners && i < threshold - 1)
                wallet.addTransactionSigner(new KeyChainTransactionSigner(keyChain));
        }

//        MarriedKeyChain chain = MarriedKeyChain.builder()
//                .random(new SecureRandom())
//                .followingKeys(followingKeys)
//                .threshold(threshold).build();
//        wallet.addAndActivateHDChain(chain);
    }
 
开发者ID:JohnnyCryptoCoin,项目名称:speciebox,代码行数:21,代码来源:WalletTools.java


示例8: main

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.start();
    PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
    peerGroup.addAddress(addr);
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash blockHash = Sha256Hash.wrap(args[0]);
    Future<Block> future = peer.getBlock(blockHash);
    System.out.println("Waiting for node to send us the requested block: " + blockHash);
    Block block = future.get();
    System.out.println(block);
    peerGroup.stopAsync();
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:22,代码来源:FetchBlock.java


示例9: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    BriefLogFormatter.initVerbose();
    Context.propagate(new Context(testNet, 100, Coin.ZERO, false));
    testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
    wallet = new Wallet(PARAMS) {
        @Override
        public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
                                     int relativityOffset) throws VerificationException {
            super.receiveFromBlock(tx, block, blockType, relativityOffset);
            BlockChainTest.this.block[0] = block;
            if (isTransactionRelevant(tx) && tx.isCoinBase()) {
                BlockChainTest.this.coinbaseTransaction = tx;
            }
        }
    };
    wallet.freshReceiveKey();

    resetBlockStore();
    chain = new BlockChain(PARAMS, wallet, blockStore);

    coinbaseTo = wallet.currentReceiveKey().toAddress(PARAMS);
    Context.get().initDash(false, true);
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:26,代码来源:BlockChainTest.java


示例10: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
    wallet = new Wallet(PARAMS);
    myKey = wallet.currentReceiveKey();
    myAddress = myKey.toAddress(PARAMS);
    blockStore = new MemoryBlockStore(PARAMS);
    chain = new BlockChain(PARAMS, wallet, blockStore);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:10,代码来源:TestWithWallet.java


示例11: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Utils.setMockClock(); // Use mock clock
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
    MemoryBlockStore blockStore = new MemoryBlockStore(PARAMS);
    wallet = new Wallet(PARAMS);
    ECKey key1 = wallet.freshReceiveKey();
    ECKey key2 = wallet.freshReceiveKey();
    chain = new BlockChain(PARAMS, wallet, blockStore);
    coinsTo = key1.toAddress(PARAMS);
    coinsTo2 = key2.toAddress(PARAMS);
    someOtherGuy = new ECKey().toAddress(PARAMS);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:15,代码来源:ChainSplitTest.java


示例12: testDeprecatedBlockVersion

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion)
        throws Exception {
    final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS);
    final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore);

    // Build a historical chain of version 3 blocks
    long timeSeconds = 1231006505;
    int height = 0;
    FakeTxBuilder.BlockPair chainHead = null;

    // Put in just enough v2 blocks to be a minority
    for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }
    // Fill the rest of the window with v3 blocks
    for (; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }

    chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
    // Trying to add a new v2 block should result in rejection
    thrown.expect(VerificationException.BlockVersionOutOfDate.class);
    try {
        versionChain.add(chainHead.block);
    } catch(final VerificationException ex) {
        throw (Exception) ex.getCause();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:33,代码来源:BlockChainTest.java


示例13: estimatedBlockTime

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Test
public void estimatedBlockTime() throws Exception {
    NetworkParameters params = MainNetParams.get();
    BlockChain prod = new BlockChain(new Context(params), new MemoryBlockStore(params));
    Date d = prod.estimateBlockTime(200000);
    // The actual date of block 200,000 was 2012-09-22 10:47:00
    assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:9,代码来源:BlockChainTest.java


示例14: main

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    File file = new File(args[0]);
    Wallet wallet = Wallet.loadFromFile(file);
    System.out.println(wallet.toString());

    // Set up the components and link them together.
    final NetworkParameters params = TestNet3Params.get();
    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, wallet, blockStore);

    final PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost()));
    peerGroup.startAsync();

    wallet.addEventListener(new AbstractWalletEventListener() {
        @Override
        public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
            System.out.println("\nReceived tx " + tx.getHashAsString());
            System.out.println(tx.toString());
        }
    });

    // Now download and process the block chain.
    peerGroup.downloadBlockChain();
    peerGroup.stopAsync();
    wallet.saveToFile(file);
    System.out.println("\nDone!\n");
    System.out.println(wallet.toString());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:30,代码来源:RefreshWallet.java


示例15: main

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAsync();
    peerGroup.awaitRunning();
    peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash txHash = new Sha256Hash(args[0]);
    ListenableFuture<Transaction> future = peer.getPeerMempoolTransaction(txHash);
    System.out.println("Waiting for node to send us the requested transaction: " + txHash);
    Transaction tx = future.get();
    System.out.println(tx);

    System.out.println("Waiting for node to send us the dependencies ...");
    List<Transaction> deps = peer.downloadDependencies(tx).get();
    for (Transaction dep : deps) {
        System.out.println("Got dependency " + dep.getHashAsString());
    }

    System.out.println("Done.");
    peerGroup.stopAsync();
    peerGroup.awaitTerminated();
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:31,代码来源:FetchTransactions.java


示例16: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Wallet.SendRequest.DEFAULT_FEE_PER_KB = Coin.ZERO;
    wallet = new Wallet(params);
    myKey = wallet.currentReceiveKey();
    myAddress = myKey.toAddress(params);
    blockStore = new MemoryBlockStore(params);
    chain = new BlockChain(params, wallet, blockStore);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:10,代码来源:TestWithWallet.java


示例17: setUp

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Utils.setMockClock(); // Use mock clock
    Wallet.SendRequest.DEFAULT_FEE_PER_KB = Coin.ZERO;
    unitTestParams = UnitTestParams.get();
    wallet = new Wallet(unitTestParams);
    ECKey key1 = wallet.freshReceiveKey();
    ECKey key2 = wallet.freshReceiveKey();
    blockStore = new MemoryBlockStore(unitTestParams);
    chain = new BlockChain(unitTestParams, wallet, blockStore);
    coinsTo = key1.toAddress(unitTestParams);
    coinsTo2 = key2.toAddress(unitTestParams);
    someOtherGuy = new ECKey().toAddress(unitTestParams);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:16,代码来源:ChainSplitTest.java


示例18: estimatedBlockTime

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
@Test
public void estimatedBlockTime() throws Exception {
    NetworkParameters params = MainNetParams.get();
    BlockChain prod = new BlockChain(params, new MemoryBlockStore(params));
    Date d = prod.estimateBlockTime(200000);
    // The actual date of block 200,000 was 2012-09-22 10:47:00
    assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:9,代码来源:BlockChainTest.java


示例19: start

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
/**
 * Starts a bitcoin network peer and begins to listen
 *
 * @throws BlockStoreException
 */
public void start() throws BlockStoreException {
    BlockChain blockChain = new BlockChain(NET_PARAMS, new MemoryBlockStore(NET_PARAMS));
    PeerGroup peerGroup = new PeerGroup(NET_PARAMS, blockChain);
    peerGroup.addPeerDiscovery(new DnsDiscovery(NET_PARAMS));
    peerGroup.addEventListener(peerEventListener);
    peerGroup.startAsync();


}
 
开发者ID:lifeofreilly,项目名称:ostendo,代码行数:15,代码来源:PeerListener.java


示例20: main

import org.bitcoinj.store.MemoryBlockStore; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    File file = new File(args[0]);
    Wallet wallet = Wallet.loadFromFile(file);
    System.out.println(wallet.toString());

    // Set up the components and link them together.
    final NetworkParameters params = TestNet3Params.get();
    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, wallet, blockStore);

    final PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAsync();

    wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
            System.out.println("\nReceived tx " + tx.getHashAsString());
            System.out.println(tx.toString());
        }
    });

    // Now download and process the block chain.
    peerGroup.downloadBlockChain();
    peerGroup.stopAsync();
    wallet.saveToFile(file);
    System.out.println("\nDone!\n");
    System.out.println(wallet.toString());
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:29,代码来源:RefreshWallet.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GpioPinPwmOutput类代码示例发布时间:2022-05-22
下一篇:
Java ObjectDeserializer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap