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

fix(connector-quorum): web3 Contract type usage #810

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { Express } from "express";
import { promisify } from "util";
import { Optional } from "typescript-optional";
import Web3 from "web3";

import { Contract, ContractSendMethod } from "web3-eth-contract";
// The strange way of obtaining the contract class here is like this because
// web3-eth internally sub-classes the Contract class at runtime
// @see https://stackoverflow.com/a/63639280/698470
const Contract = new Web3().eth.Contract;
import { ContractSendMethod } from "web3-eth-contract";
import { TransactionReceipt } from "web3-eth";

import {
Expand Down Expand Up @@ -83,7 +86,8 @@ export class PluginLedgerConnectorQuorum
private readonly web3: Web3;
private httpServer: Server | SecureServer | null = null;
private contracts: {
[name: string]: Contract;
// @see https://stackoverflow.com/a/63639280/698470
[name: string]: InstanceType<typeof Contract>;
} = {};

private endpoints: IWebServiceEndpoint[] | undefined;
Expand Down Expand Up @@ -227,7 +231,7 @@ export class PluginLedgerConnectorQuorum
}

const { contractAddress } = req;
const aContract = new Contract(abi, contractAddress);
const aContract = new this.web3.eth.Contract(abi, contractAddress);
const methodRef = aContract.methods[req.methodName];

Checks.truthy(methodRef, `${fnTag} YourContract.${req.methodName}`);
Expand Down Expand Up @@ -320,7 +324,7 @@ export class PluginLedgerConnectorQuorum
contractJSON.networks = network;
keychainPlugin.set(contractName, contractJSON);
}
const contract = new Contract(
const contract = new this.web3.eth.Contract(
contractJSON.abi,
contractJSON.networks[networkId].address,
);
Expand Down Expand Up @@ -575,7 +579,7 @@ export class PluginLedgerConnectorQuorum
req.contractName,
)) as any;
this.log.info(JSON.stringify(contractJSON));
const contract = new Contract(
const contract = new this.web3.eth.Contract(
contractJSON.abi,
receipt.transactionReceipt.contractAddress,
);
Expand Down