Search in sources :

Example 31 with AccountCapsule

use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.

the class TransferAssetActuatorTest method createCapsule.

/**
 * create temp Capsule test need.
 */
@Before
public void createCapsule() {
    AccountCapsule ownerCapsule = new AccountCapsule(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)), ByteString.copyFromUtf8("owner"), AccountType.AssetIssue);
    ownerCapsule.addAsset(ASSET_NAME, 10000L);
    AccountCapsule toAccountCapsule = new AccountCapsule(ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS)), ByteString.copyFromUtf8("toAccount"), AccountType.Normal);
    AssetIssueContract assetIssueContract = AssetIssueContract.newBuilder().setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))).setName(ByteString.copyFrom(ByteArray.fromString(ASSET_NAME))).setTotalSupply(TOTAL_SUPPLY).setTrxNum(TRX_NUM).setNum(NUM).setStartTime(START_TIME).setEndTime(END_TIME).setDecayRatio(DECAY_RATIO).setVoteScore(VOTE_SCORE).setDescription(ByteString.copyFrom(ByteArray.fromString(DESCRIPTION))).setUrl(ByteString.copyFrom(ByteArray.fromString(URL))).build();
    AssetIssueCapsule assetIssueCapsule = new AssetIssueCapsule(assetIssueContract);
    dbManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
    dbManager.getAccountStore().put(toAccountCapsule.getAddress().toByteArray(), toAccountCapsule);
    dbManager.getAssetIssueStore().put(assetIssueCapsule.getName().toByteArray(), assetIssueCapsule);
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) AssetIssueCapsule(org.tron.core.capsule.AssetIssueCapsule) AssetIssueContract(org.tron.protos.Contract.AssetIssueContract) Before(org.junit.Before)

Example 32 with AccountCapsule

use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.

the class AccountStoreTest method init.

@BeforeClass
public static void init() {
    Args.setParam(new String[] { "-d", dbPath, "-w" }, Configuration.getByPath(Constant.TEST_CONF));
    AccountStoreTest = AccountStore.create(dbPath);
    AccountCapsule accountCapsule = new AccountCapsule(ByteString.copyFrom(address), ByteString.copyFrom(accountName), AccountType.forNumber(1));
    AccountStoreTest.put(data, accountCapsule);
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) BeforeClass(org.junit.BeforeClass)

Example 33 with AccountCapsule

use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.

the class AccountVoteWitnessTest method getAccountList.

private List<AccountCapsule> getAccountList() {
    final List<AccountCapsule> accountCapsuleList = Lists.newArrayList();
    final AccountCapsule accountTron = new AccountCapsule(ByteString.copyFrom("00000000001".getBytes()), ByteString.copyFromUtf8("Tron"), AccountType.Normal);
    final AccountCapsule accountMarcus = new AccountCapsule(ByteString.copyFrom("00000000002".getBytes()), ByteString.copyFromUtf8("Marcus"), AccountType.Normal);
    final AccountCapsule accountOlivier = new AccountCapsule(ByteString.copyFrom("00000000003".getBytes()), ByteString.copyFromUtf8("Olivier"), AccountType.Normal);
    final AccountCapsule accountSasaXie = new AccountCapsule(ByteString.copyFrom("00000000004".getBytes()), ByteString.copyFromUtf8("SasaXie"), AccountType.Normal);
    final AccountCapsule accountVivider = new AccountCapsule(ByteString.copyFrom("00000000005".getBytes()), ByteString.copyFromUtf8("Vivider"), AccountType.Normal);
    // accountTron addVotes
    accountTron.addVotes(accountMarcus.getAddress(), 100);
    accountTron.addVotes(accountOlivier.getAddress(), 100);
    accountTron.addVotes(accountSasaXie.getAddress(), 100);
    accountTron.addVotes(accountVivider.getAddress(), 100);
    // accountMarcus addVotes
    accountMarcus.addVotes(accountTron.getAddress(), 100);
    accountMarcus.addVotes(accountOlivier.getAddress(), 100);
    accountMarcus.addVotes(accountSasaXie.getAddress(), 100);
    accountMarcus.addVotes(ByteString.copyFrom("00000000006".getBytes()), 100);
    accountMarcus.addVotes(ByteString.copyFrom("00000000007".getBytes()), 100);
    // accountOlivier addVotes
    accountOlivier.addVotes(accountTron.getAddress(), 100);
    accountOlivier.addVotes(accountMarcus.getAddress(), 100);
    accountOlivier.addVotes(accountSasaXie.getAddress(), 100);
    accountOlivier.addVotes(accountVivider.getAddress(), 100);
    // accountSasaXie addVotes
    // accountVivider addVotes
    accountCapsuleList.add(accountTron);
    accountCapsuleList.add(accountMarcus);
    accountCapsuleList.add(accountOlivier);
    accountCapsuleList.add(accountSasaXie);
    accountCapsuleList.add(accountVivider);
    return accountCapsuleList;
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule)

