use of com.radixdlt.application.tokens.state.TokensInAccount in project radixdlt by radixdlt.
the class SplitTokenConstructor method construct.
@Override
public void construct(SplitToken action, TxBuilder txBuilder) throws TxBuilderException {
var userAccount = action.userAcct();
var tokens = txBuilder.downSubstate(TokensInAccount.class, p -> p.resourceAddr().equals(action.rri()) && p.holdingAddress().equals(userAccount) && p.amount().compareTo(action.minSize()) > 0);
var amt1 = tokens.amount().divide(UInt256.TWO);
var amt2 = tokens.amount().subtract(amt1);
txBuilder.up(new TokensInAccount(userAccount, action.rri(), amt1));
txBuilder.up(new TokensInAccount(userAccount, action.rri(), amt2));
txBuilder.end();
}
use of com.radixdlt.application.tokens.state.TokensInAccount in project radixdlt by radixdlt.
the class BurnTokenConstructor method construct.
@Override
public void construct(BurnToken action, TxBuilder txBuilder) throws TxBuilderException {
var buf = ByteBuffer.allocate(2 + 1 + ECPublicKey.COMPRESSED_BYTES);
buf.put(SubstateTypeId.TOKENS.id());
buf.put((byte) 0);
buf.put(action.fromAddr().getBytes());
var index = SubstateIndex.create(buf.array(), TokensInAccount.class);
var change = txBuilder.downFungible(index, p -> p.resourceAddr().equals(action.resourceAddr()) && p.holdingAddress().equals(action.fromAddr()), action.amount(), available -> {
var from = AccountBucket.from(action.resourceAddr(), action.fromAddr());
return new NotEnoughResourcesException(from, action.amount(), available);
});
if (!change.isZero()) {
txBuilder.up(new TokensInAccount(action.fromAddr(), action.resourceAddr(), change));
}
txBuilder.end();
}
use of com.radixdlt.application.tokens.state.TokensInAccount in project radixdlt by radixdlt.
the class TransferTokensConstructorV2 method construct.
@Override
public void construct(TransferToken action, TxBuilder txBuilder) throws TxBuilderException {
var buf = ByteBuffer.allocate(2 + 1 + ECPublicKey.COMPRESSED_BYTES);
buf.put(SubstateTypeId.TOKENS.id());
buf.put((byte) 0);
buf.put(action.fromAddr().getBytes());
var index = SubstateIndex.create(buf.array(), TokensInAccount.class);
var change = txBuilder.downFungible(index, p -> p.resourceAddr().equals(action.resourceAddr()) && p.holdingAddress().equals(action.fromAddr()), action.amount(), available -> {
var from = AccountBucket.from(action.resourceAddr(), action.fromAddr());
return new NotEnoughResourcesException(from, action.amount(), available);
});
if (!change.isZero()) {
txBuilder.up(new TokensInAccount(action.fromAddr(), action.resourceAddr(), change));
}
txBuilder.up(new TokensInAccount(action.toAddr(), action.resourceAddr(), action.amount()));
txBuilder.end();
}
use of com.radixdlt.application.tokens.state.TokensInAccount in project radixdlt by radixdlt.
the class MintTokenConstructor method construct.
@Override
public void construct(MintToken action, TxBuilder txBuilder) throws TxBuilderException {
txBuilder.up(new TokensInAccount(action.toAddr(), action.resourceAddr(), action.amount()));
txBuilder.end();
}
use of com.radixdlt.application.tokens.state.TokensInAccount in project radixdlt by radixdlt.
the class TxBuilder method takeFeeReserve.
public void takeFeeReserve(REAddr addr, UInt256 amount) {
lowLevelBuilder.syscall(Syscall.FEE_RESERVE_TAKE, amount);
if (!amount.isZero()) {
up(new TokensInAccount(addr, REAddr.ofNativeToken(), amount));
}
this.feeReserveTake = this.feeReserveTake.add(amount);
}
Aggregations