本文整理汇总了Java中com.google.bitcoin.store.MemoryBlockStore类的典型用法代码示例。如果您正苦于以下问题:Java MemoryBlockStore类的具体用法?Java MemoryBlockStore怎么用?Java MemoryBlockStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemoryBlockStore类属于com.google.bitcoin.store包,在下文中一共展示了MemoryBlockStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.google.bitcoin.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.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();
}
示例2: setUp
import com.google.bitcoin.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 = BigInteger.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.addKey(new ECKey());
resetBlockStore();
chain = new BlockChain(unitTestParams, wallet, blockStore);
coinbaseTo = wallet.getKeys().get(0).toAddress(unitTestParams);
}
示例3: main
import com.google.bitcoin.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();
}
示例4: main
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的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();
}
示例5: main
import com.google.bitcoin.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.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());
}
示例6: main
import com.google.bitcoin.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.startAndWait();
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.stopAndWait();
}
示例7: setUp
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的package包/类
public void setUp() throws Exception {
BriefLogFormatter.init();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
myKey = new ECKey();
myAddress = myKey.toAddress(params);
wallet = new Wallet(params);
wallet.addKey(myKey);
blockStore = new MemoryBlockStore(params);
chain = new BlockChain(params, wallet, blockStore);
}
示例8: setUp
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
BriefLogFormatter.init();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams);
wallet.addKey(new ECKey());
wallet.addKey(new ECKey());
blockStore = new MemoryBlockStore(unitTestParams);
chain = new BlockChain(unitTestParams, wallet, blockStore);
coinsTo = wallet.getKeys().get(0).toAddress(unitTestParams);
coinsTo2 = wallet.getKeys().get(1).toAddress(unitTestParams);
someOtherGuy = new ECKey().toAddress(unitTestParams);
}
示例9: estimatedBlockTime
import com.google.bitcoin.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").parse("2012-10-23T08:35:05.000-0700"), d);
}
示例10: setUp
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp(new MemoryBlockStore(UnitTestParams.get()));
peerGroup.addWallet(wallet);
// Fix the random permutation that TransactionBroadcast uses to shuffle the peers.
TransactionBroadcast.random = new Random(0);
peerGroup.setMinBroadcastConnections(2);
peerGroup.startAndWait();
}
示例11: setUp
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
peerToMessageCount = new HashMap<Peer, AtomicInteger>();
connectedPeers = new LinkedBlockingQueue<Peer>();
disconnectedPeers = new LinkedBlockingQueue<Peer>();
listener = new AbstractPeerEventListener() {
@Override
public void onPeerConnected(Peer peer, int peerCount) {
connectedPeers.add(peer);
}
@Override
public void onPeerDisconnected(Peer peer, int peerCount) {
disconnectedPeers.add(peer);
}
@Override
public Message onPreMessageReceived(Peer peer, Message m) {
AtomicInteger messageCount = peerToMessageCount.get(peer);
if (messageCount == null) {
messageCount = new AtomicInteger(0);
peerToMessageCount.put(peer, messageCount);
}
messageCount.incrementAndGet();
// Just pass the message right through for further processing.
return m;
}
};
super.setUp(new MemoryBlockStore(UnitTestParams.get()));
peerGroup.addWallet(wallet);
}
示例12: main
import com.google.bitcoin.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.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());
}
示例13: setUp
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
BriefLogFormatter.init();
Utils.setMockClock(); // Use mock clock
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams);
wallet.addKey(new ECKey());
wallet.addKey(new ECKey());
blockStore = new MemoryBlockStore(unitTestParams);
chain = new BlockChain(unitTestParams, wallet, blockStore);
coinsTo = wallet.getKeys().get(0).toAddress(unitTestParams);
coinsTo2 = wallet.getKeys().get(1).toAddress(unitTestParams);
someOtherGuy = new ECKey().toAddress(unitTestParams);
}
示例14: setUp
import com.google.bitcoin.store.MemoryBlockStore; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
Utils.setMockClock(); // Use mock clock
super.setUp(new MemoryBlockStore(UnitTestParams.get()));
peerGroup.addWallet(wallet);
// Fix the random permutation that TransactionBroadcast uses to shuffle the peers.
TransactionBroadcast.random = new Random(0);
peerGroup.setMinBroadcastConnections(2);
peerGroup.startAndWait();
}
示例15: main
import com.google.bitcoin.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, 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.stopAsync();
wallet.saveToFile(file);
System.out.println("\nDone!\n");
System.out.println(wallet.toString());
}