use of org.tron.core.config.args.GenesisBlock in project java-tron by tronprotocol.
the class Manager method initWitness.
/**
* save witnesses into database.
*/
private void initWitness() {
final Args args = Args.getInstance();
final GenesisBlock genesisBlockArg = args.getGenesisBlock();
genesisBlockArg.getWitnesses().forEach(key -> {
byte[] keyAddress = ByteArray.fromHexString(key.getAddress());
ByteString address = ByteString.copyFrom(keyAddress);
if (!this.accountStore.has(keyAddress)) {
final AccountCapsule accountCapsule = new AccountCapsule(ByteString.EMPTY, address, AccountType.AssetIssue, 0L);
this.accountStore.put(keyAddress, accountCapsule);
}
final WitnessCapsule witnessCapsule = new WitnessCapsule(address, key.getVoteCount(), key.getUrl());
witnessCapsule.setIsJobs(true);
this.witnessStore.put(keyAddress, witnessCapsule);
this.wits.add(witnessCapsule);
});
}
use of org.tron.core.config.args.GenesisBlock in project java-tron by tronprotocol.
the class Manager method initAccount.
/**
* save account into database.
*/
public void initAccount() {
final Args args = Args.getInstance();
final GenesisBlock genesisBlockArg = args.getGenesisBlock();
genesisBlockArg.getAssets().forEach(account -> {
// to be set in conf
account.setAccountType("Normal");
final AccountCapsule accountCapsule = new AccountCapsule(account.getAccountName(), ByteString.copyFrom(account.getAddressBytes()), account.getAccountType(), account.getBalance());
this.accountStore.put(account.getAddressBytes(), accountCapsule);
});
}
use of org.tron.core.config.args.GenesisBlock 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;
}
Aggregations