Package com.bitsofproof.supernode.common

Examples of com.bitsofproof.supernode.common.Hash


      MessageProducer blockHeaderRequestProducer = session.createProducer (session.createQueue ("headerRequest"));

      BytesMessage m = session.createBytesMessage ();
      BCSAPIMessage.Hash.Builder builder = BCSAPIMessage.Hash.newBuilder ();
      builder.setBcsapiversion (1);
      builder.addHash (ByteString.copyFrom (new Hash (hash).toByteArray ()));
      m.writeBytes (builder.build ().toByteArray ());
      byte[] response = synchronousRequest (session, blockHeaderRequestProducer, m);
      if ( response != null )
      {
        Block b = Block.fromProtobuf (BCSAPIMessage.Block.parseFrom (response));
View Full Code Here


    {
      ArrayList<byte[]> tree = new ArrayList<byte[]> ();
      for ( Transaction t : transactions )
      {
        t.computeHash ();
        tree.add (new Hash (t.getHash ()).toByteArray ());
      }
      BinaryAggregator<byte[]> aggregator = new BinaryAggregator<byte[]> ()
      {
        @Override
        public byte[] merge (byte[] a, byte[] b)
        {
          try
          {
            MessageDigest digest = MessageDigest.getInstance ("SHA-256");
            digest.update (a);
            return digest.digest (digest.digest (b));
          }
          catch ( NoSuchAlgorithmException e )
          {
            return null;
          }
        }
      };
      merkleRoot = new Hash (aggregator.aggregate (tree)).toString ();
    }
  }
View Full Code Here

  }

  public void toWireHeaderOnly (WireFormat.Writer writer)
  {
    writer.writeUint32 (version);
    writer.writeHash (new Hash (previousHash));
    writer.writeHash (new Hash (merkleRoot));
    writer.writeUint32 (createTime);
    writer.writeUint32 (difficultyTarget);
    writer.writeUint32 (nonce);
  }
View Full Code Here

    builder.setBcsapiversion (1);
    builder.setVersion ((int) version);
    builder.setDifficulty ((int) difficultyTarget);
    builder.setNonce ((int) nonce);
    builder.setTimestamp ((int) createTime);
    builder.setMerkleRoot (ByteString.copyFrom (new Hash (merkleRoot).toByteArray ()));
    builder.setPreviousBlock (ByteString.copyFrom (new Hash (previousHash).toByteArray ()));
    if ( transactions != null )
    {
      for ( Transaction t : transactions )
      {
        builder.addTransactions (t.toProtobuf ());
View Full Code Here

    Block block = new Block ();
    block.setVersion (pb.getVersion ());
    block.setDifficultyTarget (pb.getDifficulty ());
    block.setNonce (pb.getNonce ());
    block.setCreateTime (pb.getTimestamp ());
    block.setPreviousHash (new Hash (pb.getPreviousBlock ().toByteArray ()).toString ());
    block.setMerkleRoot (new Hash (pb.getMerkleRoot ().toByteArray ()).toString ());
    if ( pb.getTransactionsCount () > 0 )
    {
      block.setTransactions (new ArrayList<Transaction> ());
      for ( BCSAPIMessage.Transaction t : pb.getTransactionsList () )
      {
View Full Code Here

TOP

Related Classes of com.bitsofproof.supernode.common.Hash

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.