pub fn encode_create_child_vasp_account_script(
    coin_type: TypeTag,
    child_address: AccountAddress,
    auth_key_prefix: Vec<u8, Global>,
    add_all_currencies: bool,
    child_initial_balance: u64
) -> Script
Expand description

Summary

Creates a Child VASP account with its parent being the sending account of the transaction. The sender of the transaction must be a Parent VASP account.

Technical Description

Creates a ChildVASP account for the sender parent_vasp at child_address with a balance of child_initial_balance in CoinType and an initial authentication key of auth_key_prefix | child_address.

If add_all_currencies is true, the child address will have a zero balance in all available currencies in the system.

The new account will be a child account of the transaction sender, which must be a Parent VASP account. The child account will be recorded against the limit of child accounts of the creating Parent VASP account.

Events

Successful execution with a child_initial_balance greater than zero will emit:

  • A DiemAccount::SentPaymentEvent with the payer field being the Parent VASP’s address, and payee field being child_address. This is emitted on the Parent VASP’s DiemAccount::DiemAccount sent_events handle.
  • A DiemAccount::ReceivedPaymentEvent with the payer field being the Parent VASP’s address, and payee field being child_address. This is emitted on the new Child VASPS’s DiemAccount::DiemAccount received_events handle.

Parameters

NameTypeDescription
CoinTypeTypeThe Move type for the CoinType that the child account should be created with. CoinType must be an already-registered currency on-chain.
parent_vasp&signerThe signer reference of the sending account. Must be a Parent VASP account.
child_addressaddressAddress of the to-be-created Child VASP account.
auth_key_prefixvector<u8>The authentication key prefix that will be used initially for the newly created account.
add_all_currenciesboolWhether to publish balance resources for all known currencies when the account is created.
child_initial_balanceu64The initial balance in CoinType to give the child account when it’s created.

Common Abort Conditions

Error CategoryError ReasonDescription
Errors::INVALID_ARGUMENTDiemAccount::EMALFORMED_AUTHENTICATION_KEYThe auth_key_prefix was not of length 32.
Errors::REQUIRES_ROLERoles::EPARENT_VASPThe sending account wasn’t a Parent VASP account.
Errors::ALREADY_PUBLISHEDRoles::EROLE_IDThe child_address address is already taken.
Errors::LIMIT_EXCEEDEDVASP::ETOO_MANY_CHILDRENThe sending account has reached the maximum number of allowed child accounts.
Errors::NOT_PUBLISHEDDiem::ECURRENCY_INFOThe CoinType is not a registered currency on-chain.
Errors::INVALID_STATEDiemAccount::EWITHDRAWAL_CAPABILITY_ALREADY_EXTRACTEDThe withdrawal capability for the sending account has already been extracted.
Errors::NOT_PUBLISHEDDiemAccount::EPAYER_DOESNT_HOLD_CURRENCYThe sending account doesn’t have a balance in CoinType.
Errors::LIMIT_EXCEEDEDDiemAccount::EINSUFFICIENT_BALANCEThe sending account doesn’t have at least child_initial_balance of CoinType balance.
Errors::INVALID_ARGUMENTDiemAccount::ECANNOT_CREATE_AT_VM_RESERVEDThe child_address is the reserved address 0x0.
  • Script::create_parent_vasp_account
  • Script::add_currency_to_account
  • Script::rotate_authentication_key
  • Script::add_recovery_rotation_capability
  • Script::create_recovery_address