本文整理汇总了Java中org.bitcoinj.core.Block类的典型用法代码示例。如果您正苦于以下问题:Java Block类的具体用法?Java Block怎么用?Java Block使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Block类属于org.bitcoinj.core包,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlocksDownloaded
import org.bitcoinj.core.Block; //导入依赖的package包/类
@Override
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
//Log.d("BlocksDownloaded",block.getHashAsString());
Integer height=blockChain.getChainHead().getHeight();
synchronized (blocks) {
blocks.put(block, height);
if (blocks.keySet().size() >= 30) {
blocks.remove(blocks.keySet().toArray()[blocks.keySet().size() - 1]);
}
}
if(System.currentTimeMillis()-lastTimestamp>1000) {
refreshUI();
lastTimestamp = System.currentTimeMillis();
}
}
示例2: onBindViewHolder
import org.bitcoinj.core.Block; //导入依赖的package包/类
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
synchronized (mDataset) {
final Block block = (Block) (mDataset.keySet().toArray()[position]);
Integer height = (Integer) (mDataset.values().toArray())[position];
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy/MM/dd HH:mm");
String formatted = dateFormat.format(block.getTime());
holder.mTvTitle.setText(formatted);
holder.mTvBlockHash.setText(block.getHashAsString());
holder.mTvHeight.setText(String.valueOf(height));
holder.mTvTransactions.setText(String.valueOf(block.getTransactions().size()));
holder.key = block.getHashAsString().toString();
}
}
示例3: SQLiteBlockStore
import org.bitcoinj.core.Block; //导入依赖的package包/类
public SQLiteBlockStore(NetworkParameters params, Context context) throws BlockStoreException {
this.params = params;
blocksDataSource = new BlocksDataSource(context);
blocksDataSource.open();
if (blocksDataSource.count()==0){
createNewBlockStore(params);
} else{
try {
DBBlock block = blocksDataSource.getLast();
Block b = new Block(params, block.getHeader());
StoredBlock s = build(b);
this.chainHead = s.getHeader().getHash();
} catch (Exception e) {
throw new BlockStoreException("Invalid BlockStore chainHead");
}
}
blocksDataSource.close();
}
示例4: get
import org.bitcoinj.core.Block; //导入依赖的package包/类
@Override
public synchronized StoredBlock get(Sha256Hash hash) throws BlockStoreException {
if(hash==null)
throw new BlockStoreException("Invalid hash");
blocksDataSource.open();
DBBlock block = null;
try {
block = blocksDataSource.getHash(hash.toString());
} catch (Exception e) {
blocksDataSource.close();
return null;
}
Block b = new Block(params, block.getHeader());
StoredBlock s = build(b);
blocksDataSource.close();
return s;
}
示例5: onBlocksDownloaded
import org.bitcoinj.core.Block; //导入依赖的package包/类
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
if(!this.caughtUp) {
if(blocksLeft == 0) {
this.caughtUp = true;
this.doneDownload();
this.future.set(Long.valueOf(peer.getBestHeight()));
}
if(blocksLeft >= 0 && this.originalBlocksLeft > 0) {
double pct = 100.0D - 100.0D * ((double)blocksLeft / (double)this.originalBlocksLeft);
if((int)pct != this.lastPercent) {
this.lastBlockDate = new Date(block.getTimeSeconds() * 1000L);
this.progress(pct, blocksLeft, this.lastBlockDate);
this.lastPercent = (int)pct;
}
}
}
}
示例6: onBlocksDownloaded
import org.bitcoinj.core.Block; //导入依赖的package包/类
@Override
public void onBlocksDownloaded(Peer arg0, Block arg1,
@Nullable FilteredBlock arg2, int arg3) {
System.out.println("received block");
boolean receivedBcastAnnouncmnt = false;
Map<Sha256Hash, Transaction> assocTxs = arg2.getAssociatedTransactions();
for(Transaction tx : assocTxs.values()) {
System.out.println("from within mixpartner discovery " + tx);
if(tx.getOutputs().size() > 1 &&
BroadcastAnnouncement.isBroadcastAnnouncementScript(tx.getOutput(1).getScriptBytes()))
//&& !wallet.isTransactionRelevant(tx)) {
//tx.getInput(0).getScriptSig().getChunks().get(0)
{
if(!this.broadcasts.contains(tx) && wallet.getTransaction(tx.getHash()) == null) {
this.broadcasts.add(tx);
receivedBcastAnnouncmnt = true;
}
}
}
if(receivedBcastAnnouncmnt) {
for(BroadcastAnnouncementChangeEventListener l : listeners) {
l.onBroadcastAnnouncementChanged();
}
}
}
示例7: createGenesis
import org.bitcoinj.core.Block; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n, Block.BLOCK_VERSION_GENESIS);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
byte[] bytes = Utils.HEX.decode
("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode
("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, FIFTY_COINS, scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例8: getTransactionVerificationFlags
import org.bitcoinj.core.Block; //导入依赖的package包/类
/**
* The flags indicating which script validation tests should be applied to
* the given transaction. Enables support for alternative blockchains which enable
* tests based on different criteria.
*
* @param block block the transaction belongs to.
* @param transaction to determine flags for.
* @param height height of the block, if known, null otherwise. Returned
* tests should be a safe subset if block height is unknown.
*/
public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(final Block block,
final Transaction transaction, final VersionTally tally, final Integer height) {
final EnumSet<Script.VerifyFlag> verifyFlags = EnumSet.noneOf(Script.VerifyFlag.class);
if (block.getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME)
verifyFlags.add(Script.VerifyFlag.P2SH);
// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
// blocks, when 75% of the network has upgraded:
if (block.getVersion() >= Block.BLOCK_VERSION_BIP65 &&
tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP65) > this.getMajorityEnforceBlockUpgrade()) {
verifyFlags.add(Script.VerifyFlag.CHECKLOCKTIMEVERIFY);
}
return verifyFlags;
}
示例9: onBlocksDownloaded
import org.bitcoinj.core.Block; //导入依赖的package包/类
@Override
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
if (caughtUp)
return;
if (blocksLeft == 0) {
caughtUp = true;
doneDownload();
future.set(peer.getBestHeight());
}
if (blocksLeft < 0 || originalBlocksLeft <= 0)
return;
double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft));
if ((int) pct != lastPercent) {
progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000));
lastPercent = (int) pct;
}
}
示例10: reDownloadBlockTransactions
import org.bitcoinj.core.Block; //导入依赖的package包/类
public void reDownloadBlockTransactions(Integer blockHeight) {
Database db = Database.getInstance();
ResultSet rs = db.executeQuery("select * from blocks where block_index='"+blockHeight.toString()+"';");
try {
if (rs.next()) {
Block block = peerGroup.getDownloadPeer().getBlock(new Sha256Hash(rs.getString("block_hash"))).get();
db.executeUpdate("delete from transactions where block_index='"+blockHeight.toString()+"';");
Integer txSnInBlock=0;
for (Transaction tx : block.getTransactions()) {
importPPkTransaction(tx,txSnInBlock, block, blockHeight);
txSnInBlock++;
}
}
} catch (Exception e) {
}
}
示例11: importBlock
import org.bitcoinj.core.Block; //导入依赖的package包/类
public void importBlock(Block block, Integer blockHeight) {
statusMessage = "Importing block "+blockHeight;
logger.info(statusMessage);
Database db = Database.getInstance();
ResultSet rs = db.executeQuery("select * from blocks where block_hash='"+block.getHashAsString()+"';");
try {
if (!rs.next()) {
db.executeUpdate("INSERT INTO blocks(block_index,block_hash,block_time,block_nonce) VALUES('"+blockHeight.toString()+"','"+block.getHashAsString()+"','"+block.getTimeSeconds()+"','"+block.getNonce()+"')");
}
Integer txSnInBlock=0;
for (Transaction tx : block.getTransactions()) {
importPPkTransaction(tx,txSnInBlock, block, blockHeight);
txSnInBlock++;
}
} catch (SQLException e) {
}
}
示例12: get
import org.bitcoinj.core.Block; //导入依赖的package包/类
/**
* Get the block at height index.
*
* Returns null if we didn't see the block yet, or if we started at a checkpoint after the block.
*/
public Block get(long index) {
lock.lock();
try {
if (channel.size() < (index+1) * HEADER_SIZE)
return null;
ByteBuffer b = ByteBuffer.allocate((int)HEADER_SIZE);
int n = channel.read(b, index * HEADER_SIZE);
if (n == 0) return null;
if (n != HEADER_SIZE)
throw new RuntimeException("partial read from store file");
if (Arrays.equals(b.array(), EMPTY))
return null;
return new Block(params, b.array());
} catch (IOException e) {
throw propagate(e);
} finally {
lock.unlock();
}
}
示例13: add
import org.bitcoinj.core.Block; //导入依赖的package包/类
public boolean add(Block block) {
checkState(block.getTransactions() == null);
lock.lock();
try {
if (!block.getPrevBlockHash().equals(top().getHash())) {
log.error("block.prev = {}, but expecting {}@{}", block.getPrevBlockHash(), top().getHash(), getHeight());
return false;
}
channel.write(ByteBuffer.wrap(block.bitcoinSerialize()), channel.size());
return true;
} catch (Exception e) {
throw propagate(e);
} finally {
lock.unlock();
}
}
示例14: UnitTestParams
import org.bitcoinj.core.Block; //导入依赖的package包/类
public UnitTestParams() {
super();
id = ID_UNITTESTNET;
packetMagic = 0x0b110907;
addressHeader = CoinDefinition.testnetAddressHeader;
p2shHeader = CoinDefinition.testnetp2shHeader;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
maxTarget = new BigInteger("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16);
genesisBlock.setTime(System.currentTimeMillis() / 1000);
genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET);
//genesisBlock.solve();
port = CoinDefinition.TestPort;
interval = 10;
dumpedPrivateKeyHeader = 128 + CoinDefinition.testnetAddressHeader;
targetTimespan = 200000000; // 6 years. Just a very big number.
spendableCoinbaseDepth = 5;
subsidyDecreaseBlockCount = 100;
dnsSeeds = null;
}
示例15: createGenesis
import org.bitcoinj.core.Block; //导入依赖的package包/类
private static AltcoinBlock createGenesis(NetworkParameters params) {
AltcoinBlock genesisBlock = new AltcoinBlock(params, Block.BLOCK_VERSION_GENESIS);
Transaction t = new Transaction(params);
try {
byte[] bytes = Utils.HEX.decode
("04ffff001d0104084e696e746f6e646f");
t.addInput(new TransactionInput(params, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode
("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(params, t, COIN.multiply(88), scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}