Skip to content

Commit

Permalink
Merge pull request #192 from ethereum-ts/kk/web3-upgrade-1.2.4
Browse files Browse the repository at this point in the history
upgrade web3, deal with breaking changes
  • Loading branch information
krzkaczor committed Nov 24, 2019
2 parents 8b28654 + 1d7ceda commit 23ce4b9
Show file tree
Hide file tree
Showing 7 changed files with 712 additions and 426 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -24,7 +24,6 @@
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"devDependencies": {
"@types/web3": "^1.0.20",
"krzkaczor-solc": "^0.4.24",
"mocha": "^4.0.1",
"mocha-prepare": "^0.1.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/typechain-target-web3-v1/lib/generation.ts
Expand Up @@ -14,10 +14,10 @@ import { values } from "lodash";
export function codegen(contract: Contract) {
const template = `
import BN from "bn.js";
import Contract, { contractOptions } from "web3/eth/contract";
import { EventLog, Callback, EventEmitter } from "web3/types";
import { TransactionObject, BlockType } from "web3/eth/types";
import { ContractEvent } from "./types";
import { Contract, ContractOptions } from "web3-eth-contract";
import { EventLog } from "web3-core";
import { EventEmitter } from "events";
import { ContractEvent, Callback, TransactionObject, BlockType } from "./types";
interface EventOptions {
filter?: object;
Expand All @@ -26,7 +26,7 @@ export function codegen(contract: Contract) {
}
export class ${contract.name} extends Contract {
constructor(jsonInterface: any[], address?: string, options?: contractOptions);
constructor(jsonInterface: any[], address?: string, options?: ContractOptions);
clone(): ${contract.name};
methods: {
${codegenForFunctions(contract.functions)}
Expand Down
32 changes: 26 additions & 6 deletions packages/typechain-target-web3-v1/lib/index.ts
Expand Up @@ -44,8 +44,7 @@ export default class Web3 extends TsGeneratorPlugin {
{
path: join(this.outDirAbs, "types.d.ts"),
contents: `
import { EventLog } from "web3/types";
import { TransactionObject, BlockType } from "web3/eth/types";
import { EventLog } from "web3-core/types";
import BN from "bn.js";
import { EventEmitter } from "events";
// @ts-ignore
Expand Down Expand Up @@ -75,13 +74,34 @@ export default class Web3 extends TsGeneratorPlugin {
returnValues: T;
}
export interface ContractEventEmitter<T> extends EventEmitter {
on(event: 'data' | 'changed', listener: (event: ContractEventLog<T>) => void): this;
on(event: 'error', listener: (error: Error) => void): this;
on(event: "data" | "changed", listener: (event: ContractEventLog<T>) => void): this;
on(event: "error", listener: (error: Error) => void): this;
}
export type ContractEvent<T> = (
options?: EventOptions,
cb?: Callback<ContractEventLog<T>>
) => ContractEventEmitter<T>;`,
cb?: Callback<ContractEventLog<T>>,
) => ContractEventEmitter<T>;
export interface Tx {
nonce?: string | number;
chainId?: string | number;
from?: string;
to?: string;
data?: string;
value?: string | number;
gas?: string | number;
gasPrice?: string | number;
}
export interface TransactionObject<T> {
arguments: any[];
call(tx?: Tx): Promise<T>;
send(tx?: Tx): PromiEvent<T>;
estimateGas(tx?: Tx): Promise<number>;
encodeABI(): string;
}
export type BlockType = "latest" | "pending" | "genesis" | number;`,
},
];
}
Expand Down
6 changes: 2 additions & 4 deletions packages/typechain-target-web3-v1/package.json
Expand Up @@ -10,11 +10,9 @@
"version": "1.0.2",
"license": "MIT",
"repository": "https://github.com/ethereum-ts/Typechain",
"devDependencies": {
"web3": "1.2.1"
},
"dependencies": {
"lodash": "^4.17.15"
"lodash": "^4.17.15",
"web3": "^1.2.4"
},
"peerDependencies": {
"typechain": "^1.0.0"
Expand Down
3 changes: 1 addition & 2 deletions test/integration/targets/web3-v1/package.json
Expand Up @@ -4,13 +4,12 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"web3": "^1.2.1"
"web3": "^1.2.4"
},
"devDependencies": {
"@types/bn.js": "^4.11.1",
"@types/chai": "^4.1.2",
"@types/underscore": "^1.8.9",
"@types/web3": "^1.0.19",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
Expand Down

0 comments on commit 23ce4b9

Please sign in to comment.