2018-10-05 12:34:31 +02:00
|
|
|
import {Receipt} from "web3-utils"
|
2018-10-02 10:06:26 +02:00
|
|
|
import Asset from "../models/Asset"
|
|
|
|
import Config from "../models/Config"
|
|
|
|
import ContractBaseWrapper from "./ContractWrapperBase"
|
|
|
|
import Web3Helper from "./Web3Helper"
|
2018-10-01 18:10:26 +02:00
|
|
|
|
|
|
|
export default class OceanAuth extends ContractBaseWrapper {
|
|
|
|
|
2018-10-09 10:55:53 +02:00
|
|
|
public static async getInstance(config: Config, web3Helper: Web3Helper): Promise<OceanAuth> {
|
|
|
|
const auth: OceanAuth = new OceanAuth(config, "OceanAuth", web3Helper)
|
2018-10-02 10:06:26 +02:00
|
|
|
await auth.init()
|
|
|
|
return auth
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async getOrderStatus(orderId: string): Promise<number> {
|
2018-10-05 16:16:48 +02:00
|
|
|
return this.contract.methods.statusOfAccessRequest(orderId)
|
2018-10-05 12:34:31 +02:00
|
|
|
.call()
|
2018-10-09 10:55:53 +02:00
|
|
|
.then((status: string) => parseInt(status, 10))
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async cancelAccessRequest(orderId: string, senderAddress: string): Promise<Receipt> {
|
2018-10-05 16:16:48 +02:00
|
|
|
return this.contract.methods.cancelAccessRequest(orderId)
|
2018-10-05 12:34:31 +02:00
|
|
|
.send({
|
|
|
|
from: senderAddress,
|
|
|
|
})
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async getEncryptedAccessToken(orderId: string, senderAddress: string): Promise<Receipt> {
|
2018-10-05 16:16:48 +02:00
|
|
|
return this.contract.methods.getEncryptedAccessToken(orderId)
|
2018-10-05 12:34:31 +02:00
|
|
|
.send({
|
|
|
|
from: senderAddress,
|
|
|
|
})
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async initiateAccessRequest(asset: Asset, publicKey: string,
|
2018-10-10 11:02:00 +02:00
|
|
|
timeout: number, buyerAddress: string): Promise<Receipt> {
|
|
|
|
|
|
|
|
const args = [asset.assetId, asset.publisherId, publicKey, timeout]
|
|
|
|
const tx = this.contract.methods.initiateAccessRequest(...args)
|
|
|
|
const gas = await tx.estimateGas(args, {
|
|
|
|
from: buyerAddress,
|
|
|
|
})
|
|
|
|
return tx.send({
|
|
|
|
from: buyerAddress,
|
|
|
|
gas,
|
|
|
|
})
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
}
|