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


Java BlockStore类代码示例

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


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

示例1: setUp

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
    BriefLogFormatter.init();

    unitTestParams = UnitTestParams.get();
    Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
    this.blockStore = blockStore;
    wallet = new Wallet(unitTestParams);
    key = new ECKey();
    address = key.toAddress(unitTestParams);
    wallet.addKey(key);
    blockChain = new BlockChain(unitTestParams, wallet, blockStore);

    startPeerServers();
    if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER)
        channels.startAndWait();

    socketAddress = new InetSocketAddress("127.0.0.1", 1111);
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:19,代码来源:TestWithNetworkConnections.java

示例2: findSplit

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
/**
 * Locates the point in the chain at which newStoredBlock and chainHead diverge. Returns null if no split point was
 * found (ie they are not part of the same chain). Returns newChainHead or chainHead if they don't actually diverge
 * but are part of the same chain.
 */
private static StoredBlock findSplit(StoredBlock newChainHead, StoredBlock oldChainHead,
                                     BlockStore store) throws BlockStoreException {
    StoredBlock currentChainCursor = oldChainHead;
    StoredBlock newChainCursor = newChainHead;
    // Loop until we find the block both chains have in common. Example:
    //
    //    A -> B -> C -> D
    //         \--> E -> F -> G
    //
    // findSplit will return block B. oldChainHead = D and newChainHead = G.
    while (!currentChainCursor.equals(newChainCursor)) {
        if (currentChainCursor.getHeight() > newChainCursor.getHeight()) {
            currentChainCursor = currentChainCursor.getPrev(store);
            checkNotNull(currentChainCursor, "Attempt to follow an orphan chain");
        } else {
            newChainCursor = newChainCursor.getPrev(store);
            checkNotNull(newChainCursor, "Attempt to follow an orphan chain");
        }
    }
    return currentChainCursor;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:27,代码来源:AbstractBlockChain.java

示例3: getPrevWorkForAlgo

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
BigInteger getPrevWorkForAlgo(int algo, BlockStore blockStore)
{
    //BigInteger nWork;
    try {
        StoredBlock cursor = getPrev(blockStore);
        while (cursor != null)
        {
            if (cursor.getHeader().getAlgo() == algo)
            {
                return cursor.getHeader().getWork();
            }
            cursor = cursor.getPrev(blockStore);
        }
    }
    catch(BlockStoreException x)
    {

    }
    return CoinDefinition.getProofOfWorkLimit(algo);
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:21,代码来源:StoredBlock.java

示例4: getLastBlockForAlgo

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
public static StoredBlock getLastBlockForAlgo(StoredBlock block, int algo, BlockStore blockStore)
{
    for(;;)
    {
        if(block == null || block.getHeader().getPrevBlockHash().equals(Sha256Hash.ZERO_HASH))
            return null;
        if(block.getHeader().getAlgo() == algo)
            return block;
        try {
            block = block.getPrev(blockStore);
        }
        catch(BlockStoreException x)
        {
            return null;
        }
    }

}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:19,代码来源:Utils.java

示例5: main

import com.google.bitcoin.store.BlockStore; //导入依赖的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.startAndWait();
    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.stop();
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:22,代码来源:FetchBlock.java

示例6: setUp

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
    BriefLogFormatter.init();

    unitTestParams = UnitTestParams.get();
    Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
    this.blockStore = blockStore;
    wallet = new Wallet(unitTestParams);
    key = new ECKey();
    address = key.toAddress(unitTestParams);
    wallet.addKey(key);
    blockChain = new BlockChain(unitTestParams, wallet, blockStore);

    startPeerServers();
    if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER) {
        channels.startAsync();
        channels.awaitRunning();
    }

    socketAddress = new InetSocketAddress("127.0.0.1", 1111);
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:21,代码来源:TestWithNetworkConnections.java

示例7: main

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

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAndWait();
    PeerAddress addr = new PeerAddress(InetAddress.getByName("mc.9cat.net"), params.getPort());
    peerGroup.addAddress(addr);
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash blockHash = new Sha256Hash("b8adcd350628a717b74f3faaab32aa72398635006fba23352b3d30ce1925df79");
    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.stop();
}
 
开发者ID:9cat,项目名称:templecoin-java,代码行数:23,代码来源:FetchBlock.java

示例8: main

import com.google.bitcoin.store.BlockStore; //导入依赖的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.start();

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

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

