Search in sources :

Example 1 with Args

use of org.tron.core.config.args.Args 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);
    });
}
Also used : GenesisBlock(org.tron.core.config.args.GenesisBlock) AccountCapsule(org.tron.core.capsule.AccountCapsule) Args(org.tron.core.config.args.Args) WitnessCapsule(org.tron.core.capsule.WitnessCapsule) ByteString(com.google.protobuf.ByteString)

Example 2 with Args

use of org.tron.core.config.args.Args in project java-tron by tronprotocol.

the class FullNode method main.

/**
 * Start the FullNode.
 */
public static void main(String[] args) throws InterruptedException {
    Args.setParam(args, Configuration.getByPath(Constant.NORMAL_CONF));
    Args cfgArgs = Args.getInstance();
    ApplicationContext context = new AnnotationConfigApplicationContext(DefaultConfig.class);
    if (cfgArgs.isHelp()) {
        logger.info("Here is the help message.");
        return;
    }
    logger.info("Here is the help message." + cfgArgs.getOutputDirectory());
    Application appT = ApplicationFactory.create(context);
    // appT.init(cfgArgs);
    RpcApiService rpcApiService = new RpcApiService(appT);
    appT.addService(rpcApiService);
    if (cfgArgs.isWitness()) {
        appT.addService(new WitnessService(appT));
    }
    appT.initServices(cfgArgs);
    appT.startServices();
    appT.startup();
    rpcApiService.blockUntilShutdown();
}
Also used : Args(org.tron.core.config.args.Args) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) WitnessService(org.tron.core.services.WitnessService) Application(org.tron.common.application.Application) RpcApiService(org.tron.core.services.RpcApiService)

Example 3 with Args

use of org.tron.core.config.args.Args 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);
    });
}
Also used : GenesisBlock(org.tron.core.config.args.GenesisBlock) AccountCapsule(org.tron.core.capsule.AccountCapsule) Args(org.tron.core.config.args.Args)

Example 4 with Args

use of org.tron.core.config.args.Args in project java-tron by tronprotocol.

the class Manager method getHomeNode.

public Node getHomeNode() {
    final Args args = Args.getInstance();
    Set<Node> nodes = this.peersStore.get("home".getBytes());
    if (nodes.size() > 0) {
        return nodes.stream().findFirst().get();
    } else {
        Node node = new Node(new ECKey().getNodeId(), args.getNodeExternalIp(), args.getNodeListenPort());
        nodes.add(node);
        this.peersStore.put("home".getBytes(), nodes);
        return node;
    }
}
Also used : Args(org.tron.core.config.args.Args) Node(org.tron.common.overlay.discover.Node) ECKey(org.tron.common.crypto.ECKey)

Example 5 with Args

use of org.tron.core.config.args.Args 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

Args (org.tron.core.config.args.Args)5 GenesisBlock (org.tron.core.config.args.GenesisBlock)3 ByteString (com.google.protobuf.ByteString)2 AccountCapsule (org.tron.core.capsule.AccountCapsule)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Application (org.tron.common.application.Application)1 ECKey (org.tron.common.crypto.ECKey)1 Node (org.tron.common.overlay.discover.Node)1 ByteArray (org.tron.common.utils.ByteArray)1 BlockCapsule (org.tron.core.capsule.BlockCapsule)1 WitnessCapsule (org.tron.core.capsule.WitnessCapsule)1 RpcApiService (org.tron.core.services.RpcApiService)1 WitnessService (org.tron.core.services.WitnessService)1 Transaction (org.tron.protos.Protocol.Transaction)1