本文整理汇总了Java中org.bitcoinj.store.MemoryBlockStore类的典型用法代码示例。如果您正苦于以下问题:Java MemoryBlockStore类的具体用法?Java MemoryBlockStore怎么用?Java MemoryBlockStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryBlockStore类属于org.bitcoinj.store包,在下文中一共展示了MemoryBlockStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例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());
}
示例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();
}