Skip to content

Commit

Permalink
move back some local types to web3-eth-contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba committed Apr 11, 2023
1 parent 17be9dd commit 1b779ec
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 109 deletions.
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ import {
HexString,
LogsInput,
Mutable,
ContractAbiWithSignature,
ContractEventOptions,
ContractInitOptions,
ContractOptions,
EventLog,
NonPayableCallOptions,
PayableCallOptions,
DataFormat,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-eth-contract/src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import {
AbiConstructorFragment,
AbiEventFragment,
AbiFunctionFragment,
ContractAbiWithSignature,
ContractOptions,
EventLog,
LogsInput,
BlockNumberOrTag,
Filter,
Expand Down Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/src/log_subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
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.
Expand Down
101 changes: 101 additions & 0 deletions packages/web3-eth-contract/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,114 @@ 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';

export type NonPayableTxOptions = NonPayableCallOptions;
export type PayableTxOptions = PayableCallOptions;

export type ContractAbiWithSignature = ReadonlyArray<AbiFragment & { signature: HexString }>;

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<string, unknown>;
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<string, unknown>;
/**
* 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<Inputs = unknown[], Outputs = unknown[]> {
arguments: Inputs;
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-eth-contract/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
98 changes: 1 addition & 97 deletions packages/web3-types/src/eth_contract_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,107 +15,11 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

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<AbiFragment & { signature: HexString }>;

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<string, unknown>;
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<string, unknown>;
/**
* 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).
Expand Down

0 comments on commit 1b779ec

Please sign in to comment.