Skip to content

Commit

Permalink
refactor: consolidate InvalidcontractAddressError into @taquito/core …
Browse files Browse the repository at this point in the history
…and improve across packages

re #1994
  • Loading branch information
hui-an-yang committed May 9, 2023
1 parent e7f372d commit 7b3432e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
13 changes: 13 additions & 0 deletions packages/taquito-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,16 @@ export class InvalidSignatureError extends ParameterValidationError {
errorDetail ? (this.message += ` ${errorDetail}`) : null;
}
}

/**
* @category Error
* @description Error indicates an invalid contract address being passed or used
*/
export class InvalidContractAddressError extends ParameterValidationError {
constructor(public contractAddress: string, errorDetail?: string) {
super();
this.name = 'InvalidContractAddressError';
this.message = `The contract address '${contractAddress}' is invalid.`;
errorDetail ? (this.message += ` ${errorDetail}`) : null;
}
}
3 changes: 1 addition & 2 deletions packages/taquito-local-forging/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
prefixLength,
InvalidKeyHashError,
InvalidPublicKeyError,
InvalidContractAddressError,
} from '@taquito/utils';
import {
OversizedEntryPointError,
Expand All @@ -29,7 +28,7 @@ import {
} from './michelson/codec';
import { Uint8ArrayConsumer } from './uint8array-consumer';
import { pad } from './utils';
import { InvalidAddressError } from '@taquito/core';
import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core';

// https://tezos.gitlab.io/shell/p2p_api.html specifies data types and structure for forging

Expand Down
17 changes: 6 additions & 11 deletions packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@ import {
PendingOperations,
OriginationProofParams,
} from '../types';
import { InvalidAddressError } from '@taquito/core';
import {
InvalidContractAddressError,
validateContractAddress,
validateAddress,
ValidationResult,
} from '@taquito/utils';
import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core';
import { validateContractAddress, validateAddress, ValidationResult } from '@taquito/utils';

interface CachedDataInterface {
[key: string]: {
Expand Down Expand Up @@ -229,7 +224,7 @@ export class RpcClientCache implements RpcClientInterface {
*
* @param address contract address from which we want to retrieve the storage
* @param options contains generic configuration for rpc calls
*
* @throws {@link InvalidContractAddressError}
* @description Access the data of the contract.
*
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-storage
Expand All @@ -256,7 +251,7 @@ export class RpcClientCache implements RpcClientInterface {
*
* @param address contract address from which we want to retrieve the script
* @param options contains generic configuration for rpc calls
*
* @throws {@link InvalidContractAddressError}
* @description Access the code and data of the contract.
*
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
Expand Down Expand Up @@ -284,7 +279,7 @@ export class RpcClientCache implements RpcClientInterface {
* @param address contract address from which we want to retrieve the script
* @param unparsingMode default is { unparsing_mode: "Readable" }
* @param options contains generic configuration for rpc calls
*
* @throws {@link InvalidContractAddressError}
* @description Access the script of the contract and normalize it using the requested unparsing mode.
*
*/
Expand Down Expand Up @@ -824,7 +819,7 @@ export class RpcClientCache implements RpcClientInterface {
* @param contract address of the contract we want to get the entrypoints of
*
* @description Return the list of entrypoints of the contract
*
* @throws {@link InvalidContractAddressError}
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-entrypoints
*
* @version 005_PsBABY5H
Expand Down
12 changes: 1 addition & 11 deletions packages/taquito-utils/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ export {
InvalidKeyError,
InvalidPublicKeyError,
InvalidSignatureError,
InvalidContractAddressError,
} from '@taquito/core';

/**
* @category Error
* @description Error that indicates an invalid contract address being passed or used
*/
export class InvalidContractAddressError extends Error {
public name = 'InvalidContractAddressError';
constructor(public contractAddress: string) {
super(`The contract address '${contractAddress}' is invalid`);
}
}

/**
* @category Error
* @description Error that indicates an invalid chain id being passed or used
Expand Down
21 changes: 11 additions & 10 deletions packages/taquito/src/contract/rpc-contract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ import {
createSmartRollupOriginateOperation,
} from './prepare';
import { smartContractAbstractionSemantic } from './semantic';
import {
validateAddress,
validateContractAddress,
InvalidContractAddressError,
ValidationResult,
} from '@taquito/utils';
import { validateAddress, validateContractAddress, ValidationResult } from '@taquito/utils';
import { EstimationProvider } from '../estimate/estimate-provider-interface';
import { TxRollupOriginationOperation } from '../operations/tx-rollup-origination-operation';
import { TxRollupBatchOperation } from '../operations/tx-rollup-batch-operation';
Expand All @@ -71,7 +66,7 @@ import { ProposalsOperation } from '../operations/proposals-operation';
import { UpdateConsensusKeyOperation } from '../operations/update-consensus-key-operation';
import { SmartRollupAddMessagesOperation } from '../operations/smart-rollup-add-messages-operation';
import { SmartRollupOriginateOperation } from '../operations/smart-rollup-originate-operation';
import { InvalidAddressError } from '@taquito/core';
import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core';

export class RpcContractProvider
extends OperationEmitter
Expand All @@ -88,7 +83,7 @@ export class RpcContractProvider
*
* @param contract contract address you want to get the storage from
* @param schema optional schema can either be the contract script rpc response or a michelson-encoder schema
*
* @throws {@link InvalidContractAddressError}
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
*/
async getStorage<T>(contract: string, schema?: ContractSchema): Promise<T> {
Expand Down Expand Up @@ -117,7 +112,7 @@ export class RpcContractProvider
* @param contract contract address you want to get the storage from
* @param key contract big map key to fetch value from
* @param schema optional schema can either be the contract script rpc response or a michelson-encoder schema
*
* @throws {@link InvalidContractAddressError}
* @deprecated Deprecated in favor of getBigMapKeyByID
*
* @see https://tezos.gitlab.io/api/rpc.html#post-block-id-context-contracts-contract-id-big-map-get
Expand Down Expand Up @@ -769,7 +764,13 @@ export class RpcContractProvider
context
);
}

/**
*
* @description Create an smart contract abstraction for the address specified.
*
* @param address Smart contract address
* @throws {@link InvalidContractAddressError}
*/
async at<T extends DefaultContractType = DefaultContractType>(
address: string,
contractAbstractionComposer: ContractAbstractionComposer<T> = (x) => x as any
Expand Down
4 changes: 2 additions & 2 deletions packages/taquito/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import {
WalletProvider,
WalletTransferParams,
} from './interface';
import { InvalidAddressError } from '@taquito/core';
import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core';
import {
validateAddress,
validateContractAddress,
InvalidContractAddressError,
ValidationResult,
InvalidOperationKindError,
} from '@taquito/utils';
Expand Down Expand Up @@ -333,6 +332,7 @@ export class Wallet {
* smart contract abstraction will leverage the wallet provider to make smart contract calls
*
* @param address Smart contract address
* @throws {@link InvalidContractAddressError} If the contract address is not valid
*/
async at<T extends ContractAbstraction<Wallet>>(
address: string,
Expand Down

0 comments on commit 7b3432e

Please sign in to comment.