Search in sources :

Example 1 with TokensInAccount

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();
}
Also used : TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount)

Example 2 with TokensInAccount

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();
}
Also used : TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount)

Example 3 with TokensInAccount

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();
}
Also used : TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount)

Example 4 with TokensInAccount

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();
}
Also used : TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount)

Example 5 with TokensInAccount

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);
}
Also used : TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount)

Aggregations

TokensInAccount (com.radixdlt.application.tokens.state.TokensInAccount)7 SystemConstraintScrypt (com.radixdlt.application.system.scrypt.SystemConstraintScrypt)1 TokenResource (com.radixdlt.application.tokens.state.TokenResource)1 TokenResourceMetadata (com.radixdlt.application.tokens.state.TokenResourceMetadata)1 REFieldSerialization (com.radixdlt.atom.REFieldSerialization)1 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)1 ConstraintScrypt (com.radixdlt.atomos.ConstraintScrypt)1 Loader (com.radixdlt.atomos.Loader)1 SubstateDefinition (com.radixdlt.atomos.SubstateDefinition)1 com.radixdlt.constraintmachine (com.radixdlt.constraintmachine)1 ResourceCreatedEvent (com.radixdlt.constraintmachine.REEvent.ResourceCreatedEvent)1 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)1 ReservedSymbolException (com.radixdlt.constraintmachine.exceptions.ReservedSymbolException)1 DeserializeException (com.radixdlt.serialization.DeserializeException)1 UInt256 (com.radixdlt.utils.UInt256)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1