Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marketplace: load manifest on demand #896

Merged
merged 6 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 144 additions & 133 deletions systemservices/marketplace/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,110 @@ tasks:
type: String
manifestProtocol: &manifestProtocol
type: String
manifestData: &manifestData
createTime: *createTime
offers: &offers
type: Object
repeated: true
optional: true
object: &offer
offerIndex: &offerIndex
type: String
price: &price
type: String
duration: &duration
type: String
active:
type: Boolean
createTime: *createTime
purchases: &purchases
type: Object
repeated: true
optional: true
object: &purchase
purchaser: &purchaser
type: String
expire: &expire
type: String
createTime: *createTime
error: &outputError
name: "Error"
description: "Output when an error occurs"
data:
message:
name: "Message"
description: "The error message"
type: String
code:
name: "Error code"
description: "The error code"
type: String
optional: true
getService:
inputs:
sid: *sid
outputs:
error: *outputError
success:
data:
sid: *sid
createTime: *createTime
owner: *owner
offers: *offers
purchases: *purchases
versions:
type: Object
repeated: true
optional: true
object:
<<: *version
manifestData: &manifestData
type: Object
optional: true
object:
version:
type: String
service: &manifestServiceData
type: Object
optional: true
object:
version:
hashVersion:
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
type: String
service: &manifestServiceData
deployment:
type: Object
object:
hashVersion:
type:
type: String
deployment:
type: Object
object:
type:
type: String
source:
type: String
definition:
source:
type: String
definition:
type: Object
object:
hash:
type: String
sid:
type: String
name:
type: String
description:
type: String
optional: true
tasks:
type: Object
repeated: true
optional: true
object:
hash:
type: String
sid:
key:
type: String
name:
type: String
optional: true
description:
type: String
optional: true
tasks:
inputs: &manifestServiceDataParameters
type: Object
repeated: true
optional: true
object:
repeated: true
object:
key:
type: String
name:
Expand All @@ -79,47 +148,20 @@ tasks:
description:
type: String
optional: true
inputs: &manifestServiceDataParameters
type: Object
type:
type: String
optional:
type: Boolean
optional: true
repeated:
type: Boolean
optional: true
repeated: true
object:
key:
type: String
name:
type: String
optional: true
description:
type: String
optional: true
type:
type: String
optional:
type: Boolean
optional: true
repeated:
type: Boolean
optional: true
object:
type: Object
optional: true
outputs:
object:
type: Object
repeated: true
object:
key:
type: String
name:
type: String
optional: true
description:
type: String
optional: true
data: *manifestServiceDataParameters
events:
optional: true
outputs:
type: Object
repeated: true
optional: true
object:
key:
type: String
Expand All @@ -130,90 +172,59 @@ tasks:
type: String
optional: true
data: *manifestServiceDataParameters
configuration:
type: Object
events:
type: Object
repeated: true
optional: true
object:
key:
type: String
name:
type: String
optional: true
object: &manifestServiceDataConfiguration
volumes:
type: String
repeated: true
optional: true
volumesFrom:
type: String
repeated: true
optional: true
ports:
type: String
repeated: true
optional: true
args:
type: String
repeated: true
optional: true
command:
type: String
optional: true
dependencies:
type: Object
description:
type: String
optional: true
data: *manifestServiceDataParameters
configuration:
type: Object
optional: true
object: &manifestServiceDataConfiguration
volumes:
type: String
repeated: true
optional: true
object:
<<: *manifestServiceDataConfiguration
key:
type: String
image:
type: String
repository:
volumesFrom:
type: String
repeated: true
optional: true
ports:
type: String
repeated: true
optional: true
args:
type: String
repeated: true
optional: true
command:
type: String
optional: true
readme:
dependencies:
type: Object
repeated: true
optional: true
object:
<<: *manifestServiceDataConfiguration
key:
type: String
image:
type: String
repository:
type: String
optional: true
createTime: *createTime
offers: &offers
type: Object
repeated: true
optional: true
object: &offer
offerIndex: &offerIndex
type: String
price: &price
type: String
duration: &duration
type: String
active:
type: Boolean
createTime: *createTime
purchases: &purchases
type: Object
repeated: true
optional: true
object: &purchase
purchaser: &purchaser
type: String
expire: &expire
type: String
createTime: *createTime
error: &outputError
name: "Error"
description: "Output when an error occurs"
data:
message:
name: "Message"
description: "The error message"
type: String
code:
name: "Error code"
description: "The error code"
type: String
optional: true
getService:
inputs:
sid: *sid
outputs:
success:
data: *service
error: *outputError
readme:
type: String
optional: true
preparePublishServiceVersion:
inputs:
service: *manifestServiceData
Expand Down
9 changes: 0 additions & 9 deletions systemservices/marketplace/src/contracts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import BigNumber from "bignumber.js"
import { Marketplace } from "./Marketplace"
import { Version } from "../types/version";
import { hexToString, parseTimestamp, stringToHex, hexToHash, hashToHex } from "./utils";
import { getManifest } from "./manifest";
import { requireServiceExist } from "./service";

const getServiceVersions = async (contract: Marketplace, sid: string): Promise<Version[]> => {
Expand All @@ -26,18 +25,10 @@ const getServiceVersion = async (contract: Marketplace, versionHash: string): Pr
throw new Error(`version ${versionHash} does not exist`)
}
const version = await contract.methods.serviceVersion(versionHashHex).call()
let manifestData = null
try {
manifestData = await getManifest(hexToString(version.manifestProtocol), hexToString(version.manifest))
}
catch (error) {
console.warn('error getManifest', error.toString())
}
return {
versionHash: versionHash,
manifest: hexToString(version.manifest),
manifestProtocol: hexToString(version.manifestProtocol),
manifestData: manifestData,
createTime: parseTimestamp(version.createTime),
}
}
Expand Down
19 changes: 18 additions & 1 deletion systemservices/marketplace/src/tasks/getService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import { TaskInputs, TaskOutputs } from "mesg-js/lib/service"
import { Marketplace } from "../contracts/Marketplace"
import { getService } from "../contracts/service";
import { getManifest } from "../contracts/manifest";

export default (contract: Marketplace) => async (inputs: TaskInputs, outputs: TaskOutputs): Promise<void> => {
try {
const service = await getService(contract, inputs.sid)
return outputs.success(service)
const versionsWithManifest = await Promise.all(service.versions.map(async (version) => {
let manifestData = null
try {
manifestData = await getManifest(version.manifestProtocol, version.manifest)
}
catch (error) {
console.warn('error getManifest', error.toString())
}
return {
...version,
manifestData
}
}))
return outputs.success({
...service,
versions: versionsWithManifest,
})
}
catch (error) {
console.error('error in getService', error)
Expand Down
Loading