UNPKG

swapable

Version:
100 lines (99 loc) 3.44 kB
/** * This file is part of Swapable shared under AGPL-3.0 * Copyright (C) 2021 Using Blockchain Ltd, Reg No.: 12658136, United Kingdom * * @package Swapable * @author Grégory Saive for Using Blockchain Ltd <greg@ubc.digital> * @license AGPL-3.0 */ import { AggregateTransaction, PublicAccount, Transaction } from 'symbol-sdk'; import { TransactionURI } from 'symbol-uri-scheme'; import { AllowanceResult, Command, CommandOption, Context } from '../../index'; /** * @class BaseCommand * @package Swapable * @subpackage Contracts * @since v1.0.0 * @description Abstract class that describes a command interface for executing * commands that involve swapable digital assets. */ export declare abstract class BaseCommand implements Command { /** * @description Execution context */ readonly context: Context; /** * Construct a command object around `context`. * * @param {Context} context */ constructor( /** * @description Execution context */ context: Context); /** * Getter for the command name. * * @return {string} **/ abstract get name(): string; /** * Getter for the command descriptor. * * @return {string} **/ abstract get descriptor(): string; /** * Verifies **allowance** of `actor` to execute command. Arguments to * the command execution can be passed in `argv`. * * @param {PublicAccount} actor * @param {Array<CommandOption>} argv * @return {AllowanceResult} **/ abstract canExecute(actor: PublicAccount, argv: CommandOption[] | undefined): AllowanceResult; /** * Execute the command with `actor` operator account. Arguments to * the command execution can be passed in `argv`. * * @param {PublicAccount} actor * @param {Array<CommandOption>} argv * @return {TransactionURI} **/ abstract execute(actor: PublicAccount, argv: CommandOption[] | undefined): TransactionURI<Transaction>; /** * Prepare the command's transactions. Some commands may require * the atomic execution of all their transactions and therefor * need the prepare method to wrap transactions inside an aggregate * transaction. * * @param {PublicAccount} actor * @param {Array<CommandOption>} argv * @return {TransactionURI} **/ protected abstract prepare(): AggregateTransaction | Transaction; /** * Build a command's transactions. Transactions returned here will * be formatted to a transaction URI in the `execute()` step. * * @return {Transaction} **/ protected abstract get transactions(): Transaction[]; /** * Asserts the allowance of `actor` to execute the command. * * @param {PublicAccount} actor * @param {CommandOption[]} argv * @throws {FailureOperationForbidden} On denial of authorization */ protected assertExecutionAllowance(actor: PublicAccount, argv: CommandOption[] | undefined): boolean; /** * Asserts the presence of `fields` in `argv`. * * @param {CommandOption[]} argv * @param {string[]} fields * @throws {FailureMissingArgument} On missing mandatory argument(s). */ protected assertHasMandatoryArguments(argv: CommandOption[] | undefined, fields: string[]): boolean; }