@libra-opensource/client-sdk-typescript
Version:
744 lines (743 loc) • 331 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stdlib = exports.Types = exports.ScriptCallVariantUpdateMintingAbility = exports.ScriptCallVariantUpdateExchangeRate = exports.ScriptCallVariantUpdateDualAttestationLimit = exports.ScriptCallVariantUpdateDiemVersion = exports.ScriptCallVariantUnfreezeAccount = exports.ScriptCallVariantTieredMint = exports.ScriptCallVariantSetValidatorOperatorWithNonceAdmin = exports.ScriptCallVariantSetValidatorOperator = exports.ScriptCallVariantSetValidatorConfigAndReconfigure = exports.ScriptCallVariantRotateSharedEd25519PublicKey = exports.ScriptCallVariantRotateDualAttestationInfo = exports.ScriptCallVariantRotateAuthenticationKeyWithRecoveryAddress = exports.ScriptCallVariantRotateAuthenticationKeyWithNonceAdmin = exports.ScriptCallVariantRotateAuthenticationKeyWithNonce = exports.ScriptCallVariantRotateAuthenticationKey = exports.ScriptCallVariantRemoveValidatorAndReconfigure = exports.ScriptCallVariantRegisterValidatorConfig = exports.ScriptCallVariantPublishSharedEd25519PublicKey = exports.ScriptCallVariantPreburn = exports.ScriptCallVariantPeerToPeerWithMetadata = exports.ScriptCallVariantFreezeAccount = exports.ScriptCallVariantCreateValidatorOperatorAccount = exports.ScriptCallVariantCreateValidatorAccount = exports.ScriptCallVariantCreateRecoveryAddress = exports.ScriptCallVariantCreateParentVaspAccount = exports.ScriptCallVariantCreateDesignatedDealer = exports.ScriptCallVariantCreateChildVaspAccount = exports.ScriptCallVariantCancelBurn = exports.ScriptCallVariantBurnTxnFees = exports.ScriptCallVariantBurn = exports.ScriptCallVariantAddValidatorAndReconfigure = exports.ScriptCallVariantAddToScriptAllowList = exports.ScriptCallVariantAddRecoveryRotationCapability = exports.ScriptCallVariantAddCurrencyToAccount = exports.ScriptCall = void 0;
const DiemTypes = __importStar(require("../diemTypes"));
/**
* Structured representation of a call into a known Move script.
*/
class ScriptCall {
}
exports.ScriptCall = ScriptCall;
class ScriptCallVariantAddCurrencyToAccount extends ScriptCall {
constructor(currency) {
super();
this.currency = currency;
}
}
exports.ScriptCallVariantAddCurrencyToAccount = ScriptCallVariantAddCurrencyToAccount;
class ScriptCallVariantAddRecoveryRotationCapability extends ScriptCall {
constructor(recovery_address) {
super();
this.recovery_address = recovery_address;
}
}
exports.ScriptCallVariantAddRecoveryRotationCapability = ScriptCallVariantAddRecoveryRotationCapability;
class ScriptCallVariantAddToScriptAllowList extends ScriptCall {
constructor(hash, sliding_nonce) {
super();
this.hash = hash;
this.sliding_nonce = sliding_nonce;
}
}
exports.ScriptCallVariantAddToScriptAllowList = ScriptCallVariantAddToScriptAllowList;
class ScriptCallVariantAddValidatorAndReconfigure extends ScriptCall {
constructor(sliding_nonce, validator_name, validator_address) {
super();
this.sliding_nonce = sliding_nonce;
this.validator_name = validator_name;
this.validator_address = validator_address;
}
}
exports.ScriptCallVariantAddValidatorAndReconfigure = ScriptCallVariantAddValidatorAndReconfigure;
class ScriptCallVariantBurn extends ScriptCall {
constructor(token, sliding_nonce, preburn_address) {
super();
this.token = token;
this.sliding_nonce = sliding_nonce;
this.preburn_address = preburn_address;
}
}
exports.ScriptCallVariantBurn = ScriptCallVariantBurn;
class ScriptCallVariantBurnTxnFees extends ScriptCall {
constructor(coin_type) {
super();
this.coin_type = coin_type;
}
}
exports.ScriptCallVariantBurnTxnFees = ScriptCallVariantBurnTxnFees;
class ScriptCallVariantCancelBurn extends ScriptCall {
constructor(token, preburn_address) {
super();
this.token = token;
this.preburn_address = preburn_address;
}
}
exports.ScriptCallVariantCancelBurn = ScriptCallVariantCancelBurn;
class ScriptCallVariantCreateChildVaspAccount extends ScriptCall {
constructor(coin_type, child_address, auth_key_prefix, add_all_currencies, child_initial_balance) {
super();
this.coin_type = coin_type;
this.child_address = child_address;
this.auth_key_prefix = auth_key_prefix;
this.add_all_currencies = add_all_currencies;
this.child_initial_balance = child_initial_balance;
}
}
exports.ScriptCallVariantCreateChildVaspAccount = ScriptCallVariantCreateChildVaspAccount;
class ScriptCallVariantCreateDesignatedDealer extends ScriptCall {
constructor(currency, sliding_nonce, addr, auth_key_prefix, human_name, add_all_currencies) {
super();
this.currency = currency;
this.sliding_nonce = sliding_nonce;
this.addr = addr;
this.auth_key_prefix = auth_key_prefix;
this.human_name = human_name;
this.add_all_currencies = add_all_currencies;
}
}
exports.ScriptCallVariantCreateDesignatedDealer = ScriptCallVariantCreateDesignatedDealer;
class ScriptCallVariantCreateParentVaspAccount extends ScriptCall {
constructor(coin_type, sliding_nonce, new_account_address, auth_key_prefix, human_name, add_all_currencies) {
super();
this.coin_type = coin_type;
this.sliding_nonce = sliding_nonce;
this.new_account_address = new_account_address;
this.auth_key_prefix = auth_key_prefix;
this.human_name = human_name;
this.add_all_currencies = add_all_currencies;
}
}
exports.ScriptCallVariantCreateParentVaspAccount = ScriptCallVariantCreateParentVaspAccount;
class ScriptCallVariantCreateRecoveryAddress extends ScriptCall {
constructor() {
super();
}
}
exports.ScriptCallVariantCreateRecoveryAddress = ScriptCallVariantCreateRecoveryAddress;
class ScriptCallVariantCreateValidatorAccount extends ScriptCall {
constructor(sliding_nonce, new_account_address, auth_key_prefix, human_name) {
super();
this.sliding_nonce = sliding_nonce;
this.new_account_address = new_account_address;
this.auth_key_prefix = auth_key_prefix;
this.human_name = human_name;
}
}
exports.ScriptCallVariantCreateValidatorAccount = ScriptCallVariantCreateValidatorAccount;
class ScriptCallVariantCreateValidatorOperatorAccount extends ScriptCall {
constructor(sliding_nonce, new_account_address, auth_key_prefix, human_name) {
super();
this.sliding_nonce = sliding_nonce;
this.new_account_address = new_account_address;
this.auth_key_prefix = auth_key_prefix;
this.human_name = human_name;
}
}
exports.ScriptCallVariantCreateValidatorOperatorAccount = ScriptCallVariantCreateValidatorOperatorAccount;
class ScriptCallVariantFreezeAccount extends ScriptCall {
constructor(sliding_nonce, to_freeze_account) {
super();
this.sliding_nonce = sliding_nonce;
this.to_freeze_account = to_freeze_account;
}
}
exports.ScriptCallVariantFreezeAccount = ScriptCallVariantFreezeAccount;
class ScriptCallVariantPeerToPeerWithMetadata extends ScriptCall {
constructor(currency, payee, amount, metadata, metadata_signature) {
super();
this.currency = currency;
this.payee = payee;
this.amount = amount;
this.metadata = metadata;
this.metadata_signature = metadata_signature;
}
}
exports.ScriptCallVariantPeerToPeerWithMetadata = ScriptCallVariantPeerToPeerWithMetadata;
class ScriptCallVariantPreburn extends ScriptCall {
constructor(token, amount) {
super();
this.token = token;
this.amount = amount;
}
}
exports.ScriptCallVariantPreburn = ScriptCallVariantPreburn;
class ScriptCallVariantPublishSharedEd25519PublicKey extends ScriptCall {
constructor(public_key) {
super();
this.public_key = public_key;
}
}
exports.ScriptCallVariantPublishSharedEd25519PublicKey = ScriptCallVariantPublishSharedEd25519PublicKey;
class ScriptCallVariantRegisterValidatorConfig extends ScriptCall {
constructor(validator_account, consensus_pubkey, validator_network_addresses, fullnode_network_addresses) {
super();
this.validator_account = validator_account;
this.consensus_pubkey = consensus_pubkey;
this.validator_network_addresses = validator_network_addresses;
this.fullnode_network_addresses = fullnode_network_addresses;
}
}
exports.ScriptCallVariantRegisterValidatorConfig = ScriptCallVariantRegisterValidatorConfig;
class ScriptCallVariantRemoveValidatorAndReconfigure extends ScriptCall {
constructor(sliding_nonce, validator_name, validator_address) {
super();
this.sliding_nonce = sliding_nonce;
this.validator_name = validator_name;
this.validator_address = validator_address;
}
}
exports.ScriptCallVariantRemoveValidatorAndReconfigure = ScriptCallVariantRemoveValidatorAndReconfigure;
class ScriptCallVariantRotateAuthenticationKey extends ScriptCall {
constructor(new_key) {
super();
this.new_key = new_key;
}
}
exports.ScriptCallVariantRotateAuthenticationKey = ScriptCallVariantRotateAuthenticationKey;
class ScriptCallVariantRotateAuthenticationKeyWithNonce extends ScriptCall {
constructor(sliding_nonce, new_key) {
super();
this.sliding_nonce = sliding_nonce;
this.new_key = new_key;
}
}
exports.ScriptCallVariantRotateAuthenticationKeyWithNonce = ScriptCallVariantRotateAuthenticationKeyWithNonce;
class ScriptCallVariantRotateAuthenticationKeyWithNonceAdmin extends ScriptCall {
constructor(sliding_nonce, new_key) {
super();
this.sliding_nonce = sliding_nonce;
this.new_key = new_key;
}
}
exports.ScriptCallVariantRotateAuthenticationKeyWithNonceAdmin = ScriptCallVariantRotateAuthenticationKeyWithNonceAdmin;
class ScriptCallVariantRotateAuthenticationKeyWithRecoveryAddress extends ScriptCall {
constructor(recovery_address, to_recover, new_key) {
super();
this.recovery_address = recovery_address;
this.to_recover = to_recover;
this.new_key = new_key;
}
}
exports.ScriptCallVariantRotateAuthenticationKeyWithRecoveryAddress = ScriptCallVariantRotateAuthenticationKeyWithRecoveryAddress;
class ScriptCallVariantRotateDualAttestationInfo extends ScriptCall {
constructor(new_url, new_key) {
super();
this.new_url = new_url;
this.new_key = new_key;
}
}
exports.ScriptCallVariantRotateDualAttestationInfo = ScriptCallVariantRotateDualAttestationInfo;
class ScriptCallVariantRotateSharedEd25519PublicKey extends ScriptCall {
constructor(public_key) {
super();
this.public_key = public_key;
}
}
exports.ScriptCallVariantRotateSharedEd25519PublicKey = ScriptCallVariantRotateSharedEd25519PublicKey;
class ScriptCallVariantSetValidatorConfigAndReconfigure extends ScriptCall {
constructor(validator_account, consensus_pubkey, validator_network_addresses, fullnode_network_addresses) {
super();
this.validator_account = validator_account;
this.consensus_pubkey = consensus_pubkey;
this.validator_network_addresses = validator_network_addresses;
this.fullnode_network_addresses = fullnode_network_addresses;
}
}
exports.ScriptCallVariantSetValidatorConfigAndReconfigure = ScriptCallVariantSetValidatorConfigAndReconfigure;
class ScriptCallVariantSetValidatorOperator extends ScriptCall {
constructor(operator_name, operator_account) {
super();
this.operator_name = operator_name;
this.operator_account = operator_account;
}
}
exports.ScriptCallVariantSetValidatorOperator = ScriptCallVariantSetValidatorOperator;
class ScriptCallVariantSetValidatorOperatorWithNonceAdmin extends ScriptCall {
constructor(sliding_nonce, operator_name, operator_account) {
super();
this.sliding_nonce = sliding_nonce;
this.operator_name = operator_name;
this.operator_account = operator_account;
}
}
exports.ScriptCallVariantSetValidatorOperatorWithNonceAdmin = ScriptCallVariantSetValidatorOperatorWithNonceAdmin;
class ScriptCallVariantTieredMint extends ScriptCall {
constructor(coin_type, sliding_nonce, designated_dealer_address, mint_amount, tier_index) {
super();
this.coin_type = coin_type;
this.sliding_nonce = sliding_nonce;
this.designated_dealer_address = designated_dealer_address;
this.mint_amount = mint_amount;
this.tier_index = tier_index;
}
}
exports.ScriptCallVariantTieredMint = ScriptCallVariantTieredMint;
class ScriptCallVariantUnfreezeAccount extends ScriptCall {
constructor(sliding_nonce, to_unfreeze_account) {
super();
this.sliding_nonce = sliding_nonce;
this.to_unfreeze_account = to_unfreeze_account;
}
}
exports.ScriptCallVariantUnfreezeAccount = ScriptCallVariantUnfreezeAccount;
class ScriptCallVariantUpdateDiemVersion extends ScriptCall {
constructor(sliding_nonce, major) {
super();
this.sliding_nonce = sliding_nonce;
this.major = major;
}
}
exports.ScriptCallVariantUpdateDiemVersion = ScriptCallVariantUpdateDiemVersion;
class ScriptCallVariantUpdateDualAttestationLimit extends ScriptCall {
constructor(sliding_nonce, new_micro_xdx_limit) {
super();
this.sliding_nonce = sliding_nonce;
this.new_micro_xdx_limit = new_micro_xdx_limit;
}
}
exports.ScriptCallVariantUpdateDualAttestationLimit = ScriptCallVariantUpdateDualAttestationLimit;
class ScriptCallVariantUpdateExchangeRate extends ScriptCall {
constructor(currency, sliding_nonce, new_exchange_rate_numerator, new_exchange_rate_denominator) {
super();
this.currency = currency;
this.sliding_nonce = sliding_nonce;
this.new_exchange_rate_numerator = new_exchange_rate_numerator;
this.new_exchange_rate_denominator = new_exchange_rate_denominator;
}
}
exports.ScriptCallVariantUpdateExchangeRate = ScriptCallVariantUpdateExchangeRate;
class ScriptCallVariantUpdateMintingAbility extends ScriptCall {
constructor(currency, allow_minting) {
super();
this.currency = currency;
this.allow_minting = allow_minting;
}
}
exports.ScriptCallVariantUpdateMintingAbility = ScriptCallVariantUpdateMintingAbility;
var Types;
(function (Types) {
Types[Types["Boolean"] = 0] = "Boolean";
Types[Types["U8"] = 1] = "U8";
Types[Types["U64"] = 2] = "U64";
Types[Types["U128"] = 3] = "U128";
Types[Types["Address"] = 4] = "Address";
Types[Types["Array"] = 5] = "Array";
Types[Types["Struct"] = 6] = "Struct";
})(Types = exports.Types || (exports.Types = {}));
class Stdlib {
static fromHexString(hexString) {
return new Uint8Array(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
}
/**
* # Summary
* Adds a zero `Currency` balance to the sending `account`. This will enable `account` to
* send, receive, and hold `Diem::Diem<Currency>` coins. This transaction can be
* successfully sent by any account that is allowed to hold balances
* (e.g., VASP, Designated Dealer).
*
* # Technical Description
* After the successful execution of this transaction the sending account will have a
* `DiemAccount::Balance<Currency>` resource with zero balance published under it. Only
* accounts that can hold balances can send this transaction, the sending account cannot
* already have a `DiemAccount::Balance<Currency>` published under it.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `Currency` | Type | The Move type for the `Currency` being added to the sending account of the transaction. `Currency` must be an already-registered currency on-chain. |
* | `account` | `&signer` | The signer of the sending account of the transaction. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::NOT_PUBLISHED` | `Diem::ECURRENCY_INFO` | The `Currency` is not a registered currency on-chain. |
* | `Errors::INVALID_ARGUMENT` | `DiemAccount::EROLE_CANT_STORE_BALANCE` | The sending `account`'s role does not permit balances. |
* | `Errors::ALREADY_PUBLISHED` | `DiemAccount::EADD_EXISTING_CURRENCY` | A balance for `Currency` is already published under the sending `account`. |
*
* # Related Scripts
* * `Script::create_child_vasp_account`
* * `Script::create_parent_vasp_account`
* * `Script::peer_to_peer_with_metadata`
*/
static encodeAddCurrencyToAccountScript(currency) {
const code = Stdlib.ADD_CURRENCY_TO_ACCOUNT_CODE;
const tyArgs = [currency];
const args = [];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # Summary
* Stores the sending accounts ability to rotate its authentication key with a designated recovery
* account. Both the sending and recovery accounts need to belong to the same VASP and
* both be VASP accounts. After this transaction both the sending account and the
* specified recovery account can rotate the sender account's authentication key.
*
* # Technical Description
* Adds the `DiemAccount::KeyRotationCapability` for the sending account
* (`to_recover_account`) to the `RecoveryAddress::RecoveryAddress` resource under
* `recovery_address`. After this transaction has been executed successfully the account at
* `recovery_address` and the `to_recover_account` may rotate the authentication key of
* `to_recover_account` (the sender of this transaction).
*
* The sending account of this transaction (`to_recover_account`) must not have previously given away its unique key
* rotation capability, and must be a VASP account. The account at `recovery_address`
* must also be a VASP account belonging to the same VASP as the `to_recover_account`.
* Additionally the account at `recovery_address` must have already initialized itself as
* a recovery account address using the `Script::create_recovery_address` transaction script.
*
* The sending account's (`to_recover_account`) key rotation capability is
* removed in this transaction and stored in the `RecoveryAddress::RecoveryAddress`
* resource stored under the account at `recovery_address`.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `to_recover_account` | `&signer` | The signer reference of the sending account of this transaction. |
* | `recovery_address` | `address` | The account address where the `to_recover_account`'s `DiemAccount::KeyRotationCapability` will be stored. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::INVALID_STATE` | `DiemAccount::EKEY_ROTATION_CAPABILITY_ALREADY_EXTRACTED` | `to_recover_account` has already delegated/extracted its `DiemAccount::KeyRotationCapability`. |
* | `Errors::NOT_PUBLISHED` | `RecoveryAddress::ERECOVERY_ADDRESS` | `recovery_address` does not have a `RecoveryAddress` resource published under it. |
* | `Errors::INVALID_ARGUMENT` | `RecoveryAddress::EINVALID_KEY_ROTATION_DELEGATION` | `to_recover_account` and `recovery_address` do not belong to the same VASP. |
*
* # Related Scripts
* * `Script::create_recovery_address`
* * `Script::rotate_authentication_key_with_recovery_address`
*/
static encodeAddRecoveryRotationCapabilityScript(recovery_address) {
const code = Stdlib.ADD_RECOVERY_ROTATION_CAPABILITY_CODE;
const tyArgs = [];
const args = [
new DiemTypes.TransactionArgumentVariantAddress(recovery_address),
];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # Summary
* Adds a script hash to the transaction allowlist. This transaction
* can only be sent by the Diem Root account. Scripts with this hash can be
* sent afterward the successful execution of this script.
*
* # Technical Description
*
* The sending account (`dr_account`) must be the Diem Root account. The script allow
* list must not already hold the script `hash` being added. The `sliding_nonce` must be
* a valid nonce for the Diem Root account. After this transaction has executed
* successfully a reconfiguration will be initiated, and the on-chain config
* `DiemTransactionPublishingOption::DiemTransactionPublishingOption`'s
* `script_allow_list` field will contain the new script `hash` and transactions
* with this `hash` can be successfully sent to the network.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `dr_account` | `&signer` | The signer reference of the sending account of this transaction. Must be the Diem Root signer. |
* | `hash` | `vector<u8>` | The hash of the script to be added to the script allowlist. |
* | `sliding_nonce` | `u64` | The `sliding_nonce` (see: `SlidingNonce`) to be used for this transaction. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::NOT_PUBLISHED` | `SlidingNonce::ESLIDING_NONCE` | A `SlidingNonce` resource is not published under `dr_account`. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_TOO_OLD` | The `sliding_nonce` is too old and it's impossible to determine if it's duplicated or not. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_TOO_NEW` | The `sliding_nonce` is too far in the future. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_ALREADY_RECORDED` | The `sliding_nonce` has been previously recorded. |
* | `Errors::REQUIRES_ADDRESS` | `CoreAddresses::EDIEM_ROOT` | The sending account is not the Diem Root account. |
* | `Errors::REQUIRES_ROLE` | `Roles::EDIEM_ROOT` | The sending account is not the Diem Root account. |
* | `Errors::INVALID_ARGUMENT` | `DiemTransactionPublishingOption::EINVALID_SCRIPT_HASH` | The script `hash` is an invalid length. |
* | `Errors::INVALID_ARGUMENT` | `DiemTransactionPublishingOption::EALLOWLIST_ALREADY_CONTAINS_SCRIPT` | The on-chain allowlist already contains the script `hash`. |
*/
static encodeAddToScriptAllowListScript(hash, sliding_nonce) {
const code = Stdlib.ADD_TO_SCRIPT_ALLOW_LIST_CODE;
const tyArgs = [];
const args = [
new DiemTypes.TransactionArgumentVariantU8Vector(hash),
new DiemTypes.TransactionArgumentVariantU64(sliding_nonce),
];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # Summary
* Adds a validator account to the validator set, and triggers a
* reconfiguration of the system to admit the account to the validator set for the system. This
* transaction can only be successfully called by the Diem Root account.
*
* # Technical Description
* This script adds the account at `validator_address` to the validator set.
* This transaction emits a `DiemConfig::NewEpochEvent` event and triggers a
* reconfiguration. Once the reconfiguration triggered by this script's
* execution has been performed, the account at the `validator_address` is
* considered to be a validator in the network.
*
* This transaction script will fail if the `validator_address` address is already in the validator set
* or does not have a `ValidatorConfig::ValidatorConfig` resource already published under it.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `dr_account` | `&signer` | The signer reference of the sending account of this transaction. Must be the Diem Root signer. |
* | `sliding_nonce` | `u64` | The `sliding_nonce` (see: `SlidingNonce`) to be used for this transaction. |
* | `validator_name` | `vector<u8>` | ASCII-encoded human name for the validator. Must match the human name in the `ValidatorConfig::ValidatorConfig` for the validator. |
* | `validator_address` | `address` | The validator account address to be added to the validator set. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::NOT_PUBLISHED` | `SlidingNonce::ESLIDING_NONCE` | A `SlidingNonce` resource is not published under `dr_account`. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_TOO_OLD` | The `sliding_nonce` is too old and it's impossible to determine if it's duplicated or not. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_TOO_NEW` | The `sliding_nonce` is too far in the future. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_ALREADY_RECORDED` | The `sliding_nonce` has been previously recorded. |
* | `Errors::REQUIRES_ADDRESS` | `CoreAddresses::EDIEM_ROOT` | The sending account is not the Diem Root account. |
* | `Errors::REQUIRES_ROLE` | `Roles::EDIEM_ROOT` | The sending account is not the Diem Root account. |
* | 0 | 0 | The provided `validator_name` does not match the already-recorded human name for the validator. |
* | `Errors::INVALID_ARGUMENT` | `DiemSystem::EINVALID_PROSPECTIVE_VALIDATOR` | The validator to be added does not have a `ValidatorConfig::ValidatorConfig` resource published under it, or its `config` field is empty. |
* | `Errors::INVALID_ARGUMENT` | `DiemSystem::EALREADY_A_VALIDATOR` | The `validator_address` account is already a registered validator. |
* | `Errors::INVALID_STATE` | `DiemConfig::EINVALID_BLOCK_TIME` | An invalid time value was encountered in reconfiguration. Unlikely to occur. |
*
* # Related Scripts
* * `Script::create_validator_account`
* * `Script::create_validator_operator_account`
* * `Script::register_validator_config`
* * `Script::remove_validator_and_reconfigure`
* * `Script::set_validator_operator`
* * `Script::set_validator_operator_with_nonce_admin`
* * `Script::set_validator_config_and_reconfigure`
*/
static encodeAddValidatorAndReconfigureScript(sliding_nonce, validator_name, validator_address) {
const code = Stdlib.ADD_VALIDATOR_AND_RECONFIGURE_CODE;
const tyArgs = [];
const args = [
new DiemTypes.TransactionArgumentVariantU64(sliding_nonce),
new DiemTypes.TransactionArgumentVariantU8Vector(validator_name),
new DiemTypes.TransactionArgumentVariantAddress(validator_address),
];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # Summary
* Burns all coins held in the preburn resource at the specified
* preburn address and removes them from the system. The sending account must
* be the Treasury Compliance account.
* The account that holds the preburn resource will normally be a Designated
* Dealer, but there are no enforced requirements that it be one.
*
* # Technical Description
* This transaction permanently destroys all the coins of `Token` type
* stored in the `Diem::Preburn<Token>` resource published under the
* `preburn_address` account address.
*
* This transaction will only succeed if the sending `account` has a
* `Diem::BurnCapability<Token>`, and a `Diem::Preburn<Token>` resource
* exists under `preburn_address`, with a non-zero `to_burn` field. After the successful execution
* of this transaction the `total_value` field in the
* `Diem::CurrencyInfo<Token>` resource published under `0xA550C18` will be
* decremented by the value of the `to_burn` field of the preburn resource
* under `preburn_address` immediately before this transaction, and the
* `to_burn` field of the preburn resource will have a zero value.
*
* ## Events
* The successful execution of this transaction will emit a `Diem::BurnEvent` on the event handle
* held in the `Diem::CurrencyInfo<Token>` resource's `burn_events` published under
* `0xA550C18`.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `Token` | Type | The Move type for the `Token` currency being burned. `Token` must be an already-registered currency on-chain. |
* | `tc_account` | `&signer` | The signer reference of the sending account of this transaction, must have a burn capability for `Token` published under it. |
* | `sliding_nonce` | `u64` | The `sliding_nonce` (see: `SlidingNonce`) to be used for this transaction. |
* | `preburn_address` | `address` | The address where the coins to-be-burned are currently held. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::NOT_PUBLISHED` | `SlidingNonce::ESLIDING_NONCE` | A `SlidingNonce` resource is not published under `account`. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_TOO_OLD` | The `sliding_nonce` is too old and it's impossible to determine if it's duplicated or not. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_TOO_NEW` | The `sliding_nonce` is too far in the future. |
* | `Errors::INVALID_ARGUMENT` | `SlidingNonce::ENONCE_ALREADY_RECORDED` | The `sliding_nonce` has been previously recorded. |
* | `Errors::REQUIRES_CAPABILITY` | `Diem::EBURN_CAPABILITY` | The sending `account` does not have a `Diem::BurnCapability<Token>` published under it. |
* | `Errors::NOT_PUBLISHED` | `Diem::EPREBURN` | The account at `preburn_address` does not have a `Diem::Preburn<Token>` resource published under it. |
* | `Errors::INVALID_STATE` | `Diem::EPREBURN_EMPTY` | The `Diem::Preburn<Token>` resource is empty (has a value of 0). |
* | `Errors::NOT_PUBLISHED` | `Diem::ECURRENCY_INFO` | The specified `Token` is not a registered currency on-chain. |
*
* # Related Scripts
* * `Script::burn_txn_fees`
* * `Script::cancel_burn`
* * `Script::preburn`
*/
static encodeBurnScript(token, sliding_nonce, preburn_address) {
const code = Stdlib.BURN_CODE;
const tyArgs = [token];
const args = [
new DiemTypes.TransactionArgumentVariantU64(sliding_nonce),
new DiemTypes.TransactionArgumentVariantAddress(preburn_address),
];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # Summary
* Burns the transaction fees collected in the `CoinType` currency so that the
* Diem association may reclaim the backing coins off-chain. May only be sent
* by the Treasury Compliance account.
*
* # Technical Description
* Burns the transaction fees collected in `CoinType` so that the
* association may reclaim the backing coins. Once this transaction has executed
* successfully all transaction fees that will have been collected in
* `CoinType` since the last time this script was called with that specific
* currency. Both `balance` and `preburn` fields in the
* `TransactionFee::TransactionFee<CoinType>` resource published under the `0xB1E55ED`
* account address will have a value of 0 after the successful execution of this script.
*
* ## Events
* The successful execution of this transaction will emit a `Diem::BurnEvent` on the event handle
* held in the `Diem::CurrencyInfo<CoinType>` resource's `burn_events` published under
* `0xA550C18`.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `CoinType` | Type | The Move type for the `CoinType` being added to the sending account of the transaction. `CoinType` must be an already-registered currency on-chain. |
* | `tc_account` | `&signer` | The signer reference of the sending account of this transaction. Must be the Treasury Compliance account. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::REQUIRES_ADDRESS` | `CoreAddresses::ETREASURY_COMPLIANCE` | The sending account is not the Treasury Compliance account. |
* | `Errors::NOT_PUBLISHED` | `TransactionFee::ETRANSACTION_FEE` | `CoinType` is not an accepted transaction fee currency. |
* | `Errors::INVALID_ARGUMENT` | `Diem::ECOIN` | The collected fees in `CoinType` are zero. |
*
* # Related Scripts
* * `Script::burn`
* * `Script::cancel_burn`
*/
static encodeBurnTxnFeesScript(coin_type) {
const code = Stdlib.BURN_TXN_FEES_CODE;
const tyArgs = [coin_type];
const args = [];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # Summary
* Cancels and returns all coins held in the preburn area under
* `preburn_address` and returns the funds to the `preburn_address`'s balance.
* Can only be successfully sent by an account with Treasury Compliance role.
*
* # Technical Description
* Cancels and returns all coins held in the `Diem::Preburn<Token>` resource under the `preburn_address` and
* return the funds to the `preburn_address` account's `DiemAccount::Balance<Token>`.
* The transaction must be sent by an `account` with a `Diem::BurnCapability<Token>`
* resource published under it. The account at `preburn_address` must have a
* `Diem::Preburn<Token>` resource published under it, and its value must be nonzero. The transaction removes
* the entire balance held in the `Diem::Preburn<Token>` resource, and returns it back to the account's
* `DiemAccount::Balance<Token>` under `preburn_address`. Due to this, the account at
* `preburn_address` must already have a balance in the `Token` currency published
* before this script is called otherwise the transaction will fail.
*
* ## Events
* The successful execution of this transaction will emit:
* * A `Diem::CancelBurnEvent` on the event handle held in the `Diem::CurrencyInfo<Token>`
* resource's `burn_events` published under `0xA550C18`.
* * A `DiemAccount::ReceivedPaymentEvent` on the `preburn_address`'s
* `DiemAccount::DiemAccount` `received_events` event handle with both the `payer` and `payee`
* being `preburn_address`.
*
* # Parameters
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `Token` | Type | The Move type for the `Token` currenty that burning is being cancelled for. `Token` must be an already-registered currency on-chain. |
* | `account` | `&signer` | The signer reference of the sending account of this transaction, must have a burn capability for `Token` published under it. |
* | `preburn_address` | `address` | The address where the coins to-be-burned are currently held. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::REQUIRES_CAPABILITY` | `Diem::EBURN_CAPABILITY` | The sending `account` does not have a `Diem::BurnCapability<Token>` published under it. |
* | `Errors::NOT_PUBLISHED` | `Diem::EPREBURN` | The account at `preburn_address` does not have a `Diem::Preburn<Token>` resource published under it. |
* | `Errors::NOT_PUBLISHED` | `Diem::ECURRENCY_INFO` | The specified `Token` is not a registered currency on-chain. |
* | `Errors::INVALID_ARGUMENT` | `DiemAccount::ECOIN_DEPOSIT_IS_ZERO` | The value held in the preburn resource was zero. |
* | `Errors::INVALID_ARGUMENT` | `DiemAccount::EPAYEE_CANT_ACCEPT_CURRENCY_TYPE` | The account at `preburn_address` doesn't have a balance resource for `Token`. |
* | `Errors::LIMIT_EXCEEDED` | `DiemAccount::EDEPOSIT_EXCEEDS_LIMITS` | The depositing of the funds held in the prebun area would exceed the `account`'s account limits. |
* | `Errors::INVALID_STATE` | `DualAttestation::EPAYEE_COMPLIANCE_KEY_NOT_SET` | The `account` does not have a compliance key set on it but dual attestion checking was performed. |
*
* # Related Scripts
* * `Script::burn_txn_fees`
* * `Script::burn`
* * `Script::preburn`
*/
static encodeCancelBurnScript(token, preburn_address) {
const code = Stdlib.CANCEL_BURN_CODE;
const tyArgs = [token];
const args = [
new DiemTypes.TransactionArgumentVariantAddress(preburn_address),
];
return new DiemTypes.Script(code, tyArgs, args);
}
/**
* # 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
* | Name | Type | Description |
* | ------ | ------ | ------------- |
* | `CoinType` | Type | The Move type for the `CoinType` that the child account should be created with. `CoinType` must be an already-registered currency on-chain. |
* | `parent_vasp` | `&signer` | The signer reference of the sending account. Must be a Parent VASP account. |
* | `child_address` | `address` | Address of the to-be-created Child VASP account. |
* | `auth_key_prefix` | `vector<u8>` | The authentication key prefix that will be used initially for the newly created account. |
* | `add_all_currencies` | `bool` | Whether to publish balance resources for all known currencies when the account is created. |
* | `child_initial_balance` | `u64` | The initial balance in `CoinType` to give the child account when it's created. |
*
* # Common Abort Conditions
* | Error Category | Error Reason | Description |
* | ---------------- | -------------- | ------------- |
* | `Errors::INVALID_ARGUMENT` | `DiemAccount::EMALFORMED_AUTHENTICATION_KEY` | The `auth_key_prefix` was not of length 32. |
* | `Errors::REQUIRES_ROLE` | `Roles::EPARENT_VASP` | The sending account wasn't a Parent VASP account. |
* | `Errors::ALREADY_PUBLISHED` | `Roles::EROLE_ID` | The `child_address` address is already taken. |
* | `Errors::LIMIT_EXCEEDED` | `VASP::ETOO_MANY_CHILDREN` | The sending account has reached the maximum number of allowed child accounts. |
* | `Errors::NOT_PUBLISHED` | `Diem::ECURRENCY_INFO` | The `CoinType` is not a registered currency on-chain. |
* | `Errors::INVALID_STATE` | `DiemAccount::EWITHDRAWAL_CAPABILITY_ALREADY_EXTRACTED` | The withdrawal capability for the sending account has already been extracted. |
* | `Errors::NOT_PUBLISHED` | `DiemAccount::EPAYER_DOESNT_HOLD_CURRENCY` | The sending account doesn't have a balance in `CoinType`. |
* | `Errors::LIMIT_EXCEEDED` | `DiemAccount::EINSUFFICIENT_BALANCE` | The sending account doesn't have at least `child_initial_balance` of `CoinType` balance. |
* | `Errors::INVALID_ARGUMENT` | `DiemAccount::ECANNOT_CREATE_AT_VM_RESERVED` | The `child_address` is the reserved address 0x0. |
*
* # Related Scripts
* * `Script::create_parent_vasp_account`
* * `Script::add_currency_to_account`
* * `Script::rotate_authentication_key`
* * `Script::add_recovery_rotation_capability`
* * `Script::create_recovery_address`
*/
static encodeCreateChildVaspAccountScript(coin_type, child_address, auth_key_prefix, add_all_currencies, child_initial_balance) {