Skip to content

Commit

Permalink
fix(connector-quorum): web3 Contract type usage
Browse files Browse the repository at this point in the history
This was broken by an earlier commit:
d75b9af

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Apr 19, 2021
1 parent ec22a0f commit 80c8253
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 80c8253

Please sign in to comment.