1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

fix brizo connection

This commit is contained in:
Sebastian Gerske 2018-11-26 15:24:59 +01:00
parent ccf6bb4227
commit 43a5e53d57
4 changed files with 50 additions and 14 deletions

View File

@ -1,6 +1,8 @@
import Config from "../models/Config" import Config from "../models/Config"
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
const apiPath = "/api/v1/brizo/services"
export default class Brizo { export default class Brizo {
private url: string private url: string
@ -10,16 +12,16 @@ export default class Brizo {
} }
public getPurchaseEndpoint() { public getPurchaseEndpoint() {
return `${this.url}/api/v1/brizo/services/access/purchase?` return `${this.url}${apiPath}/access/purchase?`
} }
public getConsumeEndpoint(pubKey: string, serviceId: string, url: string) { public getConsumeEndpoint(pubKey: string, serviceId: string, url: string) {
return `${this.url}/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}` return `${this.url}${apiPath}/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}`
} }
public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) { public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) {
// tslint:disable-next-line // tslint:disable-next-line
return `${this.url}/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId=${serviceId}&algo=${algo}&container=${container}"` return `${this.url}${apiPath}/compute?pubKey=${pubKey}&serviceId=${serviceId}&algo=${algo}&container=${container}"`
} }
public async initializeServiceAgreement( public async initializeServiceAgreement(
@ -27,17 +29,20 @@ export default class Brizo {
serviceAgreementId: string, serviceAgreementId: string,
serviceDefinitionId: string, serviceDefinitionId: string,
signature: string, signature: string,
consumerPublicKey: string): Promise<any> { consumerAddress: string): Promise<any> {
return WebServiceConnectorProvider.getConnector().post( return WebServiceConnectorProvider
`${this.url}/api/v1/brizo/services/access/initialize`, .getConnector()
{ .post(
did, `${this.url}${apiPath}/access/initialize`,
serviceAgreementId, JSON.stringify({
serviceDefinitionId, did,
signature, serviceAgreementId,
consumerPublicKey, serviceDefinitionId,
}) signature,
consumerAddress,
}),
)
} }
} }

View File

@ -74,6 +74,9 @@ import {Account, Logger, Ocean} from "../squid"
Logger.log("did", ddo.id) Logger.log("did", ddo.id)
const accessService: Service = ddo.findServiceByType("Access") const accessService: Service = ddo.findServiceByType("Access")
await consumer.requestTokens(metaData.base.price)
const serviceAgreementResult: any = await ocean const serviceAgreementResult: any = await ocean
.signServiceAgreement( .signServiceAgreement(
ddo.id, ddo.id,

View File

@ -216,7 +216,7 @@ export default class Ocean {
serviceAgreementId, serviceAgreementId,
serviceDefinitionId, serviceDefinitionId,
serviceAgreementSignature, serviceAgreementSignature,
await consumer.getPublicKey()) consumer.getId())
Logger.log(result) Logger.log(result)
} }

28
test.html Normal file
View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="dist/umd/squid.js"></script>
<script>
const config = {
// web3Provider: web3 ? web3.currentProvider : null,
aquariusUri: "http://localhost:5000",
brizoUri: "http://localhost:8030",
parityUri: "http://localhost:9545",
secretStoreUri: "http://localhost:12001",
threshold: 0,
password: "unittest",
address: "0xed243adfb84a6626eba46178ccb567481c6e655d",
}
squid.Ocean
.getInstance(config)
.then(ocn => {
console.log(ocn)
})
</script>
</head>
<body>
</body>
</html>