mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
map parameter values
This commit is contained in:
parent
dfff8fc228
commit
cc91cdb054
4
src/models/InputType.ts
Normal file
4
src/models/InputType.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export default class InputType {
|
||||
public name: string
|
||||
public type: string
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
import InputType from "./InputType"
|
||||
|
||||
export default class MethodReflection {
|
||||
public contractName: string
|
||||
public methodName: string
|
||||
public address: string
|
||||
public signature: string
|
||||
public inputs: any[]
|
||||
public inputs: InputType[]
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import Service from "../ddo/Service"
|
||||
import Keeper from "../keeper/Keeper"
|
||||
import Web3Provider from "../keeper/Web3Provider"
|
||||
import Config from "../models/Config"
|
||||
import ValuePair from "../models/ValuePair"
|
||||
import InputType from "../models/InputType"
|
||||
import ValueType from "../models/ValueType"
|
||||
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
||||
import Logger from "../utils/Logger"
|
||||
@ -92,13 +92,31 @@ export default class Ocean {
|
||||
} as Event,
|
||||
]
|
||||
|
||||
const parameters: Parameter[] = condition.methodReflection.inputs.map((input: ValuePair) => {
|
||||
const mapParameterValueToName = (name) => {
|
||||
|
||||
switch (name) {
|
||||
case "price":
|
||||
return metadata.base.price
|
||||
case "assetId":
|
||||
return "0x" + id
|
||||
case "documentKeyId":
|
||||
return "0x1234"
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const parameters: Parameter[] = condition.methodReflection.inputs.map((input: InputType) => {
|
||||
return {
|
||||
...input,
|
||||
value: "xxx",
|
||||
name: input.name,
|
||||
type: input.type,
|
||||
value: mapParameterValueToName(input.name),
|
||||
} as Parameter
|
||||
})
|
||||
|
||||
// Logger.log(`${condition.methodReflection.contractName}.${condition.methodReflection.methodName}`,
|
||||
// JSON.stringify(parameters, null, 2))
|
||||
|
||||
return {
|
||||
contractName: condition.methodReflection.contractName,
|
||||
methodName: condition.methodReflection.methodName,
|
||||
|
@ -4,6 +4,7 @@ import Service from "../../ddo/Service"
|
||||
import Keeper from "../../keeper/Keeper"
|
||||
import Web3Provider from "../../keeper/Web3Provider"
|
||||
import ValuePair from "../../models/ValuePair"
|
||||
import Logger from "../../utils/Logger"
|
||||
import Account from "../Account"
|
||||
import OceanBase from "../OceanBase"
|
||||
|
||||
@ -99,7 +100,11 @@ export default class ServiceAgreement extends OceanBase {
|
||||
}
|
||||
|
||||
private static hashSingleValue(data: ValuePair): string {
|
||||
return Web3Provider.getWeb3().utils.soliditySha3(data).toString("hex")
|
||||
try {
|
||||
return Web3Provider.getWeb3().utils.soliditySha3(data).toString("hex")
|
||||
} catch (err) {
|
||||
Logger.error(`Hashing of ${JSON.stringify(data, null, 2)} failed.`)
|
||||
}
|
||||
}
|
||||
|
||||
private static hashServiceAgreement(serviceAgreementTemplateId: string, serviceAgreementId: string,
|
||||
@ -130,10 +135,15 @@ export default class ServiceAgreement extends OceanBase {
|
||||
|
||||
service.conditions.forEach((condition) => {
|
||||
condition.parameters.forEach((parameter) => {
|
||||
values.push({type: parameter.type, value: parameter.value} as ValuePair)
|
||||
values.push({
|
||||
type: parameter.type,
|
||||
value: parameter.name === "serviceId" ? "0x" + serviceAgreementId : parameter.value,
|
||||
} as ValuePair)
|
||||
})
|
||||
})
|
||||
|
||||
// Logger.log("Values", JSON.stringify(values, null, 2))
|
||||
|
||||
return values
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import EventHandlers from "../../src/ddo/EventHandlers"
|
||||
import MetaData from "../../src/ddo/MetaData"
|
||||
import Parameter from "../../src/ddo/Parameter"
|
||||
import Service from "../../src/ddo/Service"
|
||||
import ValuePair from "../../src/models/ValuePair"
|
||||
import InputType from "../../src/models/InputType"
|
||||
import Account from "../../src/ocean/Account"
|
||||
import IdGenerator from "../../src/ocean/IdGenerator"
|
||||
import Ocean from "../../src/ocean/Ocean"
|
||||
@ -28,6 +28,8 @@ let consumerAccount: Account
|
||||
let accessService: Service
|
||||
let metaDataService: Service
|
||||
|
||||
const assetId: string = IdGenerator.generateId()
|
||||
|
||||
describe("ServiceAgreement", () => {
|
||||
|
||||
before(async () => {
|
||||
@ -39,6 +41,7 @@ describe("ServiceAgreement", () => {
|
||||
publisherAccount = accounts[1]
|
||||
consumerAccount = accounts[2]
|
||||
|
||||
const metadata = new MetaData()
|
||||
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
||||
new ServiceAgreementTemplate(new Access())
|
||||
|
||||
@ -62,10 +65,25 @@ describe("ServiceAgreement", () => {
|
||||
} as Event,
|
||||
]
|
||||
|
||||
const parameters: Parameter[] = condition.methodReflection.inputs.map((input: ValuePair) => {
|
||||
const mapParameterValueToName = (name) => {
|
||||
|
||||
switch (name) {
|
||||
case "price":
|
||||
return metadata.base.price
|
||||
case "assetId":
|
||||
return "0x" + assetId
|
||||
case "documentKeyId":
|
||||
return "0x1234"
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const parameters: Parameter[] = condition.methodReflection.inputs.map((input: InputType) => {
|
||||
return {
|
||||
...input,
|
||||
value: "xxx",
|
||||
name: input.name,
|
||||
type: input.type,
|
||||
value: mapParameterValueToName(input.name),
|
||||
} as Parameter
|
||||
})
|
||||
|
||||
@ -92,7 +110,7 @@ describe("ServiceAgreement", () => {
|
||||
|
||||
metaDataService = {
|
||||
type: "MetaData",
|
||||
metadata: new MetaData(),
|
||||
metadata,
|
||||
} as Service
|
||||
})
|
||||
|
||||
@ -102,7 +120,6 @@ describe("ServiceAgreement", () => {
|
||||
const id: string = IdGenerator.generateId()
|
||||
const did: string = `did:op:${id}`
|
||||
const ddo = new DDO({id: did, service: [accessService]})
|
||||
const assetId: string = IdGenerator.generateId()
|
||||
const serviceAgreementId: string = IdGenerator.generateId()
|
||||
|
||||
// @ts-ignore
|
||||
@ -123,7 +140,6 @@ describe("ServiceAgreement", () => {
|
||||
const id: string = IdGenerator.generateId()
|
||||
const did: string = `did:op:${id}`
|
||||
const ddo = new DDO({id: did, service: [accessService]})
|
||||
const assetId: string = IdGenerator.generateId()
|
||||
const serviceAgreementId: string = IdGenerator.generateId()
|
||||
|
||||
// @ts-ignore
|
||||
@ -149,7 +165,6 @@ describe("ServiceAgreement", () => {
|
||||
const id: string = IdGenerator.generateId()
|
||||
const did: string = `did:op:${id}`
|
||||
const ddo = new DDO({id: did, service: [accessService]})
|
||||
const assetId: string = IdGenerator.generateId()
|
||||
const serviceAgreementId: string = IdGenerator.generateId()
|
||||
|
||||
// @ts-ignore
|
||||
@ -175,7 +190,6 @@ describe("ServiceAgreement", () => {
|
||||
const id: string = IdGenerator.generateId()
|
||||
const did: string = `did:op:${id}`
|
||||
const ddo = new DDO({id: did, service: [accessService, metaDataService]})
|
||||
const assetId: string = IdGenerator.generateId()
|
||||
const serviceAgreementId: string = IdGenerator.generateId()
|
||||
|
||||
// @ts-ignore
|
||||
@ -202,7 +216,6 @@ describe("ServiceAgreement", () => {
|
||||
const id: string = IdGenerator.generateId()
|
||||
const did: string = `did:op:${id}`
|
||||
const ddo = new DDO({id: did, service: [accessService]})
|
||||
const assetId: string = IdGenerator.generateId()
|
||||
const serviceAgreementId: string = IdGenerator.generateId()
|
||||
|
||||
// @ts-ignore
|
||||
|
Loading…
Reference in New Issue
Block a user