From 1b779ec1e69556fd1d05d0c397d85ff5f498886f Mon Sep 17 00:00:00 2001
From: Muhammad-Altabba <24407834+Muhammad-Altabba@users.noreply.github.com>
Date: Tue, 11 Apr 2023 17:43:19 +0200
Subject: [PATCH] move back some local types to web3-eth-contract
---
packages/web3-eth-contract/CHANGELOG.md | 2 +-
packages/web3-eth-contract/src/contract.ts | 8 +-
packages/web3-eth-contract/src/encoding.ts | 6 +-
.../web3-eth-contract/src/log_subscription.ts | 2 +-
packages/web3-eth-contract/src/types.ts | 101 ++++++++++++++++++
packages/web3-eth-contract/src/utils.ts | 3 +-
packages/web3-types/CHANGELOG.md | 2 +-
packages/web3-types/src/eth_contract_types.ts | 98 +----------------
8 files changed, 113 insertions(+), 109 deletions(-)
diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md
index c03b72c9802..da862462aaf 100644
--- a/packages/web3-eth-contract/CHANGELOG.md
+++ b/packages/web3-eth-contract/CHANGELOG.md
@@ -247,7 +247,7 @@ const transactionHash = receipt.transactionHash;
- `getSendTxParams` will now return `input` instead of `data` in returned transaction parameters object (#5915)
- `Contract` constructor will now thrown new `ContractTransactionDataAndInputError` if both `data` and `input` are passed in `ContractInitOptions` for `Contract` constructor (#5915)
-- The types `ContractAbiWithSignature`, `EventLog`, `ContractEventOptions`, `ContractOptions`, `ContractInitOptions` and `PayableCallOptions` moved to `web3-types`. (#5993)
+- The types `ContractInitOptions`, `NonPayableCallOptions` and `PayableCallOptions` are moved to `web3-types`. (#5993)
### Removed
diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts
index 6a82e18abe6..36ec032045f 100644
--- a/packages/web3-eth-contract/src/contract.ts
+++ b/packages/web3-eth-contract/src/contract.ts
@@ -63,11 +63,7 @@ import {
HexString,
LogsInput,
Mutable,
- ContractAbiWithSignature,
- ContractEventOptions,
ContractInitOptions,
- ContractOptions,
- EventLog,
NonPayableCallOptions,
PayableCallOptions,
DataFormat,
@@ -86,6 +82,10 @@ import { ALL_EVENTS_ABI } from './constants';
import { decodeEventABI, decodeMethodReturn, encodeEventABI, encodeMethodABI } from './encoding';
import { LogsSubscription } from './log_subscription';
import {
+ ContractAbiWithSignature,
+ ContractEventOptions,
+ ContractOptions,
+ EventLog,
NonPayableMethodObject,
NonPayableTxOptions,
PayableMethodObject,
diff --git a/packages/web3-eth-contract/src/encoding.ts b/packages/web3-eth-contract/src/encoding.ts
index 92b9eed888b..d40c5a85a0a 100644
--- a/packages/web3-eth-contract/src/encoding.ts
+++ b/packages/web3-eth-contract/src/encoding.ts
@@ -21,9 +21,6 @@ import {
AbiConstructorFragment,
AbiEventFragment,
AbiFunctionFragment,
- ContractAbiWithSignature,
- ContractOptions,
- EventLog,
LogsInput,
BlockNumberOrTag,
Filter,
@@ -51,6 +48,9 @@ import { blockSchema, logSchema } from 'web3-eth';
import { Web3ContractError } from 'web3-errors';
+// eslint-disable-next-line import/no-cycle
+import { ContractOptions, ContractAbiWithSignature, EventLog } from './types';
+
export const encodeEventABI = (
{ address }: ContractOptions,
event: AbiEventFragment & { signature: string },
diff --git a/packages/web3-eth-contract/src/log_subscription.ts b/packages/web3-eth-contract/src/log_subscription.ts
index f80ab00db6e..1863f891c4d 100644
--- a/packages/web3-eth-contract/src/log_subscription.ts
+++ b/packages/web3-eth-contract/src/log_subscription.ts
@@ -18,9 +18,9 @@ along with web3.js. If not, see .
import { AbiEventFragment, LogsInput, HexString, Topic, DataFormat } from 'web3-types';
import { Web3RequestManager, Web3Subscription } from 'web3-core';
// eslint-disable-next-line import/no-cycle
-import { ContractAbiWithSignature, EventLog } from 'web3-types';
import { decodeEventABI } from './encoding';
// eslint-disable-next-line import/no-cycle
+import { EventLog, ContractAbiWithSignature } from './types';
/**
* LogSubscription to be used to subscribe to events logs.
diff --git a/packages/web3-eth-contract/src/types.ts b/packages/web3-eth-contract/src/types.ts
index 89a7ddbcd86..005936f0662 100644
--- a/packages/web3-eth-contract/src/types.ts
+++ b/packages/web3-eth-contract/src/types.ts
@@ -29,6 +29,12 @@ import {
DataFormat,
DEFAULT_RETURN_FORMAT,
FormatType,
+ AbiFragment,
+ Address,
+ Bytes,
+ ContractAbi,
+ HexString32Bytes,
+ Uint,
} from 'web3-types';
// eslint-disable-next-line import/no-cycle
import { LogsSubscription } from './log_subscription';
@@ -36,6 +42,101 @@ import { LogsSubscription } from './log_subscription';
export type NonPayableTxOptions = NonPayableCallOptions;
export type PayableTxOptions = PayableCallOptions;
+export type ContractAbiWithSignature = ReadonlyArray;
+
+export interface EventLog {
+ readonly event: string;
+ readonly id?: string;
+ readonly logIndex?: bigint | number | string;
+ readonly transactionIndex?: bigint | number | string;
+ readonly transactionHash?: HexString32Bytes;
+ readonly blockHash?: HexString32Bytes;
+ readonly blockNumber?: bigint | number | string;
+ readonly address: string;
+ readonly topics: HexString[];
+ readonly data: HexString;
+ readonly raw?: { data: string; topics: unknown[] };
+ readonly returnValues: Record;
+ readonly signature?: HexString;
+}
+
+export interface ContractEventOptions {
+ /**
+ * Let you filter events by indexed parameters, e.g. `{filter: {myNumber: [12,13]}}` means all events where `myNumber` is `12` or `13`.
+ */
+ filter?: Record;
+ /**
+ * The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized` can also be used. For specific range use {@link Contract.getPastEvents}.
+ */
+ fromBlock?: BlockNumberOrTag;
+ /**
+ * This allows to manually set the topics for the event filter. If given the filter property and event signature, (topic[0]) will not be set automatically. Each topic can also be a nested array of topics that behaves as “or” operation between the given nested topics.
+ */
+ topics?: string[];
+}
+
+export interface ContractOptions {
+ /**
+ * The maximum gas provided for a transaction (gas limit).
+ */
+ readonly gas?: Uint;
+ /**
+ * The gas price in wei to use for transactions.
+ */
+ readonly gasPrice?: Uint;
+ /**
+ * The address transactions should be made from.
+ */
+ readonly from?: Address;
+ /**
+ * The byte code of the contract. Used when the contract gets {@link Contract.deploy | deployed}
+ */
+ readonly input?: Bytes;
+ /**
+ * The {@doclink glossary/json_interface | json interface} object derived from the [ABI](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI) of this contract.
+ *
+ * Re-setting this will regenerate the methods and events of the contract instance.
+ *
+ * ```ts
+ * myContract.options.jsonInterface;
+ * > [{
+ * "type":"function",
+ * "name":"foo",
+ * "inputs": [{"name":"a","type":"uint256"}],
+ * "outputs": [{"name":"b","type":"address"}],
+ * "signature": "0x...",
+ * },{
+ * "type":"event",
+ * "name":"Event",
+ * "inputs": [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"bytes32","indexed":false}],
+ * "signature": "0x...",
+ * }]
+ *
+ * // Set a new ABI interface
+ * // Note: the "signature" of every function and event's ABI is not needed to be provided when assigning.
+ * // It will be calculated and set automatically inside the setter.
+ * myContract.options.jsonInterface = [...];
+ * ```
+ */
+ get jsonInterface(): ContractAbiWithSignature;
+ set jsonInterface(value: ContractAbi);
+
+ /**
+ * The address used for this contract instance. All transactions generated by web3.js from this contract will contain this address as the `to`.
+ *
+ * The address will be stored in lowercase.
+ *
+ * ```ts
+ * myContract.options.address;
+ * > '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
+ *
+ * // set a new address
+ * myContract.options.address = '0x1234FFDD...';
+ * ```
+ */
+ address?: Address; // All transactions generated by web3.js from this contract will contain this address as the "to".
+}
+
export interface NonPayableMethodObject {
arguments: Inputs;
/**
diff --git a/packages/web3-eth-contract/src/utils.ts b/packages/web3-eth-contract/src/utils.ts
index 4c41a8a60d3..b52f8d8f755 100644
--- a/packages/web3-eth-contract/src/utils.ts
+++ b/packages/web3-eth-contract/src/utils.ts
@@ -24,12 +24,11 @@ import {
HexString,
NonPayableCallOptions,
PayableCallOptions,
- ContractOptions,
ContractInitOptions,
} from 'web3-types';
import { isNullish, mergeDeep, toHex } from 'web3-utils';
import { encodeMethodABI } from './encoding';
-import { Web3ContractContext } from './types';
+import { ContractOptions, Web3ContractContext } from './types';
export const getSendTxParams = ({
abi,
diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md
index 8849f76aace..392f2ad306a 100644
--- a/packages/web3-types/CHANGELOG.md
+++ b/packages/web3-types/CHANGELOG.md
@@ -90,4 +90,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `data` property in `TransactionOutput` was renamed to `input` (#5915)
- The method `signTransaction` inside `Web3BaseWalletAccount` is now utilizing the type `Transaction` for its argument. (#5993)
- The types `FMT_NUMBER`, `NumberTypes`, `FMT_BYTES`, `ByteTypes`, `DataFormat`, `DEFAULT_RETURN_FORMAT`, `ETH_DATA_FORMAT` and `FormatType` moved from `web3-utils`. (#5993)
-- The types `ContractAbiWithSignature`, `EventLog`, `ContractEventOptions`, `ContractOptions`, `ContractInitOptions` and `PayableCallOptions` are moved from `web3-eth-contract`. (#5993)
+- The types `ContractInitOptions`, `NonPayableCallOptions` and `PayableCallOptions` are moved from `web3-eth-contract`. (#5993)
diff --git a/packages/web3-types/src/eth_contract_types.ts b/packages/web3-types/src/eth_contract_types.ts
index 1646ebb8dfc..4d9fd5bd81b 100644
--- a/packages/web3-types/src/eth_contract_types.ts
+++ b/packages/web3-types/src/eth_contract_types.ts
@@ -15,107 +15,11 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see .
*/
-import { Address, BlockNumberOrTag, HexString32Bytes, Uint } from './eth_types';
-import { AbiFragment, ContractAbi } from './eth_abi_types';
+import { Address, Uint } from './eth_types';
import { SupportedProviders } from './web3_base_provider';
import { Bytes, HexString } from './primitives_types';
import { EthExecutionAPI } from './apis/eth_execution_api';
-export type ContractAbiWithSignature = ReadonlyArray;
-
-export interface EventLog {
- readonly event: string;
- readonly id?: string;
- readonly logIndex?: bigint | number | string;
- readonly transactionIndex?: bigint | number | string;
- readonly transactionHash?: HexString32Bytes;
- readonly blockHash?: HexString32Bytes;
- readonly blockNumber?: bigint | number | string;
- readonly address: string;
- readonly topics: HexString[];
- readonly data: HexString;
- readonly raw?: { data: string; topics: unknown[] };
- readonly returnValues: Record;
- readonly signature?: HexString;
-}
-
-export interface ContractEventOptions {
- /**
- * Let you filter events by indexed parameters, e.g. `{filter: {myNumber: [12,13]}}` means all events where `myNumber` is `12` or `13`.
- */
- filter?: Record;
- /**
- * The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized` can also be used. For specific range use {@link Contract.getPastEvents}.
- */
- fromBlock?: BlockNumberOrTag;
- /**
- * This allows to manually set the topics for the event filter. If given the filter property and event signature, (topic[0]) will not be set automatically. Each topic can also be a nested array of topics that behaves as “or” operation between the given nested topics.
- */
- topics?: string[];
-}
-
-export interface ContractOptions {
- /**
- * The maximum gas provided for a transaction (gas limit).
- */
- readonly gas?: Uint;
- /**
- * The gas price in wei to use for transactions.
- */
- readonly gasPrice?: Uint;
- /**
- * The address transactions should be made from.
- */
- readonly from?: Address;
- /**
- * The byte code of the contract. Used when the contract gets {@link Contract.deploy | deployed}
- */
- readonly input?: Bytes;
- /**
- * The {@doclink glossary/json_interface | json interface} object derived from the [ABI](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI) of this contract.
- *
- * Re-setting this will regenerate the methods and events of the contract instance.
- *
- * ```ts
- * myContract.options.jsonInterface;
- * > [{
- * "type":"function",
- * "name":"foo",
- * "inputs": [{"name":"a","type":"uint256"}],
- * "outputs": [{"name":"b","type":"address"}],
- * "signature": "0x...",
- * },{
- * "type":"event",
- * "name":"Event",
- * "inputs": [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"bytes32","indexed":false}],
- * "signature": "0x...",
- * }]
- *
- * // Set a new ABI interface
- * // Note: the "signature" of every function and event's ABI is not needed to be provided when assigning.
- * // It will be calculated and set automatically inside the setter.
- * myContract.options.jsonInterface = [...];
- * ```
- */
- get jsonInterface(): ContractAbiWithSignature;
- set jsonInterface(value: ContractAbi);
-
- /**
- * The address used for this contract instance. All transactions generated by web3.js from this contract will contain this address as the `to`.
- *
- * The address will be stored in lowercase.
- *
- * ```ts
- * myContract.options.address;
- * > '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
- *
- * // set a new address
- * myContract.options.address = '0x1234FFDD...';
- * ```
- */
- address?: Address; // All transactions generated by web3.js from this contract will contain this address as the "to".
-}
-
export interface ContractInitOptions {
/**
* The maximum gas provided for a transaction (gas limit).