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


Java Block.getTransactions方法代码示例

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


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

示例1: 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) {

  }
}
 
开发者ID:ppkpub,项目名称:javatool,代码行数:18,代码来源:Blocks.java

示例2: 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) {
  }
}
 
开发者ID:ppkpub,项目名称:javatool,代码行数:18,代码来源:Blocks.java

示例3: BlockSummary

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public BlockSummary(int height, Block blk, TXUtil tx_util, Map<Sha256Hash, TransactionSummary> tx_cache)
{
  this.height = height;
  this.block_hash = blk.getHash();

  tx_map = new HashMap<>();

  for(Transaction tx : blk.getTransactions())
  {
    TransactionSummary tx_sum = new TransactionSummary(tx, tx_util, tx_cache);

    tx_map.put(tx.getHash(), tx_sum);
    synchronized(tx_cache)
    {
      tx_cache.put(tx.getHash(), tx_sum);
    }
  }
}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:19,代码来源:BlockSummary.java

示例4: searchBlockForPartner

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public void searchBlockForPartner(Block block) throws NullPointerException {
	if(this.head == null) {
		throw new NullPointerException("Block must not be null");
	}
	
	List<Transaction> listTxs = block.getTransactions();
	for(Transaction tx : listTxs) {
		System.out.println("test transaction " + tx.getHashAsString());
		if(isTransactionBroadcastAnnouncement(tx)) {
			broadcasts.add(tx);
			System.out.println("found a broadcast announcement!");
			System.out.println(tx);
		}
	}
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:16,代码来源:MixPartnerDiscovery.java

示例5: getNameTransaction

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
@Override
public Transaction getNameTransaction(String name, Sha256Hash blockHash, String identity) throws Exception {
    
    Block nameFullBlock = peerGroup.getDownloadPeer().getBlock(blockHash).get();
    
    // The full block hasn't been verified in any way!
    // So let's do that now.
    
    if (! nameFullBlock.getHash().equals(blockHash)) {
        throw new Exception("Block hash mismatch!");
    }
    
    // Now we know that the received block actually does have a header that matches the hash that we requested.
    // However, that doesn't mean that the block's contents are valid.
    
    final EnumSet<Block.VerifyFlag> flags = EnumSet.noneOf(Block.VerifyFlag.class);
    nameFullBlock.verify(-1, flags);
    
    // Now we know that the block is internally valid (including the merkle root).
    // We haven't verified signature validity, but our threat model is SPV.
    
    for (Transaction tx : nameFullBlock.getTransactions()) {
        if (NameTransactionUtils.getNameAnyUpdateOutput(tx, name) != null) {
            return tx;
        }
    }
    
    // The name wasn't found.
    return null;
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:31,代码来源:NameLookupByBlockHashOneFullBlock.java

示例6: getTransaction

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
@Override
public SerializedTransaction getTransaction(Sha256Hash hash)
{
  if (debug) System.out.println("Looking up tx: " + hash);
  long t1=System.nanoTime();
  Set<Sha256Hash> block_list = getTxToBlockMap(hash);
  //System.out.println("Get tx: " + hash + " - blocks: " + block_list);

  for(Sha256Hash block_hash : block_list)
  {
    SerializedBlock sb = getBlock(block_hash);
    if (sb != null)
    {
      Block b = sb.getBlock(network_parameters);

      for(Transaction tx : b.getTransactions())
      {
        if (tx.getHash().equals(hash))
        {
          TimeRecord.record(t1, "db_get_tx_found");
          return new SerializedTransaction(tx, b.getTime().getTime());
        }
      }

    }
  }
  TimeRecord.record(t1, "db_get_tx_not_found");
  return null;

}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:31,代码来源:LittleDB.java

示例7: run

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public void run()
{
    while(true)
    {
        Sha256Hash blk_hash = null;
        try
        {
            blk_hash = queue.take();
            String op = jelly.getDB().getBlockRescanMap().get(blk_hash);
            if ((op == null) || (!op.equals(rescan_operation)))
            {
                Block blk = jelly.getDB().getBlockMap().get(blk_hash).getBlock(jelly.getNetworkParameters());
                for(Transaction tx : blk.getTransactions())
                {
                    //jelly.getDB().getTransactionMap().put(tx.getHash(), new SerializedTransaction(tx));
                    //jelly.getImporter().putTxOutSpents(tx);
                    jelly.getImporter().putInternal(tx, blk.getHash());
                    transactions_scanned.incrementAndGet();
                }
                jelly.getDB().getBlockRescanMap().put(blk_hash, rescan_operation);
            }
            sem.release(1);
            blocks_scanned.incrementAndGet();


        }
        catch(Throwable t)
        {
            t.printStackTrace();
            if (blk_hash != null) queue.offer(blk_hash);
        }
    }

}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:35,代码来源:BlockRewrite.java

示例8: run

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public void run()
{
    while(true)
    {
        Sha256Hash blk_hash = null;
        try
        {
            blk_hash = queue.take();
            String op = jelly.getDB().getBlockRescanMap().get(blk_hash);
            if ((op == null) || (!op.equals(rescan_operation)))
            {
                Block blk = jelly.getDB().getBlockMap().get(blk_hash).getBlock(jelly.getNetworkParameters());
                for(Transaction tx : blk.getTransactions())
                {
                  SerializedTransaction tx2 = jelly.getDB().getTransactionMap().get(tx.getHash());
                  if (tx2 == null)
                  {
                    System.out.println("Transaction map does not contain " + tx.getHash());
                    System.exit(-1);
                  }
                  Collection<String> addresses = tx_util.getAllAddresses(tx, true, null);
                  for(String addr : addresses)
                  {
                    Set<Sha256Hash> tx_set = getAddressToTxSet(addr);
                    if (!tx_set.contains(tx.getHash()))
                    {
                      System.out.println("Address list for " + addr + " does not contain " + tx.getHash());
                      System.out.println(tx_set);
                      System.exit(-1);
                    }
                  }

                  Set<Sha256Hash> blk_set = jelly.getDB().getTxToBlockMap(tx.getHash());
                  if (!blk_set.contains(blk.getHash()))
                  {
                    System.out.println("TX Block list doesn't contain " + blk.getHash() + " for " + tx.getHash());
                    System.exit(-1);
                  }


                  transactions_scanned.incrementAndGet();
                }
                jelly.getDB().getBlockRescanMap().put(blk_hash, rescan_operation);
            }
            sem.release(1);
            blocks_scanned.incrementAndGet();


        }
        catch(Throwable t)
        {
            t.printStackTrace();
            if (blk_hash != null) queue.offer(blk_hash);
        }
    }

}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:58,代码来源:BlockMadScan.java

示例9: PerformanceRig

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public PerformanceRig(Config config)
  throws Exception
{
  Jelectrum jelly = new Jelectrum(config);

  int start_height = 375000;
  int items = 1000;


  TimeRecord tr = new TimeRecord();
  TimeRecord.setSharedRecord(tr);
  for(int h = start_height; h < start_height + items; h++)
  {
    long t1=0;
    Sha256Hash hash = jelly.getBlockChainCache().getBlockHashAtHeight(h);

    t1 = System.nanoTime();
    SerializedBlock s_blk = jelly.getDB().getBlockMap().get(hash);
    TimeRecord.record(t1, "get_serialized_block");

    t1 = System.nanoTime();
    Block blk = s_blk.getBlock( jelly.getNetworkParameters() );
    int sz = blk.getTransactions().size();
    HashSet<Sha256Hash> hashes = new HashSet<>();
    for(Transaction tx : blk.getTransactions())
    {
      hashes.add(tx.getHash());
    }
    TimeRecord.record(t1, "get_block");

    t1 = System.nanoTime();
    BlockSummary blk_sum = jelly.getDB().getBlockSummaryMap().get(hash);
    TimeRecord.record(t1, "get_block_summary");

    byte[] block_summary_serial = null;
  
    t1 = System.nanoTime();
    {
      ByteArrayOutputStream b_out = new ByteArrayOutputStream();
      ObjectOutputStream o_out = new ObjectOutputStream(b_out);
      o_out.writeObject(blk_sum);
      o_out.flush();

      byte[] b = b_out.toByteArray();
      TimeRecord.record(t1, "serialize_block_summary_size", b.length);
      block_summary_serial = b;
    }
    TimeRecord.record(t1, "serialize_block_summary");

    t1 = System.nanoTime();
    {
      ByteArrayInputStream b_in=new ByteArrayInputStream(block_summary_serial);
      ObjectInputStream o_in = new ObjectInputStream(b_in);

      BlockSummary blk_sum_read = (BlockSummary) o_in.readObject();
    }
    TimeRecord.record(t1, "deserialize_block_summary");

    t1 = System.nanoTime();
    ProtoBlockSummary proto_blk = blk_sum.getProto();
    TimeRecord.record(t1, "proto_create");

    t1 = System.nanoTime();
    ByteString proto_bytes = proto_blk.toByteString();
    TimeRecord.record(t1, "serialize_proto");
    TimeRecord.record(t1, "serialize_proto_size", proto_bytes.size());

    t1 = System.nanoTime();
    ProtoBlockSummary proto_blk_read = ProtoBlockSummary.parseFrom(proto_bytes);
    TimeRecord.record(t1, "deserialize_proto");
    


  }

  tr.printReport(System.out);


}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:80,代码来源:PerformanceRig.java

示例10: main

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception
{
  String config_path = args[0];
  Jelectrum jelly = new Jelectrum(new Config(config_path));

  int block_number = Integer.parseInt(args[1]);
  
  Sha256Hash block_hash = jelly.getBlockChainCache().getBlockHashAtHeight(block_number);
  System.out.println("Block hash: " + block_hash);
  Block b = jelly.getDB().getBlock(block_hash).getBlock(jelly.getNetworkParameters());
  System.out.println("Inspecting " + block_number + " - " + block_hash);

  int tx_count =0;
  int out_count =0;
  for(Transaction tx : b.getTransactions())
  {
    int idx=0;
    for(TransactionOutput tx_out : tx.getOutputs())
    {
      byte[] pub_key_bytes=getPublicKeyForTxOut(tx_out, jelly.getNetworkParameters());

      String public_key = null;
      if (pub_key_bytes != null) public_key = Hex.encodeHexString(pub_key_bytes);
      else public_key = "None";
      
      String script_bytes = Hex.encodeHexString(tx_out.getScriptBytes());

      String[] cmd=new String[3];
      cmd[0]="python";
      cmd[1]=jelly.getConfig().get("utxo_check_tool");
      cmd[2]=script_bytes;

      //System.out.println(script_bytes);

      Process p = Runtime.getRuntime().exec(cmd);

      Scanner scan = new Scanner(p.getInputStream());
      String ele_key = scan.nextLine();

      if (!ele_key.equals(public_key))
      {
        System.out.println("Mismatch on " + tx_out.getParentTransaction().getHash() + ":" + idx);
        System.out.println("  Script: " + script_bytes);
        System.out.println("  Jelectrum: " + public_key);
        System.out.println("  Electrum:  " + ele_key);

      }

      out_count++;
      idx++;
    }
    tx_count++;
  }
  System.out.println("TX Count: " + tx_count);
  System.out.println("Out Count: " + out_count);


}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:59,代码来源:UtxoTrieMgr.java


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