# Invocation
Structure that contains fields of a script invocation that can be used by the callable function.
# Constructor
Invocation(payments: List[ AttachedPayment], caller: Address, callerPublicKey: ByteVector, transactionId: ByteVector, fee: Int, feeAssetId: ByteVector|Unit, originCaller: Address, originCallerPublicKey: ByteVector)
# Fields
The field values depend on how the callable function is invoked.
If the script is invoked by an Invoke Script transaction or an Ethereum transaction:
# | Name | Data type | Description |
---|---|---|---|
1 | payments | List[AttachedPayment] | Payments indicated in the transaction |
2 | caller | Address | Address of the account that sent the transaction |
3 | callerPublicKey | ByteVector | Public key of the account that sent the transaction |
4 | transactionId | ByteVector | ID of the transaction |
5 | fee | Int | Transaction fee |
6 | feeAssetId | ByteVector|Unit | ID of a token to pay the fee. unit means WAVES |
7 | originCaller | Address | Duplicates the caller field |
8 | originCallerPublicKey | ByteVector | Duplicates the callerPublicKey field |
If the callable function is invoked by the invoke
or reentrantInvoke
function (see the dApp-to-dApp invocation article):
# | Name | Data type | Description |
---|---|---|---|
1 | payments | List[AttachedPayment] | Payments indicated in the invoke or reentrantInvoke function |
2 | caller | Address | Address of the dApp that invokes the callable function |
3 | callerPublicKey | ByteVector | Public key of the dApp that invokes the callable function |
4 | transactionId | ByteVector | ID of the transaction |
5 | fee | Int | Transaction fee |
6 | feeAssetId | ByteVector|Unit | ID of a token to pay the fee. unit means WAVES |
7 | originCaller | Address | Address of the account that sent the transaction |
8 | originCallerPublicKey | ByteVector | Public key of the account that sent the transaction |
The
originCaller
,originCallerPublicKey
,transactionId
,fee
, andfeeAssetId
values are the same for all dApp-to-dApp invocations within a single transaction.
# Example: Payments Processing
The following function checks that the first payment in the transaction is at least 1 WAVES or 5 in the specified asset.
{-# STDLIB_VERSION 8 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
func isPaymentOk(i: Invocation) = {
let acceptableAssetId = base58'3JmaWyFqWo8YSA8x3DXCBUW7veesxacvKx19dMv7wTMg'
if (size(i.payments) == 0) then {
throw("Payment not attached")
} else {
let p = i.payments[0]
match p.assetId {
case assetId: ByteVector => assetId == acceptableAssetId && p.amount >= 500000000
case _ => p.amount >= 100000000
}
}
}
@Callable(i)
func foo() = {
if isPaymentOk(i) then ([],unit) else throw("Wrong payment amount or asset")
}