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);
}
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);
}
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;
}
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());
}
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);
}
}
Aggregations