use of org.tron.protos.Contract.AssetIssueContract in project java-tron by tronprotocol.
the class AssetIssueActuator method execute.
@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
long fee = calcFee();
try {
if (!this.contract.is(AssetIssueContract.class)) {
throw new ContractExeException();
}
if (dbManager == null) {
throw new ContractExeException();
}
AssetIssueContract assetIssueContract = contract.unpack(AssetIssueContract.class);
AssetIssueCapsule assetIssueCapsule = new AssetIssueCapsule(assetIssueContract);
dbManager.getAssetIssueStore().put(assetIssueCapsule.getName().toByteArray(), assetIssueCapsule);
dbManager.adjustBalance(assetIssueContract.getOwnerAddress().toByteArray(), -calcFee());
ret.setStatus(fee, code.SUCESS);
AccountCapsule accountCapsule = dbManager.getAccountStore().get(assetIssueContract.getOwnerAddress().toByteArray());
accountCapsule.addAsset(ByteArray.toStr(assetIssueContract.getName().toByteArray()), assetIssueContract.getTotalSupply());
dbManager.getAccountStore().put(assetIssueContract.getOwnerAddress().toByteArray(), accountCapsule);
} catch (InvalidProtocolBufferException e) {
ret.setStatus(fee, code.FAILED);
throw new ContractExeException();
} catch (BalanceInsufficientException e) {
ret.setStatus(fee, code.FAILED);
throw new ContractExeException();
}
return true;
}
use of org.tron.protos.Contract.AssetIssueContract in project java-tron by tronprotocol.
the class ParticipateAssetIssueActuatorTest method initAssetIssue.
private void initAssetIssue(long startTimestmp, long endTimestmp) {
AssetIssueContract assetIssueContract = AssetIssueContract.newBuilder().setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS))).setName(ByteString.copyFrom(ByteArray.fromString(ASSET_NAME))).setTotalSupply(TOTAL_SUPPLY).setTrxNum(TRX_NUM).setNum(NUM).setStartTime(startTimestmp).setEndTime(endTimestmp).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.getAssetIssueStore().put(assetIssueCapsule.getName().toByteArray(), assetIssueCapsule);
}
use of org.tron.protos.Contract.AssetIssueContract 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.protos.Contract.AssetIssueContract in project java-tron by tronprotocol.
the class AssetIssueActuator method validate.
@Override
public boolean validate() throws ContractValidateException {
if (!this.contract.is(AssetIssueContract.class)) {
throw new ContractValidateException();
}
try {
final AssetIssueContract assetIssueContract = this.contract.unpack(AssetIssueContract.class);
Preconditions.checkNotNull(assetIssueContract.getOwnerAddress(), "OwnerAddress is null");
Preconditions.checkNotNull(assetIssueContract.getName(), "name is null");
if (this.dbManager.getAssetIssueStore().get(assetIssueContract.getName().toByteArray()) != null) {
throw new ContractValidateException();
}
} catch (InvalidProtocolBufferException e) {
throw new ContractValidateException();
}
return false;
}
Aggregations