Search in sources :

Example 1 with Transaction

use of org.tron.protos.Protocol.Transaction in project java-tron by tronprotocol.

the class BlockUtil method newGenesisBlockCapsule.

/**
 * create genesis block from transactions.
 */
public static BlockCapsule newGenesisBlockCapsule() {
    Args args = Args.getInstance();
    GenesisBlock genesisBlockArg = args.getGenesisBlock();
    List<Transaction> transactionList = genesisBlockArg.getAssets().stream().map(key -> {
        String address = key.getAddress();
        long balance = key.getBalance();
        return TransactionUtil.newGenesisTransaction(address, balance);
    }).collect(Collectors.toList());
    long timestamp = Long.parseLong(genesisBlockArg.getTimestamp());
    ByteString parentHash = ByteString.copyFrom(ByteArray.fromHexString(genesisBlockArg.getParentHash()));
    long number = Long.parseLong(genesisBlockArg.getNumber());
    BlockCapsule blockCapsule = new BlockCapsule(timestamp, parentHash, number, transactionList);
    blockCapsule.setMerkleRoot();
    blockCapsule.generatedByMyself = true;
    return blockCapsule;
}
Also used : GenesisBlock(org.tron.core.config.args.GenesisBlock) ByteString(com.google.protobuf.ByteString) Transaction(org.tron.protos.Protocol.Transaction) List(java.util.List) GenesisBlock(org.tron.core.config.args.GenesisBlock) Args(org.tron.core.config.args.Args) ByteArray(org.tron.common.utils.ByteArray) BlockCapsule(org.tron.core.capsule.BlockCapsule) Collectors(java.util.stream.Collectors) Args(org.tron.core.config.args.Args) Transaction(org.tron.protos.Protocol.Transaction) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) BlockCapsule(org.tron.core.capsule.BlockCapsule)

Aggregations

ByteString (com.google.protobuf.ByteString)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ByteArray (org.tron.common.utils.ByteArray)1 BlockCapsule (org.tron.core.capsule.BlockCapsule)1 Args (org.tron.core.config.args.Args)1 GenesisBlock (org.tron.core.config.args.GenesisBlock)1 Transaction (org.tron.protos.Protocol.Transaction)1