From 20dd4d2d340d99e4630df059a60ff6964c178d1f Mon Sep 17 00:00:00 2001 From: Vladislav Shabanov Date: Fri, 8 Mar 2019 17:52:24 +0700 Subject: [PATCH 1/2] Separate Transaction and TransactionConfig --- packages/web3-core/types/index.d.ts | 39 ++++++++++++++++----- packages/web3-eth-accounts/types/index.d.ts | 10 +++--- packages/web3-eth-personal/types/index.d.ts | 6 ++-- packages/web3-eth/types/index.d.ts | 19 +++++----- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index e0dc08e7212..f56e3edff9f 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -60,7 +60,7 @@ export class AbstractWeb3Module { } export interface TransactionSigner { - sign(tx: Transaction): Promise; + sign(transactionConfig: TransactionConfig): Promise; } export interface SignedTransaction { @@ -117,23 +117,44 @@ export interface PromiEvent extends Promise { } export interface Transaction { + hash: string; + nonce: number; + blockHash: string | null; + blockNumber: number | null; + transactionIndex: number | null; + from: string; + to: string; + value: string; + gasPrice: string; + gas: number; + input: string; +} + +export interface TransactionConfig { from?: string | number; to?: string; - gasPrice?: string; - gas?: number | string; value?: number | string; - chainId?: number; + gas?: number | string; + gasPrice?: number | string; data?: string; nonce?: number; - v?: string; - r?: string; - s?: string; - hash?: string; + chainId?: number; } export interface RLPEncodedTransaction { raw: string; - tx: Transaction; + tx: { + nonce: string; + gasPrice: string; + gas: string; + to: string; + value: string; + input: string; + r: string; + s: string; + v: string; + hash: string; + } } export interface TransactionReceipt { diff --git a/packages/web3-eth-accounts/types/index.d.ts b/packages/web3-eth-accounts/types/index.d.ts index ce953c34567..661a645d4e3 100644 --- a/packages/web3-eth-accounts/types/index.d.ts +++ b/packages/web3-eth-accounts/types/index.d.ts @@ -17,7 +17,7 @@ * @date 2018 */ -import {AbstractWeb3Module, Transaction, Web3ModuleOptions, SignedTransaction} from 'web3-core'; +import {AbstractWeb3Module, TransactionConfig, Web3ModuleOptions, SignedTransaction} from 'web3-core'; import {provider} from 'web3-providers'; export class Accounts extends AbstractWeb3Module { @@ -27,7 +27,7 @@ export class Accounts extends AbstractWeb3Module { privateKeyToAccount(privateKey: string): Account; - signTransaction(tx: Transaction, privateKey: string, callback?: () => void): Promise; + signTransaction(transactionConfig: TransactionConfig, privateKey: string, callback?: () => void): Promise; recoverTransaction(signature: string): string; @@ -35,8 +35,8 @@ export class Accounts extends AbstractWeb3Module { sign(data: string, privateKey: string): Sign; - recover(message: SignedTransaction): string; - recover(message: string | SignedTransaction, signature: string, preFixed?: boolean): string; + recover(signedTransaction: SignedTransaction): string; + recover(message: string, signature: string, preFixed?: boolean): string; recover(message: string, v: string, r: string, s: string, preFixed?: boolean): string; encrypt(privateKey: string, password: string): EncryptedKeystoreV3Json; @@ -75,7 +75,7 @@ export interface Account { address: string; privateKey: string; signTransaction: ( - tx: Transaction, + transactionConfig: TransactionConfig, callback?: (signTransaction: SignedTransaction) => void ) => Promise; sign: (data: string) => Sign; diff --git a/packages/web3-eth-personal/types/index.d.ts b/packages/web3-eth-personal/types/index.d.ts index c8d7faea7db..90ca18f4f1b 100644 --- a/packages/web3-eth-personal/types/index.d.ts +++ b/packages/web3-eth-personal/types/index.d.ts @@ -20,7 +20,7 @@ import {Accounts} from 'web3-eth-accounts'; import {provider} from 'web3-providers'; -import {AbstractWeb3Module, Providers, RLPEncodedTransaction, Transaction, Web3ModuleOptions} from 'web3-core'; +import {AbstractWeb3Module, Providers, RLPEncodedTransaction, TransactionConfig, Web3ModuleOptions} from 'web3-core'; export class Personal extends AbstractWeb3Module { constructor(provider: provider, accounts: Accounts, options?: Web3ModuleOptions); @@ -41,13 +41,13 @@ export class Personal extends AbstractWeb3Module { ): Promise; signTransaction( - transation: Transaction, + transactionConfig: TransactionConfig, password: string, callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void ): Promise; sendTransaction( - transation: Transaction, + transactionConfig: TransactionConfig, password: string, callback?: (error: Error, transactionHash: string) => void ): Promise; diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index 1e57d289922..18784ab1b9f 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -24,6 +24,7 @@ import { PromiEvent, RLPEncodedTransaction, Transaction, + TransactionConfig, TransactionReceipt, Web3ModuleOptions } from 'web3-core'; @@ -110,22 +111,22 @@ export class Eth extends AbstractWeb3Module { getTransactionCount(address: string, callback?: (error: Error, count: number) => void): Promise; getTransactionCount(address: string, defaultBlock: number | string, callback?: (error: Error, count: number) => void): Promise; - sendTransaction(transaction: Transaction, callback?: (error: Error, hash: string) => void): PromiEvent; + sendTransaction(transactionConfig: TransactionConfig, callback?: (error: Error, hash: string) => void): PromiEvent; sendSignedTransaction(signedTransactionData: string, callback?: (error: Error, gas: string) => void): PromiEvent sign(dataToSign: string, address: string | number, callback?: (error: Error, signature: string) => void): Promise; - signTransaction(transaction: Transaction, callback?: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise; - signTransaction(transaction: Transaction, address: string): Promise; - signTransaction(transaction: Transaction, address: string, callback: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise; + signTransaction(transactionConfig: TransactionConfig, callback?: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise; + signTransaction(transactionConfig: TransactionConfig, address: string): Promise; + signTransaction(transactionConfig: TransactionConfig, address: string, callback: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise; - call(transaction: Transaction): Promise; - call(transaction: Transaction, defaultBlock?: number | string): Promise; - call(transaction: Transaction, callback?: (error: Error, data: string) => void): Promise; - call(transaction: Transaction, defaultBlock: number | string, callback: (error: Error, data: string) => void): Promise; + call(transactionConfig: TransactionConfig): Promise; + call(transactionConfig: TransactionConfig, defaultBlock?: number | string): Promise; + call(transactionConfig: TransactionConfig, callback?: (error: Error, data: string) => void): Promise; + call(transactionConfig: TransactionConfig, defaultBlock: number | string, callback: (error: Error, data: string) => void): Promise; - estimateGas(transaction: Transaction, callback?: (error: Error, gas: number) => void): Promise; + estimateGas(transactionConfig: TransactionConfig, callback?: (error: Error, gas: number) => void): Promise; getPastLogs(options: PastLogsOptions, callback?: (error: Error, logs: Log[]) => void): Promise; From 7e7fa42be54069244b7b3b6a22c29fe3cae25c88 Mon Sep 17 00:00:00 2001 From: Vladislav Shabanov Date: Fri, 8 Mar 2019 19:31:54 +0700 Subject: [PATCH 2/2] value and gasPrice can be BN --- packages/web3-core/types/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index f56e3edff9f..1f1bd9dd5fe 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -29,6 +29,7 @@ import { WebsocketProvider, WebsocketProviderOptions } from 'web3-providers'; +import {BN} from 'web3-utils'; export class AbstractWeb3Module { constructor( @@ -133,9 +134,9 @@ export interface Transaction { export interface TransactionConfig { from?: string | number; to?: string; - value?: number | string; + value?: number | string | BN; gas?: number | string; - gasPrice?: number | string; + gasPrice?: number | string | BN; data?: string; nonce?: number; chainId?: number;