use of org.tron.core.exception.BalanceInsufficientException 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.core.exception.BalanceInsufficientException 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);
}
}
use of org.tron.core.exception.BalanceInsufficientException in project java-tron by tronprotocol.
the class Manager method adjustBalance.
/**
* judge balance.
*/
public void adjustBalance(byte[] accountAddress, long amount) throws BalanceInsufficientException {
AccountCapsule account = getAccountStore().get(accountAddress);
long balance = account.getBalance();
if (amount == 0) {
return;
}
if (amount < 0 && balance < -amount) {
throw new BalanceInsufficientException(accountAddress + " Insufficient");
}
account.setBalance(balance + amount);
this.getAccountStore().put(account.getAddress().toByteArray(), account);
}
use of org.tron.core.exception.BalanceInsufficientException in project java-tron by tronprotocol.
the class TransferActuator method execute.
@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
long fee = calcFee();
try {
TransferContract transferContract = null;
transferContract = contract.unpack(TransferContract.class);
dbManager.adjustBalance(transferContract.getOwnerAddress().toByteArray(), -calcFee());
ret.setStatus(fee, code.SUCESS);
dbManager.adjustBalance(transferContract.getOwnerAddress().toByteArray(), -transferContract.getAmount());
dbManager.adjustBalance(transferContract.getToAddress().toByteArray(), transferContract.getAmount());
} catch (InvalidProtocolBufferException e) {
logger.debug(e.getMessage(), e);
ret.setStatus(fee, code.FAILED);
throw new ContractExeException(e.getMessage());
} catch (BalanceInsufficientException e) {
logger.debug(e.getMessage(), e);
ret.setStatus(fee, code.FAILED);
throw new ContractExeException(e.getMessage());
}
return true;
}
Aggregations