mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
fixed some typing issues
This commit is contained in:
parent
5ec624b2a5
commit
c9b383223b
@ -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
|
||||
|
@ -7,5 +7,5 @@
|
||||
"threshold": 0,
|
||||
"password": "secret",
|
||||
"address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb",
|
||||
"verbose": false
|
||||
"verbose": "error"
|
||||
}
|
||||
|
@ -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": {
|
||||
|
@ -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<Contract> {
|
||||
const where = (await (await Keeper.getInstance()).getNetworkName()).toLowerCase()
|
||||
try {
|
||||
return ContractHandler.contracts.get(what) || await ContractHandler.load(what, where)
|
||||
|
@ -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<Event[]> {
|
||||
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<Receipt> {
|
||||
protected async sendFrom(name: string, args: any[], from?: string): Promise<TransactionReceipt> {
|
||||
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<Receipt> {
|
||||
protected async send(name: string, from: string, args: any[]): Promise<TransactionReceipt> {
|
||||
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}"`)
|
||||
}
|
||||
|
@ -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<Receipt> {
|
||||
public async registerAttribute(did: string, checksum: string, value: string, ownerAddress: string) {
|
||||
return this.send("registerAttribute", ownerAddress, ["0x" + did, Web3Provider.getWeb3().utils.fromAscii(checksum), value])
|
||||
}
|
||||
|
||||
|
@ -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<Receipt> {
|
||||
public async requestTokens(amount: number, receiverAddress: string) {
|
||||
return this.send("requestTokens", receiverAddress, [amount])
|
||||
}
|
||||
}
|
||||
|
@ -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<Receipt> {
|
||||
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<number> {
|
||||
@ -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<boolean> {
|
||||
public async transfer(to: string, amount: number, from: string) {
|
||||
return this.send("transfer", from, [to, amount])
|
||||
}
|
||||
}
|
||||
|
@ -24,20 +24,20 @@ export abstract class Condition extends ContractBase {
|
||||
return this.call("hashValues", args)
|
||||
}
|
||||
|
||||
fulfill(agreementId: string, ...args: any[]): Promise<ConditionState>
|
||||
fulfill(agreementId: string, args: any[], from?: string): Promise<ConditionState> {
|
||||
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<string> {
|
||||
async generateIdHash(agreementId: string, ...values: any[]) {
|
||||
return this.generateId(agreementId, await this.hashValues(...values))
|
||||
}
|
||||
|
||||
generateId(agreementId: string, valueHash: string): Promise<string> {
|
||||
return this.call("generateId", [agreementId, valueHash])
|
||||
generateId(agreementId: string, valueHash: string) {
|
||||
return this.call<string>("generateId", [agreementId, valueHash])
|
||||
}
|
||||
|
||||
abortByTimeOut(agreementId: string, from?: string): Promise<ConditionState> {
|
||||
abortByTimeOut(agreementId: string, from?: string) {
|
||||
return this.sendFrom("requestTokens", [agreementId], from)
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,10 @@ export default class OceanTokens {
|
||||
* @return {Promise<boolean>} Success,
|
||||
*/
|
||||
public async transfer(to: string, amount: number, from: Account): Promise<boolean> {
|
||||
return (await Keeper.getInstance())
|
||||
(await Keeper.getInstance())
|
||||
.token
|
||||
.transfer(to, amount, from.getId())
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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[] {
|
||||
|
@ -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) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"lib": [
|
||||
"es2017",
|
||||
"es6",
|
||||
"es7"
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user