Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify SignTransaction's argument types #5993

4 changes: 2 additions & 2 deletions docs/docs/guides/web3_plugin_guide/plugin_authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ A workaround for this issue is available, below is an example of it:
import { Web3Context, Web3PluginBase } from 'web3-core';
import { ContractAbi } from 'web3-eth-abi';
import Contract from 'web3-eth-contract';
import { Address } from 'web3-types';
import { DataFormat, DEFAULT_RETURN_FORMAT, format } from 'web3-utils';
import { Address, DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-types';
import { format } from 'web3-utils';

import { ERC20TokenAbi } from './ERC20Token';

Expand Down
1 change: 1 addition & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- If a transaction object with a `data` property is passed to `txInputOptionsFormatter`, it will now be replaced with `input` (#5915)
- The types `TransactionTypeParser` and `TransactionBuilder` are now utilizing the type `Transaction` for the transaction object. (#5993)

### Removed

Expand Down
5 changes: 2 additions & 3 deletions packages/web3-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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 { HexString } from 'web3-types';
import { HexString, Transaction } from 'web3-types';

// TODO: When we have `web3-types` package we can share TransactionType
export type TransactionTypeParser = (transaction: Record<string, unknown>) => HexString | undefined;
export type TransactionTypeParser = (transaction: Transaction) => HexString | undefined;
6 changes: 3 additions & 3 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
HexString,
EthExecutionAPI,
Web3BaseProvider,
Transaction,
} from 'web3-types';
import { isNullish } from 'web3-utils';
import { ExistingPluginNamespaceError } from 'web3-errors';
Expand Down Expand Up @@ -368,11 +369,10 @@ export class Web3Context<
}

// To avoid cycle dependency declare this type in this file
// TODO: When we have `web3-types` package we can share TransactionType
export type TransactionBuilder<API extends Web3APISpec = unknown> = <
ReturnType = Record<string, unknown>,
ReturnType = Transaction,
>(options: {
transaction: Record<string, unknown>;
transaction: Transaction;
web3Context: Web3Context<API>;
privateKey?: HexString | Buffer;
}) => Promise<ReturnType>;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-core/src/web3_subscription_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ 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 { Web3APISpec } from 'web3-types';
import { DataFormat, DEFAULT_RETURN_FORMAT, Web3APISpec } from 'web3-types';
import { ProviderError, SubscriptionError } from 'web3-errors';
import { isNullish, DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-utils';
import { isNullish } from 'web3-utils';
import { isSupportSubscriptions } from './utils';
import { Web3RequestManager, Web3RequestManagerEvent } from './web3_request_manager';
import { Web3SubscriptionConstructor } from './web3_subscriptions';
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-core/src/web3_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

// eslint-disable-next-line max-classes-per-file
import { DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-utils';
import {
HexString,
BlockOutput,
Expand All @@ -27,6 +26,8 @@ import {
Log,
JsonRpcNotification,
JsonRpcSubscriptionResult,
DataFormat,
DEFAULT_RETURN_FORMAT,
} from 'web3-types';
import { jsonRpc } from 'web3-utils';
import { Web3EventEmitter, Web3EventMap } from './web3_event_emitter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 { DEFAULT_RETURN_FORMAT } from 'web3-utils';
import { DEFAULT_RETURN_FORMAT } from 'web3-types';
import { Web3RequestManagerEvent } from '../../src/web3_request_manager';
import { Web3SubscriptionManager } from '../../src/web3_subscription_manager';
import { ExampleSubscription } from './fixtures/example_subscription';
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Moved @ethereumjs/tx, @ethereumjs/common code to our source code (#5963)
- The method `signTransaction` returned by `privateKeyToAccount` is now accepting the type `Transaction` for its argument. (#5993)
3 changes: 2 additions & 1 deletion packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
PBKDF2SHA256Params,
ScryptParams,
KeyStore,
Transaction,
} from 'web3-types';
import {
bytesToBuffer,
Expand Down Expand Up @@ -594,7 +595,7 @@ export const privateKeyToAccount = (privateKey: Bytes, ignoreLength?: boolean):
address: privateKeyToAddress(privateKeyBuffer),
privateKey: bytesToHex(privateKeyBuffer),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
signTransaction: (_tx: Record<string, unknown>) => {
signTransaction: (_tx: Transaction) => {
throw new TransactionSigningError('Do not have network access to sign the transaction');
},
sign: (data: Record<string, unknown> | string) =>
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-contract/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +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)

### Removed

Expand Down
22 changes: 9 additions & 13 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ import {
HexString,
LogsInput,
Mutable,
} from 'web3-types';
import {
ContractAbiWithSignature,
ContractEventOptions,
ContractInitOptions,
ContractOptions,
EventLog,
NonPayableCallOptions,
PayableCallOptions,
DataFormat,
DEFAULT_RETURN_FORMAT,
format,
isDataFormat,
toChecksumAddress,
} from 'web3-utils';
} from 'web3-types';
import { format, isDataFormat, toChecksumAddress } from 'web3-utils';
import {
isNullish,
validator,
Expand All @@ -83,15 +86,8 @@ import { ALL_EVENTS_ABI } from './constants';
import { decodeEventABI, decodeMethodReturn, encodeEventABI, encodeMethodABI } from './encoding';
import { LogsSubscription } from './log_subscription';
import {
ContractAbiWithSignature,
ContractEventOptions,
ContractInitOptions,
ContractOptions,
EventLog,
NonPayableCallOptions,
NonPayableMethodObject,
NonPayableTxOptions,
PayableCallOptions,
PayableMethodObject,
PayableTxOptions,
Web3ContractContext,
Expand Down
18 changes: 8 additions & 10 deletions packages/web3-eth-contract/src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ 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 {
DataFormat,
DEFAULT_RETURN_FORMAT,
FMT_BYTES,
FMT_NUMBER,
format,
isNullish,
} from 'web3-utils';
import { format, isNullish } from 'web3-utils';

import {
AbiConstructorFragment,
AbiEventFragment,
AbiFunctionFragment,
ContractAbiWithSignature,
ContractOptions,
EventLog,
LogsInput,
BlockNumberOrTag,
Filter,
HexString,
Topic,
Numbers,
FMT_NUMBER,
FMT_BYTES,
DataFormat,
DEFAULT_RETURN_FORMAT,
} from 'web3-types';

import {
Expand All @@ -50,8 +50,6 @@ import {
import { blockSchema, logSchema } from 'web3-eth';

import { Web3ContractError } from 'web3-errors';
// eslint-disable-next-line import/no-cycle
import { ContractAbiWithSignature, ContractOptions, EventLog } from './types';

export const encodeEventABI = (
{ address }: ContractOptions,
Expand Down
6 changes: 2 additions & 4 deletions packages/web3-eth-contract/src/log_subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ 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 { AbiEventFragment, LogsInput, HexString, Topic } from 'web3-types';
import { AbiEventFragment, LogsInput, HexString, Topic, DataFormat } from 'web3-types';
import { Web3RequestManager, Web3Subscription } from 'web3-core';
// eslint-disable-next-line import/no-cycle
import { DataFormat } from 'web3-utils';
// 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 { ContractAbiWithSignature, EventLog } from './types';

/**
* LogSubscription to be used to subscribe to events logs.
Expand Down
Loading