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


Java BlockChain类代码示例

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


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

示例1: isNymNotSpend

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
public boolean isNymNotSpend(BlockChain bc) {
	//check locktime and compare to current bip113 time
	//we only accept p2sh
	if(!getLastTransactionOutput().getScriptPubKey().isPayToScriptHash()) {
		System.out.println("the psynym is not a p2sh");
		return false;
	}
	
	//check that redeem script matches the p2sh output hash
	if(!ScriptBuilder.createP2SHOutputScript(sp.getRedeemScript()).equals(getLastTransactionOutput().getScriptPubKey())) {
		System.out.println("the redeem script doesn't match the p2sh output hash");
		return false;
	}
	
	//check that the redeem script is the one we specified and check that it is still locked
	if(!sp.isRedeemScriptRightFormat() || !sp.isLocked(bc)) {
		System.out.println("redeem script is either not in right format or transaction is not locked, might be not spend, but we can't know without utxo set");
		return false;
	}
	return true;
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:22,代码来源:ProofMessage.java

示例2: isValidProof

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
public boolean isValidProof(BlockChain bc, PeerGroup pg, NetworkParameters params) {
	if(!isValidPath()) {
		System.out.println("path is not valid, thus proof not valid, abort");
		return false;
	}
	if(!isValidGPTx()) {
		System.out.println("gptx is not valid, abort");
		return false;
	}
	if(!isNymNotSpend(bc)) {
		System.out.println("nym is not locked anymore, consider spent, abort");
		return false;
	}
	if(!isNymTxInBlockChain(params, bc, pg)) {
		System.out.println("nymtx is not in blockchain, consider proof invalid, abort");
		return false;
	}
	System.out.println("proof seems valid");
	return true;
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:21,代码来源:ProofMessage.java

示例3: currentBitcoinBIP113Time

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
public static long currentBitcoinBIP113Time(BlockChain bc) {
	StoredBlock headBlock = bc.getChainHead();
	StoredBlock iteratingBlock = headBlock;
	long[] blockTimeStamps = new long[11];
	for(int i=0; i < 11; i++) {
		blockTimeStamps[i] = iteratingBlock.getHeader().getTimeSeconds();
		try {
			iteratingBlock = iteratingBlock.getPrev(bc.getBlockStore());
		} catch (BlockStoreException e) {
			e.printStackTrace();
		}
	}
	Arrays.sort(blockTimeStamps);
	System.out.println("current bitcoinbip113time yielded " + new Date(blockTimeStamps[5]*1000));
	return blockTimeStamps[5];
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:17,代码来源:CLTVScriptPair.java

示例4: notifyTransactionIsInBlock

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
/**
 * Called by the {@link BlockChain} when we receive a new filtered block that contains a transactions previously
 * received by a call to {@link #receivePending}.<p>
 *
 * This is necessary for the internal book-keeping Wallet does. When a transaction is received that sends us
 * coins it is added to a pool so we can use it later to create spends. When a transaction is received that
 * consumes outputs they are marked as spent so they won't be used in future.<p>
 *
 * A transaction that spends our own coins can be received either because a spend we created was accepted by the
 * network and thus made it into a block, or because our keys are being shared between multiple instances and
 * some other node spent the coins instead. We still have to know about that to avoid accidentally trying to
 * double spend.<p>
 *
 * A transaction may be received multiple times if is included into blocks in parallel chains. The blockType
 * parameter describes whether the containing block is on the main/best chain or whether it's on a presently
 * inactive side chain. We must still record these transactions and the blocks they appear in because a future
 * block might change which chain is best causing a reorganize. A re-org can totally change our balance!
 */
@Override
public boolean notifyTransactionIsInBlock(Sha256Hash txHash, StoredBlock block,
                                          BlockChain.NewBlockType blockType,
                                          int relativityOffset) throws VerificationException {
    lock.lock();
    try {
        Transaction tx = transactions.get(txHash);
        if (tx == null) {
            tx = riskDropped.get(txHash);
            if (tx != null) {
                // If this happens our risk analysis is probably wrong and should be improved.
                log.info("Risk analysis dropped tx {} but was included in block anyway", tx.getHash());
            } else {
                // False positive that was broadcast to us and ignored by us because it was irrelevant to our keys.
                return false;
            }
        }
        receive(tx, block, blockType, relativityOffset);
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:42,代码来源:Wallet.java

示例5: testInitialize

import org.bitcoinj.core.BlockChain; //导入依赖的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

示例6: isConsistent_duplicates

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
@Test
public void isConsistent_duplicates() throws Exception {
    // This test ensures that isConsistent catches duplicate transactions, eg, because we submitted the same block
    // twice (this is not allowed).
    Transaction tx = createFakeTx(PARAMS, COIN, myAddress);
    TransactionOutput output = new TransactionOutput(PARAMS, tx, valueOf(0, 5), OTHER_ADDRESS);
    tx.addOutput(output);
    wallet.receiveFromBlock(tx, null, BlockChain.NewBlockType.BEST_CHAIN, 0);

    assertTrue(wallet.isConsistent());

    Transaction txClone = PARAMS.getDefaultSerializer().makeTransaction(tx.bitcoinSerialize());
    try {
        wallet.receiveFromBlock(txClone, null, BlockChain.NewBlockType.BEST_CHAIN, 0);
        fail("Illegal argument not thrown when it should have been.");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:20,代码来源:WalletTest.java

示例7: watchingScriptsBloomFilter

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
@Test
public void watchingScriptsBloomFilter() throws Exception {
    assertFalse(wallet.isRequiringUpdateAllBloomFilter());

    Address watchedAddress = new ECKey().toAddress(PARAMS);
    Transaction t1 = createFakeTx(PARAMS, CENT, watchedAddress);
    TransactionOutPoint outPoint = new TransactionOutPoint(PARAMS, 0, t1);
    wallet.addWatchedAddress(watchedAddress);

    assertTrue(wallet.isRequiringUpdateAllBloomFilter());
    // Note that this has a 1e-12 chance of failing this unit test due to a false positive
    assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));

    sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, t1);
    assertTrue(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:17,代码来源:WalletTest.java

示例8: removeScriptsBloomFilter

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
@Test
public void removeScriptsBloomFilter() throws Exception {
    List<Address> addressesForRemoval = new ArrayList<Address>();
    for (int i = 0; i < 10; i++) {
        Address watchedAddress = new ECKey().toAddress(PARAMS);
        addressesForRemoval.add(watchedAddress);
        wallet.addWatchedAddress(watchedAddress);
    }

    wallet.removeWatchedAddresses(addressesForRemoval);

    for (Address addr : addressesForRemoval) {
        Transaction t1 = createFakeTx(PARAMS, CENT, addr);
        TransactionOutPoint outPoint = new TransactionOutPoint(PARAMS, 0, t1);

        // Note that this has a 1e-12 chance of failing this unit test due to a false positive
        assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));

        sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, t1);
        assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:23,代码来源:WalletTest.java

示例9: getBlockchainService

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
@Bean
public BlockChainService getBlockchainService(final NetworkParameters params,
                                              final BlockChain blockChain,
                                              final PeerGroup peerGroup,
                                              final TransactionStateService transactionService,
                                              final WalletDbService walletService,
                                              final AccountDbService accountService,
                                              final BlockchainSettings settings
                                              ){

    final BitcoinjBlockchainServiceImpl blockChainService =
            new BitcoinjBlockchainServiceImpl(params, blockChain, peerGroup, transactionService, walletService, accountService, settings);

    blockChainService.init();
    return blockChainService;
}
 
开发者ID:yopeio,项目名称:payment-api,代码行数:17,代码来源:BitcoinjConfiguration.java

示例10: NameLookupLatestLevelDBTransactionCache

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
public NameLookupLatestLevelDBTransactionCache (Context context, File directory, DBFactory dbFactory, BlockChain chain, BlockStore store, PeerGroup peerGroup) throws IOException {
    this.chain = chain;
    this.store = store;
    this.peerGroup = peerGroup;
    
    this.context = context;
    this.params = context.getParams();
    
    this.path = directory;
    Options options = new Options();
    options.createIfMissing();
    
    try {
        tryOpen(directory, dbFactory, options);
    } catch (IOException e) {
        dbFactory.repair(directory, options);
        tryOpen(directory, dbFactory, options);
    }
    
    chain.addNewBestBlockListener(Threading.SAME_THREAD, this);
    chain.addReorganizeListener(Threading.SAME_THREAD, this);
    chain.addTransactionReceivedListener(Threading.SAME_THREAD, this);
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:24,代码来源:NameLookupLatestLevelDBTransactionCache.java

示例11: createMultiSigWallet

import org.bitcoinj.core.BlockChain; //导入依赖的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

示例12: removeScriptsBloomFilter

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
@Test
public void removeScriptsBloomFilter() throws Exception {
    List<Address> addressesForRemoval = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Address watchedAddress = new ECKey().toAddress(PARAMS);
        addressesForRemoval.add(watchedAddress);
        wallet.addWatchedAddress(watchedAddress);
    }

    wallet.removeWatchedAddresses(addressesForRemoval);

    for (Address addr : addressesForRemoval) {
        Transaction t1 = createFakeTx(PARAMS, CENT, addr);
        TransactionOutPoint outPoint = new TransactionOutPoint(PARAMS, 0, t1);

        // Note that this has a 1e-12 chance of failing this unit test due to a false positive
        assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));

        sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, t1);
        assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
    }
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:23,代码来源:WalletTest.java

示例13: TransactionGenerator

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
public TransactionGenerator(NetworkParameters params, PeerGroup pg, Wallet w, BlockChain bc) {
	this.params = params;
	this.pg = pg;
	this.w = w;
	this.bc = bc;
	
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:8,代码来源:TransactionGenerator.java

示例14: getBlockHashByHeight

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
private Sha256Hash getBlockHashByHeight(BlockChain bc, int appearedInChainheight2) {
	int bestchainheight = bc.getBestChainHeight();
	StoredBlock block = bc.getChainHead();
	assert(block != null);
	for(int i=0; i < bestchainheight-appearedInChainheight2; i++) {
		try {
			System.out.println("iteration: " + i);
			assert(block != null);
			block = block.getPrev(bc.getBlockStore());
		} catch (BlockStoreException e) {
			e.printStackTrace();
		}
	}
	return block.getHeader().getHash();
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:16,代码来源:ProofMessage.java

示例15: Mixer

import org.bitcoinj.core.BlockChain; //导入依赖的package包/类
public Mixer(PTP ptp, BroadcastAnnouncement bca, ProofMessage pm, Wallet w, NetworkParameters params, PeerGroup pg, BlockChain bc) {
	this.ptp = ptp;
	this.bca = bca;
	this.mixPartnerAdress = new Identifier(bca.getOnionAdress() + ".onion");
	this.ownProof = pm;
	this.w = w;
	this.params = params;
	this.pg = pg;
	this.bc = bc;
	this.mfListeners = new ArrayList<MixFinishedEventListener>();
	this.lockTime = 0; 
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:13,代码来源:Mixer.java


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