@taquito/core
Version:
Classes, interfaces, and types shared across Taquito packages
340 lines (339 loc) • 12.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublicKeyNotFoundError = exports.ProhibitedActionError = exports.DeprecationError = exports.InvalidOperationKindError = exports.InvalidOperationHashError = exports.InvalidKeyHashError = exports.InvalidChainIdError = exports.InvalidContractAddressError = exports.InvalidSignatureError = exports.InvalidPublicKeyError = exports.InvalidKeyError = exports.InvalidViewParameterError = exports.InvalidMessageError = exports.InvalidHexStringError = exports.InvalidDerivationPathError = exports.InvalidAmountError = exports.InvalidBlockHashError = exports.InvalidFinalizeUnstakeAmountError = exports.InvalidStakingAddressError = exports.InvalidAddressError = exports.PermissionDeniedError = exports.NetworkError = exports.UnsupportedActionError = exports.TezosToolkitConfigError = exports.RpcError = exports.ParameterValidationError = exports.TaquitoError = void 0;
// ==========================================================================================
// parent error classes for Taquito
// ==========================================================================================
/**
* @category Error
* @description Parent error class all taquito errors to extend from
*/
class TaquitoError extends Error {
}
exports.TaquitoError = TaquitoError;
/**
* @category Error
* @description Error that indicates invalid user inputs
*/
class ParameterValidationError extends TaquitoError {
}
exports.ParameterValidationError = ParameterValidationError;
/**
* @category Error
* @description Error returned by RPC node
*/
class RpcError extends TaquitoError {
}
exports.RpcError = RpcError;
/**
* @category Error
* @description Error that indicates TezosToolKit has not been configured appropriately
*/
class TezosToolkitConfigError extends TaquitoError {
}
exports.TezosToolkitConfigError = TezosToolkitConfigError;
/**
* @category Error
* @description Error that indicates a requested action is not supported by Taquito
*/
class UnsupportedActionError extends TaquitoError {
}
exports.UnsupportedActionError = UnsupportedActionError;
/**
* @category Error
* @description Error during a network operation
*/
class NetworkError extends TaquitoError {
}
exports.NetworkError = NetworkError;
/**
* @category Error
* @description Error that indicates user attempts an action without necessary permissions
*/
class PermissionDeniedError extends TaquitoError {
}
exports.PermissionDeniedError = PermissionDeniedError;
// ==========================================================================================
// common error classes for Taquito
// ==========================================================================================
/**
* @category Error
* @description Error that indicates an invalid originated or implicit address being passed or used
*/
class InvalidAddressError extends ParameterValidationError {
constructor(address, errorDetail) {
super();
this.address = address;
this.errorDetail = errorDetail;
this.name = 'InvalidAddressError';
this.message = `Invalid address "${address}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidAddressError = InvalidAddressError;
class InvalidStakingAddressError extends ParameterValidationError {
constructor(address, errorDetail) {
super();
this.address = address;
this.errorDetail = errorDetail;
this.name = 'InvalidStakingAddressError';
this.message = `Invalid staking address "${address}", you can only set destination as your own address`;
}
}
exports.InvalidStakingAddressError = InvalidStakingAddressError;
class InvalidFinalizeUnstakeAmountError extends ParameterValidationError {
constructor(address, errorDetail) {
super();
this.address = address;
this.errorDetail = errorDetail;
this.name = 'InvalidFinalizeUnstakeAmountError';
this.message = `The amount can only be 0 when finalizing an unstake`;
}
}
exports.InvalidFinalizeUnstakeAmountError = InvalidFinalizeUnstakeAmountError;
/**
* @category Error
* @description Error that indicates an invalid block hash being passed or used
*/
class InvalidBlockHashError extends ParameterValidationError {
constructor(blockHash, errorDetail) {
super();
this.blockHash = blockHash;
this.errorDetail = errorDetail;
this.name = 'InvalidBlockHashError';
this.message = `Invalid block hash "${blockHash}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidBlockHashError = InvalidBlockHashError;
/**
* @category Error
* @description Error that indicates an invalid amount of tez being passed as a parameter
*/
class InvalidAmountError extends ParameterValidationError {
constructor(amount) {
super();
this.amount = amount;
this.name = 'InvalidAmountError';
this.message = `Invalid amount "${amount}"`;
}
}
exports.InvalidAmountError = InvalidAmountError;
/**
* @category Error
* @description Error that indicates an invalid derivation path being passed or used
*/
class InvalidDerivationPathError extends ParameterValidationError {
constructor(derivationPath, errorDetail) {
super();
this.derivationPath = derivationPath;
this.errorDetail = errorDetail;
this.name = 'InvalidDerivationPathError';
this.message = `Invalid derivation path "${derivationPath}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidDerivationPathError = InvalidDerivationPathError;
/**
* @category Error
* @description Error that indicates an invalid hex string have been passed or used
*/
class InvalidHexStringError extends ParameterValidationError {
constructor(hexString, errorDetail) {
super();
this.hexString = hexString;
this.errorDetail = errorDetail;
this.name = 'InvalidHexStringError';
this.message = `Invalid hex string "${hexString}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidHexStringError = InvalidHexStringError;
/**
* @category Error
* @description Error that indicates an invalid message being passed or used
*/
class InvalidMessageError extends ParameterValidationError {
constructor(msg, errorDetail) {
super();
this.msg = msg;
this.errorDetail = errorDetail;
this.name = 'InvalidMessageError';
this.message = `Invalid message "${msg}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidMessageError = InvalidMessageError;
/**
* @category Error
* @description Error that indicates invalid view parameter of a smart contract
*/
class InvalidViewParameterError extends ParameterValidationError {
constructor(viewName, sigs, args, cause) {
super();
this.viewName = viewName;
this.sigs = sigs;
this.args = args;
this.cause = cause;
this.name = 'InvalidViewParameterError';
this.message = `Invalid view arguments ${JSON.stringify(args)} received for name "${viewName}" expecting one of the following signatures ${JSON.stringify(sigs)}.`;
}
}
exports.InvalidViewParameterError = InvalidViewParameterError;
/**
* @category Error
* @description Error that indicates an invalid private key being passed or used
*/
class InvalidKeyError extends ParameterValidationError {
constructor(errorDetail) {
super();
this.errorDetail = errorDetail;
this.name = 'InvalidKeyError';
this.message = `Invalid private key`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidKeyError = InvalidKeyError;
/**
* @category Error
* @description Error that indicates an Invalid Public Key being passed or used
*/
class InvalidPublicKeyError extends ParameterValidationError {
constructor(publicKey, errorDetail) {
super();
this.publicKey = publicKey;
this.errorDetail = errorDetail;
this.name = 'InvalidPublicKeyError';
this.message = `Invalid public key "${publicKey}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidPublicKeyError = InvalidPublicKeyError;
/**
* @category Error
* @description Error that indicates an invalid signature being passed or used
*/
class InvalidSignatureError extends ParameterValidationError {
constructor(signature, errorDetail) {
super();
this.signature = signature;
this.errorDetail = errorDetail;
this.name = 'InvalidSignatureError';
this.message = `Invalid signature "${signature}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidSignatureError = InvalidSignatureError;
/**
* @category Error
* @description Error that indicates an invalid contract address being passed or used
*/
class InvalidContractAddressError extends ParameterValidationError {
constructor(contractAddress, errorDetail) {
super();
this.contractAddress = contractAddress;
this.errorDetail = errorDetail;
this.name = 'InvalidContractAddressError';
this.message = `Invalid contract address "${contractAddress}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidContractAddressError = InvalidContractAddressError;
/**
* @category Error
* @description Error that indicates an invalid chain id being passed or used
*/
class InvalidChainIdError extends ParameterValidationError {
constructor(chainId, errorDetail) {
super();
this.chainId = chainId;
this.errorDetail = errorDetail;
this.name = 'InvalidChainIdError';
this.message = `Invalid chain id "${chainId}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidChainIdError = InvalidChainIdError;
/**
* @category Error
* @description Error that indicates an invalid public key hash being passed or used
*/
class InvalidKeyHashError extends ParameterValidationError {
constructor(keyHash, errorDetail) {
super();
this.keyHash = keyHash;
this.errorDetail = errorDetail;
this.name = 'InvalidKeyHashError';
this.message = `Invalid public key hash "${keyHash}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidKeyHashError = InvalidKeyHashError;
/**
* @category Error
* @description Error that indicates an invalid operation hash being passed or used
*/
class InvalidOperationHashError extends ParameterValidationError {
constructor(operationHash, errorDetail) {
super();
this.operationHash = operationHash;
this.errorDetail = errorDetail;
this.name = 'InvalidOperationHashError';
this.message = `Invalid operation hash "${operationHash}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidOperationHashError = InvalidOperationHashError;
/**
* @category Error
* @description Error that indicates an invalid operation kind being passed or used
*/
class InvalidOperationKindError extends ParameterValidationError {
constructor(operationKind, errorDetail) {
super();
this.operationKind = operationKind;
this.errorDetail = errorDetail;
this.name = 'InvalidOperationKindError';
this.message = `Invalid operation kind "${operationKind}"`;
this.message += errorDetail ? ` ${errorDetail}.` : '.';
}
}
exports.InvalidOperationKindError = InvalidOperationKindError;
/**
* @category Error
* @description General error that indicates something is no longer supported and/or deprecated
*/
class DeprecationError extends UnsupportedActionError {
constructor(message) {
super();
this.message = message;
this.name = 'DeprecationError';
}
}
exports.DeprecationError = DeprecationError;
/**
* @category Error
* @description General error that indicates an action is prohibited or not allowed
*/
class ProhibitedActionError extends UnsupportedActionError {
constructor(message) {
super();
this.message = message;
this.name = 'ProhibitedActionError';
}
}
exports.ProhibitedActionError = ProhibitedActionError;
/**
* @category Error
* @description Error that indicates a failure in grabbing the public key
*/
class PublicKeyNotFoundError extends TaquitoError {
constructor(pkh, cause) {
super();
this.pkh = pkh;
this.cause = cause;
this.name = 'PublicKeyNotFoundError';
this.message = `Public key not found of this address "${pkh}" in either wallet or contract API.`;
}
}
exports.PublicKeyNotFoundError = PublicKeyNotFoundError;