apply_transfer

@mount("ft4.crosschain.apply_transfer") operation apply_transfer(init_transfer_tx: gtx_transaction, init_tx_op_index: integer, previous_hop_tx: gtx_transaction, op_index: integer, hop_index: integer)(source)

This operation must be called on every chain listed in the hops array provided to the init_transfer function which corresponds to this transfer.

When this is done, one of two things will happen:

  • If this is an intermediary hop, this chain will update its internal record of which chain that owns how much of what asset

  • If this is the final hop, the transferred amount will be credited to the recipient account

In the case where this is the last hop and the recipient account does not exist, one of two things can happen:

  • If the create on transfer account creation strategy is enabled, the assets will be received and the recipient will be able create the account and claim them.

  • If the feature is not enabled, the transfer will be rejected, in which case, the sender can get their assets back by calling the cancel_transfer in the reverse hops order.

Anyone can call this operation on behalf of any transfer, but it needs to include an iccf_proof operation which prove that the transaction was applied in the previous hop.

The functionality provided by apply_transfer can be modified by extending before_apply_transfer and after_apply_transfer

Throws "TRANSFER EXPIRED"` if deadline is a past timestamp

Throws "MISSING ACCOUNT" if all these conditions apply:

  • this chain is the last chain in the crosschain transaction

  • the account corresponding to recipient_id does not exist

  • creating account on crosschain transfer is not enabled on this chain

Throws if additional conditions provided through extensions of before_apply_transfer and after_apply_transfer are not satisfied

Throws if the current transfer is misconfigured. Common cases are:

  • the next hop or the previous one are:

    • equal to one another

    • this blockchain's RID

    • the ID of an account on this chain which is not a blockchain account

  • amount is:

    • not in the accepted range (0, 2^256) (exclusive)

    • higher than the blockchain account balance they're coming from

  • the asset is not registered on this chain

  • input is malformed:

    • arguments found in init_transfer_tx and previous_hop_tx do not match

    • hop_index is out of bounds

    • previous_hop_tx has not been sent to the chain that comes before this one on the transfer hops

  • the transfer has already been applied, canceled or unapplied on this chain.

  • the chain at hop_index on the init transaction is not this chain

  • the op_index on previous_hop_tx does not point to:

    • init_transfer when hop_index is 0

    • apply_transfer otherwise

  • the init_tx_op_index does not point to init_transfer on its init_transfer_tx

  • the operation preceding init_transfer is not an auth operation

Throws if all these conditions apply:

  • this chain is the last chain in the crosschain transaction

  • the account corresponding to recipient_id does not exist

  • creating account on crosschain transfer is enabled on this chain

  • the function implementing the account creation strategy being used (extension of create_on_crosschain_transfer) has conditions which are not satisfied

Throws if the transaction is missing the iccf_proof operation, which demonstrates that the block containing the previous_hop_tx has been anchored from the previous chain.

Requires no flags - no authorization is performed to apply a transfer.

Parameters

init_transfer_tx

the gtx_transaction that represents the tx containing the init_transfer operation on the initial chain

init_tx_op_index

the index of the init_transfer operation in init_transfer_tx

previous_hop_tx

the tx containing the init_transfer or apply_transfer operation from the previous step. In the first hop, init_transfer_tx and this argument will be the same

op_index

the index of the apply_transfer operation in previous_hop_tx

hop_index

which index in the hops array provided in the original transaction this chain represents.

See also

core.auth.is_auth_op

for information on auth operations

core.crosschain.before_apply_transfer

to add custom logic before this operation

core.crosschain.after_apply_transfer

to add custom logic after this operation

core.crosschain.applied_transfers

to know more about the crosschain transfer workflow

core.crosschain.is_create_on_crosschain_transfer_enabled

to know more about account creation on crosschain transfer