Skip to content

Commit

Permalink
Merge pull request #2479 from vshab/feature/fix-transation-typings
Browse files Browse the repository at this point in the history
 Separate Transaction and TransactionConfig in typings
  • Loading branch information
nivida authored Mar 18, 2019
2 parents 7739107 + c7270e8 commit 441135e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
40 changes: 31 additions & 9 deletions packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
WebsocketProvider,
WebsocketProviderOptions
} from 'web3-providers';
import {BN} from 'web3-utils';

export class AbstractWeb3Module {
constructor(provider: provider, options?: Web3ModuleOptions, methodFactory?: any, net?: net.Socket);
Expand All @@ -55,7 +56,7 @@ export class AbstractWeb3Module {
}

export interface TransactionSigner {
sign(tx: Transaction): Promise<SignedTransaction>;
sign(transactionConfig: TransactionConfig): Promise<SignedTransaction>;
}

export interface SignedTransaction {
Expand Down Expand Up @@ -112,23 +113,44 @@ export interface PromiEvent<T> extends Promise<T> {
}

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;
value?: number | string | BN;
gas?: number | string;
value?: number | string;
chainId?: number;
gasPrice?: number | string | BN;
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 {
Expand Down
10 changes: 5 additions & 5 deletions packages/web3-eth-accounts/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,16 +27,16 @@ export class Accounts extends AbstractWeb3Module {

privateKeyToAccount(privateKey: string): Account;

signTransaction(tx: Transaction, privateKey: string, callback?: () => void): Promise<SignedTransaction>;
signTransaction(transactionConfig: TransactionConfig, privateKey: string, callback?: () => void): Promise<SignedTransaction>;

recoverTransaction(signature: string): string;

hashMessage(message: string): string;

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;
Expand Down Expand Up @@ -75,7 +75,7 @@ export interface Account {
address: string;
privateKey: string;
signTransaction: (
tx: Transaction,
transactionConfig: TransactionConfig,
callback?: (signTransaction: SignedTransaction) => void
) => Promise<SignedTransaction>;
sign: (data: string) => Sign;
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-eth-personal/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,13 +41,13 @@ export class Personal extends AbstractWeb3Module {
): Promise<string>;

signTransaction(
transation: Transaction,
transactionConfig: TransactionConfig,
password: string,
callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void
): Promise<RLPEncodedTransaction>;

sendTransaction(
transation: Transaction,
transactionConfig: TransactionConfig,
password: string,
callback?: (error: Error, transactionHash: string) => void
): Promise<string>;
Expand Down
19 changes: 10 additions & 9 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PromiEvent,
RLPEncodedTransaction,
Transaction,
TransactionConfig,
TransactionReceipt,
Web3ModuleOptions
} from 'web3-core';
Expand Down Expand Up @@ -110,22 +111,22 @@ export class Eth extends AbstractWeb3Module {
getTransactionCount(address: string, callback?: (error: Error, count: number) => void): Promise<number>;
getTransactionCount(address: string, defaultBlock: number | string, callback?: (error: Error, count: number) => void): Promise<number>;

sendTransaction(transaction: Transaction, callback?: (error: Error, hash: string) => void): PromiEvent<TransactionReceipt>;
sendTransaction(transactionConfig: TransactionConfig, callback?: (error: Error, hash: string) => void): PromiEvent<TransactionReceipt>;

sendSignedTransaction(signedTransactionData: string, callback?: (error: Error, gas: string) => void): PromiEvent<TransactionReceipt>

sign(dataToSign: string, address: string | number, callback?: (error: Error, signature: string) => void): Promise<string>;

signTransaction(transaction: Transaction, callback?: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise<RLPEncodedTransaction>;
signTransaction(transaction: Transaction, address: string): Promise<RLPEncodedTransaction>;
signTransaction(transaction: Transaction, address: string, callback: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise<RLPEncodedTransaction>;
signTransaction(transactionConfig: TransactionConfig, callback?: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise<RLPEncodedTransaction>;
signTransaction(transactionConfig: TransactionConfig, address: string): Promise<RLPEncodedTransaction>;
signTransaction(transactionConfig: TransactionConfig, address: string, callback: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise<RLPEncodedTransaction>;

call(transaction: Transaction): Promise<string>;
call(transaction: Transaction, defaultBlock?: number | string): Promise<string>;
call(transaction: Transaction, callback?: (error: Error, data: string) => void): Promise<string>;
call(transaction: Transaction, defaultBlock: number | string, callback: (error: Error, data: string) => void): Promise<string>;
call(transactionConfig: TransactionConfig): Promise<string>;
call(transactionConfig: TransactionConfig, defaultBlock?: number | string): Promise<string>;
call(transactionConfig: TransactionConfig, callback?: (error: Error, data: string) => void): Promise<string>;
call(transactionConfig: TransactionConfig, defaultBlock: number | string, callback: (error: Error, data: string) => void): Promise<string>;

estimateGas(transaction: Transaction, callback?: (error: Error, gas: number) => void): Promise<number>;
estimateGas(transactionConfig: TransactionConfig, callback?: (error: Error, gas: number) => void): Promise<number>;

getPastLogs(options: PastLogsOptions, callback?: (error: Error, logs: Log[]) => void): Promise<Log[]>;

Expand Down

0 comments on commit 441135e

Please sign in to comment.