Example 34 with AccountCapsule

use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.

the class AccountVoteWitnessTest method printAccount.

private void printAccount(final ByteString address) {
    final AccountCapsule accountCapsule = dbManager.getAccountStore().get(address.toByteArray());
    if (null == accountCapsule) {
        logger.info("address is {}  , account is null", address.toStringUtf8());
        return;
    }
    logger.info("address is {}  ,countVoteSize is {}", accountCapsule.getAddress().toStringUtf8(), accountCapsule.getVotesList().size());
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule)

Example 35 with AccountCapsule

use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.

the class Manager method updateSignedWitness.

/**
 * @param block the block update signed witness.  set witness who signed block the 1. the latest
 * block num 2. pay the trx to witness. 3. (TODO)the latest slot num.
 */
public void updateSignedWitness(BlockCapsule block) {
    // TODO: add verification
    WitnessCapsule witnessCapsule = witnessStore.get(block.getInstance().getBlockHeader().getRawData().getWitnessAddress().toByteArray());
    long latestSlotNum = 0;
    witnessCapsule.getInstance().toBuilder().setLatestBlockNum(block.getNum()).setLatestSlotNum(latestSlotNum).build();
    AccountCapsule sun = accountStore.getSun();
    try {
        adjustBalance(sun.getAddress().toByteArray(), -WITNESS_PAY_PER_BLOCK);
    } catch (BalanceInsufficientException e) {
    }
    try {
        adjustBalance(witnessCapsule.getAddress().toByteArray(), WITNESS_PAY_PER_BLOCK);
    } catch (BalanceInsufficientException e) {
        logger.debug(e.getMessage(), e);
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) WitnessCapsule(org.tron.core.capsule.WitnessCapsule) BalanceInsufficientException(org.tron.core.exception.BalanceInsufficientException)

Aggregations

AccountCapsule (org.tron.core.capsule.AccountCapsule)42 ContractExeException (org.tron.core.exception.ContractExeException)22 ContractValidateException (org.tron.core.exception.ContractValidateException)20 TransactionResultCapsule (org.tron.core.capsule.TransactionResultCapsule)16 Test (org.junit.Test)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 DateTime (org.joda.time.DateTime)7 ByteString (com.google.protobuf.ByteString)5 Before (org.junit.Before)5 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)5 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)5 WitnessCapsule (org.tron.core.capsule.WitnessCapsule)3 Args (org.tron.core.config.args.Args)3 GenesisBlock (org.tron.core.config.args.GenesisBlock)3 Contract (org.tron.protos.Contract)3 AccountStore (org.tron.core.db.AccountStore)2 TransferAssetContract (org.tron.protos.Contract.TransferAssetContract)2 RamUsageEstimator (com.carrotsearch.sizeof.RamUsageEstimator)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1