Search in sources :

Example 1 with AssetIssueContract

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;
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) BalanceInsufficientException(org.tron.core.exception.BalanceInsufficientException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AssetIssueCapsule(org.tron.core.capsule.AssetIssueCapsule) AssetIssueContract(org.tron.protos.Contract.AssetIssueContract) ContractExeException(org.tron.core.exception.ContractExeException)

Example 2 with AssetIssueContract

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);
}
Also used : AssetIssueCapsule(org.tron.core.capsule.AssetIssueCapsule) AssetIssueContract(org.tron.protos.Contract.AssetIssueContract)

Example 3 with AssetIssueContract

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);
}
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 4 with AssetIssueContract

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;
}
Also used : ContractValidateException(org.tron.core.exception.ContractValidateException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AssetIssueContract(org.tron.protos.Contract.AssetIssueContract)

Aggregations

AssetIssueContract (org.tron.protos.Contract.AssetIssueContract)4 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 AccountCapsule (org.tron.core.capsule.AccountCapsule)2 Before (org.junit.Before)1 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)1 ContractExeException (org.tron.core.exception.ContractExeException)1 ContractValidateException (org.tron.core.exception.ContractValidateException)1