diff --git a/integration/config.ts b/integration/config.ts index 8366927..b6cd14b 100644 --- a/integration/config.ts +++ b/integration/config.ts @@ -10,8 +10,8 @@ if (process.env.SEED_WORDS) { seedphrase, configJson.nodeUri, 0, - 2, + 5, ) } -export const config = configJson as Config +export const config: Config = configJson as any diff --git a/integration/config/config.json b/integration/config/config.json index 4e15b7b..db04650 100644 --- a/integration/config/config.json +++ b/integration/config/config.json @@ -7,5 +7,5 @@ "threshold": 0, "password": "secret", "address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb", - "verbose": false + "verbose": "error" } diff --git a/package.json b/package.json index 5345942..04ec3d2 100644 --- a/package.json +++ b/package.json @@ -69,8 +69,6 @@ "save-file": "^2.3.1", "uuid": "^3.3.2", "web3": "1.0.0-beta.37", - "web3-eth-contract": "1.0.0-beta.37", - "web3-utils": "1.0.0-beta.37", "whatwg-url": "^7.0.0" }, "devDependencies": { diff --git a/src/keeper/ContractHandler.ts b/src/keeper/ContractHandler.ts index 4e012c2..612704c 100644 --- a/src/keeper/ContractHandler.ts +++ b/src/keeper/ContractHandler.ts @@ -1,11 +1,11 @@ -import Contract from "web3-eth-contract" +import { Contract } from "web3-eth-contract" import Logger from "../utils/Logger" import Keeper from "./Keeper" import Web3Provider from "./Web3Provider" export default class ContractHandler { - public static async get(what: string): Contract { + public static async get(what: string): Promise { const where = (await (await Keeper.getInstance()).getNetworkName()).toLowerCase() try { return ContractHandler.contracts.get(what) || await ContractHandler.load(what, where) diff --git a/src/keeper/contracts/ContractBase.ts b/src/keeper/contracts/ContractBase.ts index 62d3fbb..aba6397 100644 --- a/src/keeper/contracts/ContractBase.ts +++ b/src/keeper/contracts/ContractBase.ts @@ -1,6 +1,5 @@ -import Event from "web3" -import Contract from "web3-eth-contract" -import {Receipt} from "web3-utils" +import { Contract } from "web3-eth-contract" +import { TransactionReceipt } from "web3-core" import Logger from "../../utils/Logger" import ContractHandler from "../ContractHandler" import Web3Provider from "../Web3Provider" @@ -16,7 +15,7 @@ export default abstract class ContractBase { this.contractName = contractName } - public async getEventData(eventName: any, options: any): Promise { + public async getEventData(eventName: any, options: any) { if (!this.contract.events[eventName]) { throw new Error(`Event "${eventName}" not found on contract "${this.contractName}"`) } @@ -41,14 +40,14 @@ export default abstract class ContractBase { this.contract = await ContractHandler.get(this.contractName) } - protected async sendFrom(name: string, args: any[], from?: string): Promise { + protected async sendFrom(name: string, args: any[], from?: string): Promise { if (!from) { from = (await Web3Provider.getWeb3().eth.getAccounts())[0] } return this.send(name, from, args) } - protected async send(name: string, from: string, args: any[]): Promise { + protected async send(name: string, from: string, args: any[]): Promise { if (!this.contract.methods[name]) { throw new Error(`Method "${name}" is not part of contract "${this.contractName}"`) } @@ -95,12 +94,10 @@ export default abstract class ContractBase { } } - private searchMethod(methodName): any { - const foundMethod = this.contract.options.jsonInterface.find((method) => { - if (method.name === methodName) { - return method - } - }) + private searchMethod(methodName: string) { + const foundMethod = this.contract.options.jsonInterface + .map(method => ({...method, signature: (method as any).signature})) + .find((method: any) => method.name === methodName) if (!foundMethod) { throw new Error(`Method "${methodName}" is not part of contract "${this.contractName}"`) } diff --git a/src/keeper/contracts/DIDRegistry.ts b/src/keeper/contracts/DIDRegistry.ts index a4acd90..143459e 100644 --- a/src/keeper/contracts/DIDRegistry.ts +++ b/src/keeper/contracts/DIDRegistry.ts @@ -1,4 +1,3 @@ -import {Receipt} from "web3-utils" import Web3Provider from "../Web3Provider" import ContractBase from "./ContractBase" @@ -10,7 +9,7 @@ export default class DIDRegistry extends ContractBase { return didRegistry } - public async registerAttribute(did: string, checksum: string, value: string, ownerAddress: string): Promise { + public async registerAttribute(did: string, checksum: string, value: string, ownerAddress: string) { return this.send("registerAttribute", ownerAddress, ["0x" + did, Web3Provider.getWeb3().utils.fromAscii(checksum), value]) } diff --git a/src/keeper/contracts/Dispenser.ts b/src/keeper/contracts/Dispenser.ts index 74c91e2..e440f1a 100644 --- a/src/keeper/contracts/Dispenser.ts +++ b/src/keeper/contracts/Dispenser.ts @@ -1,4 +1,3 @@ -import {Receipt} from "web3-utils" import ContractBase from "./ContractBase" export default class Dispenser extends ContractBase { @@ -9,7 +8,7 @@ export default class Dispenser extends ContractBase { return market } - public async requestTokens(amount: number, receiverAddress: string): Promise { + public async requestTokens(amount: number, receiverAddress: string) { return this.send("requestTokens", receiverAddress, [amount]) } } diff --git a/src/keeper/contracts/Token.ts b/src/keeper/contracts/Token.ts index f746c74..6f5d8fb 100644 --- a/src/keeper/contracts/Token.ts +++ b/src/keeper/contracts/Token.ts @@ -1,5 +1,4 @@ import BigNumber from "bignumber.js" -import {Receipt} from "web3-utils" import ContractBase from "./ContractBase" export default class OceanToken extends ContractBase { @@ -10,8 +9,8 @@ export default class OceanToken extends ContractBase { return token } - public async approve(marketAddress: string, price: number, buyerAddress: string): Promise { - return this.send("approve", buyerAddress, [marketAddress, price]) + public async approve(to: string, price: number, from?: string) { + return this.sendFrom("approve", [to, price], from) } public async balanceOf(address: string): Promise { @@ -19,7 +18,7 @@ export default class OceanToken extends ContractBase { .then((balance: string) => new BigNumber(balance).toNumber()) } - public async transfer(to: string, amount: number, from: string): Promise { + public async transfer(to: string, amount: number, from: string) { return this.send("transfer", from, [to, amount]) } } diff --git a/src/keeper/contracts/conditions/Condition.abstract.ts b/src/keeper/contracts/conditions/Condition.abstract.ts index f0351a3..266e3fe 100644 --- a/src/keeper/contracts/conditions/Condition.abstract.ts +++ b/src/keeper/contracts/conditions/Condition.abstract.ts @@ -24,20 +24,20 @@ export abstract class Condition extends ContractBase { return this.call("hashValues", args) } - fulfill(agreementId: string, ...args: any[]): Promise - fulfill(agreementId: string, args: any[], from?: string): Promise { - return this.sendFrom("fulfill", args, from) + fulfill(agreementId: string, ...args: any[]) + fulfill(agreementId: string, args: any[], from?: string) { + return this.sendFrom("fulfill", [agreementId, ...args], from) } - async generateIdHash(agreementId: string, ...values: any[]): Promise { + async generateIdHash(agreementId: string, ...values: any[]) { return this.generateId(agreementId, await this.hashValues(...values)) } - generateId(agreementId: string, valueHash: string): Promise { - return this.call("generateId", [agreementId, valueHash]) + generateId(agreementId: string, valueHash: string) { + return this.call("generateId", [agreementId, valueHash]) } - abortByTimeOut(agreementId: string, from?: string): Promise { + abortByTimeOut(agreementId: string, from?: string) { return this.sendFrom("requestTokens", [agreementId], from) } } diff --git a/src/ocean/OceanTokens.ts b/src/ocean/OceanTokens.ts index 049b978..ffa7cbf 100644 --- a/src/ocean/OceanTokens.ts +++ b/src/ocean/OceanTokens.ts @@ -32,9 +32,10 @@ export default class OceanTokens { * @return {Promise} Success, */ public async transfer(to: string, amount: number, from: Account): Promise { - return (await Keeper.getInstance()) + (await Keeper.getInstance()) .token .transfer(to, amount, from.getId()) + return true } /** diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index e32f031..356e8b6 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -1,4 +1,3 @@ -import ConfigProvider from "../../ConfigProvider" import { Condition } from "../../ddo/Condition" import { DDO } from "../../ddo/DDO" import { ServiceAccess } from "../../ddo/Service" @@ -93,7 +92,7 @@ export default class ServiceAgreement extends OceanBase { let serviceAgreementHashSignature: string const web3 = Web3Provider.getWeb3() - if (web3.currentProvider.isMetaMask) { + if ((web3 as any).currentProvider.isMetaMask) { // password is injected by metamask, dont try to set it! serviceAgreementHashSignature = await web3.eth.personal.sign(serviceAgreementHash, consumer.getId(), null) } else { @@ -163,7 +162,7 @@ export default class ServiceAgreement extends OceanBase { private static hashValuePairArray(valuePairs: ValuePair[]): string { let hash: string try { - hash = Web3Provider.getWeb3().utils.soliditySha3(...valuePairs).toString("hex") + hash = (Web3Provider as any).getWeb3().utils.soliditySha3(...valuePairs).toString("hex") } catch (err) { Logger.error(`Hashing of ${JSON.stringify(valuePairs, null, 2)} failed.`) throw err @@ -192,7 +191,7 @@ export default class ServiceAgreement extends OceanBase { {type: "bytes32", value: "0x" + serviceAgreementId} as ValuePair, ] - return Web3Provider.getWeb3().utils.soliditySha3(...args).toString("hex") + return (Web3Provider as any).getWeb3().utils.soliditySha3(...args).toString("hex") } private static getTimeoutValuesFromService(service: ServiceAccess): number[] { diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index eced38e..fdc04b6 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -1,4 +1,3 @@ -import ConfigProvider from "../../ConfigProvider" import { Condition as DDOCondition, Dependency, Parameter } from "../../ddo/Condition" import { MetaData } from "../../ddo/MetaData" import ContractReflector from "../../keeper/ContractReflector" @@ -21,7 +20,7 @@ export default class ServiceAgreementTemplate extends OceanBase { {type: "address", value: methodReflection.address} as ValuePair, {type: "bytes4", value: methodReflection.signature} as ValuePair, ] - return Web3Provider.getWeb3().utils.soliditySha3(...values).toString("hex") + return (Web3Provider as any).getWeb3().utils.soliditySha3(...values).toString("hex") } public constructor(private template: TemplateBase) { diff --git a/tsconfig.json b/tsconfig.json index d2bc6f3..959c147 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "resolveJsonModule": true, "moduleResolution": "node", "lib": [ + "es2017", "es6", "es7" ],