示例9: GetPrevWorkForAlgoWithDecay3

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
BigInteger GetPrevWorkForAlgoWithDecay3(int algo, BlockStore blockStore)
{
    try {
        int nDistance = 0;
        //BigInteger nWork;
        StoredBlock pindex = this.getPrev(blockStore);
        while (pindex != null)
        {
            if (nDistance > 100)
            {
                return BigInteger.ZERO;
            }
            if (pindex.getHeader().getAlgo() == algo)
            {
                BigInteger nWork = pindex.getHeader().getWork();
                nWork = nWork.multiply(BigInteger.valueOf(100 - nDistance));
                nWork = nWork.divide(BigInteger.valueOf(100));
                return nWork;
            }
            pindex = this.getPrev(blockStore);
            nDistance++;
        }
    }
    catch(BlockStoreException x)
    {

    }
    return BigInteger.ZERO;
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:30,代码来源:StoredBlock.java

示例10: AbstractBlockChain

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
/**
 * Constructs a BlockChain connected to the given list of listeners (eg, wallets) and a store.
 */
public AbstractBlockChain(NetworkParameters params, List<BlockChainListener> listeners,
                          BlockStore blockStore) throws BlockStoreException {
    this.blockStore = blockStore;
    chainHead = blockStore.getChainHead();
    log.info("chain head is at height {}:\n{}", chainHead.getHeight(), chainHead.getHeader());
    this.params = params;
    this.listeners = new CopyOnWriteArrayList<ListenerRegistration<BlockChainListener>>();
    for (BlockChainListener l : listeners) addListener(l, Threading.SAME_THREAD);
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:13,代码来源:AbstractBlockChain.java

示例11: getPartialChain

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
/**
 * Returns the set of contiguous blocks between 'higher' and 'lower'. Higher is included, lower is not.
 */
private static LinkedList<StoredBlock> getPartialChain(StoredBlock higher, StoredBlock lower, BlockStore store) throws BlockStoreException {
    checkArgument(higher.getHeight() > lower.getHeight(), "higher and lower are reversed");
    LinkedList<StoredBlock> results = new LinkedList<StoredBlock>();
    StoredBlock cursor = higher;
    while (true) {
        results.add(cursor);
        cursor = checkNotNull(cursor.getPrev(store), "Ran off the end of the chain");
        if (cursor.equals(lower)) break;
    }
    return results;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:15,代码来源:AbstractBlockChain.java

示例12: setUp

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
    super.setUp(blockStore);

    remoteVersionMessage = new VersionMessage(unitTestParams, 1);
    remoteVersionMessage.localServices = VersionMessage.NODE_NETWORK;
    remoteVersionMessage.clientVersion = NotFoundMessage.MIN_PROTOCOL_VERSION;
    initPeerGroup();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:9,代码来源:TestWithPeerGroup.java

示例13: getMedianTimestampOfRecentBlocks

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
/**
 * Gets the median timestamp of the last 11 blocks
 */
private static long getMedianTimestampOfRecentBlocks(StoredBlock storedBlock,
                                                     BlockStore store) throws BlockStoreException {
    long[] timestamps = new long[11];
    int unused = 9;
    timestamps[10] = storedBlock.getHeader().getTimeSeconds();
    while (unused >= 0 && (storedBlock = storedBlock.getPrev(store)) != null)
        timestamps[unused--] = storedBlock.getHeader().getTimeSeconds();
    
    Arrays.sort(timestamps, unused+1, 11);
    return timestamps[unused + (11-unused)/2];
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:15,代码来源:AbstractBlockChain.java

示例14: setUp

import com.google.bitcoin.store.BlockStore; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
    super.setUp(blockStore);

    remoteVersionMessage = new VersionMessage(unitTestParams, 1);
    remoteVersionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
    
    ClientBootstrap bootstrap = new ClientBootstrap(new ChannelFactory() {
        public void releaseExternalResources() {}
        public Channel newChannel(ChannelPipeline pipeline) {
            ChannelSink sink = new FakeChannelSink();
            return new FakeChannel(this, pipeline, sink);
        }
        public void shutdown() {}
    });
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() throws Exception {
            VersionMessage ver = new VersionMessage(unitTestParams, 1);
            ChannelPipeline p = Channels.pipeline();
            
            Peer peer = new Peer(unitTestParams, blockChain, ver, peerGroup.getMemoryPool());
            peer.addLifecycleListener(peerGroup.startupListener);
            p.addLast("peer", peer.getHandler());
            return p;
        }

    });
    peerGroup = new PeerGroup(unitTestParams, blockChain, bootstrap);
    peerGroup.setPingIntervalMsec(0);  // Disable the pings as they just get in the way of most tests.
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:30,代码来源:TestWithPeerGroup.java

示例15: main

import com.google.bitcoin.store.BlockStore; //导入依赖的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.start();

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

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


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