pub fn encode_peer_to_peer_with_metadata_script(
    currency: TypeTag,
    payee: AccountAddress,
    amount: u64,
    metadata: Vec<u8>,
    metadata_signature: Vec<u8>
) -> Script
Expand description

Summary

Transfers a given number of coins in a specified currency from one account to another. Transfers over a specified amount defined on-chain that are between two different VASPs, or other accounts that have opted-in will be subject to on-chain checks to ensure the receiver has agreed to receive the coins. This transaction can be sent by any account that can hold a balance, and to any account that can hold a balance. Both accounts must hold balances in the currency being transacted.

Technical Description

Transfers amount coins of type Currency from payer to payee with (optional) associated metadata and an (optional) metadata_signature on the message metadata | Signer::address_of(payer) | amount | DualAttestation::DOMAIN_SEPARATOR. The metadata and metadata_signature parameters are only required if amount >= DualAttestation::get_cur_microdiem_limit XDX and payer and payee are distinct VASPs. However, a transaction sender can opt in to dual attestation even when it is not required (e.g., a DesignatedDealer -> VASP payment) by providing a non-empty metadata_signature. Standardized metadata BCS format can be found in diem_types::transaction::metadata::Metadata.

Events

Successful execution of this script emits two events:

  • A DiemAccount::SentPaymentEvent on payer’s DiemAccount::DiemAccount sent_events handle; and
  • A DiemAccount::ReceivedPaymentEvent on payee’s DiemAccount::DiemAccount received_events handle.

Parameters

NameTypeDescription
CurrencyTypeThe Move type for the Currency being sent in this transaction. Currency must be an already-registered currency on-chain.
payer&signerThe signer reference of the sending account that coins are being transferred from.
payeeaddressThe address of the account the coins are being transferred to.
metadatavector<u8>Optional metadata about this payment.
metadata_signaturevector<u8>Optional signature over metadata and payment information. See

Common Abort Conditions

Error CategoryError ReasonDescription
Errors::NOT_PUBLISHEDDiemAccount::EPAYER_DOESNT_HOLD_CURRENCYpayer doesn’t hold a balance in Currency.
Errors::LIMIT_EXCEEDEDDiemAccount::EINSUFFICIENT_BALANCEamount is greater than payer’s balance in Currency.
Errors::INVALID_ARGUMENTDiemAccount::ECOIN_DEPOSIT_IS_ZEROamount is zero.
Errors::NOT_PUBLISHEDDiemAccount::EPAYEE_DOES_NOT_EXISTNo account exists at the payee address.
Errors::INVALID_ARGUMENTDiemAccount::EPAYEE_CANT_ACCEPT_CURRENCY_TYPEAn account exists at payee, but it does not accept payments in Currency.
Errors::INVALID_STATEAccountFreezing::EACCOUNT_FROZENThe payee account is frozen.
Errors::INVALID_ARGUMENTDualAttestation::EMALFORMED_METADATA_SIGNATUREmetadata_signature is not 64 bytes.
Errors::INVALID_ARGUMENTDualAttestation::EINVALID_METADATA_SIGNATUREmetadata_signature does not verify on the against the payee's DualAttestation::Credential compliance_public_key public key.
Errors::LIMIT_EXCEEDEDDiemAccount::EWITHDRAWAL_EXCEEDS_LIMITSpayer has exceeded its daily withdrawal limits for the backing coins of XDX.
Errors::LIMIT_EXCEEDEDDiemAccount::EDEPOSIT_EXCEEDS_LIMITSpayee has exceeded its daily deposit limits for XDX.
  • Script::create_child_vasp_account
  • Script::create_parent_vasp_account
  • Script::add_currency_to_account