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

added logging, reworked consumer account on execute agreement

This commit is contained in:
Sebastian Gerske 2018-11-20 11:25:10 +01:00
parent baeddd98a7
commit 2cfb32199a

View File

@ -14,6 +14,8 @@ export default class ServiceAgreement extends OceanBase {
serviceAgreementId: string, consumer: Account): serviceAgreementId: string, consumer: Account):
Promise<string> { Promise<string> {
// Logger.log("signing SA", serviceAgreementId)
const service: Service = ddo.findServiceById(serviceDefinitionId) const service: Service = ddo.findServiceById(serviceDefinitionId)
const values: ValuePair[] = ServiceAgreement.getValuesFromService(service, serviceAgreementId) const values: ValuePair[] = ServiceAgreement.getValuesFromService(service, serviceAgreementId)
const valueHashes = ServiceAgreement.createValueHashes(values) const valueHashes = ServiceAgreement.createValueHashes(values)
@ -29,14 +31,17 @@ export default class ServiceAgreement extends OceanBase {
serviceAgreementId: string, serviceAgreementHashSignature: string, serviceAgreementId: string, serviceAgreementHashSignature: string,
consumer: Account, publisher: Account): Promise<ServiceAgreement> { consumer: Account, publisher: Account): Promise<ServiceAgreement> {
// Logger.log("executing SA", serviceAgreementId)
const service: Service = ddo.findServiceById(serviceDefinitionId) const service: Service = ddo.findServiceById(serviceDefinitionId)
const values: ValuePair[] = ServiceAgreement.getValuesFromService(service, serviceAgreementId) const values: ValuePair[] = ServiceAgreement.getValuesFromService(service, serviceAgreementId)
const valueHashes = ServiceAgreement.createValueHashes(values) const valueHashes = ServiceAgreement.createValueHashes(values)
const timeoutValues: number[] = ServiceAgreement.getTimeoutValuesFromService(service) const timeoutValues: number[] = ServiceAgreement.getTimeoutValuesFromService(service)
// todo get consumer from ddo
const serviceAgreement: ServiceAgreement = await ServiceAgreement.executeAgreement(ddo, const serviceAgreement: ServiceAgreement = await ServiceAgreement.executeAgreement(ddo,
serviceDefinitionId, serviceAgreementId, valueHashes, timeoutValues, serviceAgreementHashSignature, serviceDefinitionId, serviceAgreementId, valueHashes, timeoutValues, serviceAgreementHashSignature,
consumer, publisher) consumer.getId(), publisher)
return serviceAgreement return serviceAgreement
} }
@ -64,7 +69,8 @@ export default class ServiceAgreement extends OceanBase {
private static async executeAgreement(ddo: DDO, serviceDefinitionId: string, serviceAgreementId: string, private static async executeAgreement(ddo: DDO, serviceDefinitionId: string, serviceAgreementId: string,
valueHashes: string[], timeoutValues: number[], valueHashes: string[], timeoutValues: number[],
serviceAgreementHashSignature: string, consumer: Account, publisher: Account) serviceAgreementHashSignature: string, consumerAddress: string,
publisher: Account)
: Promise<ServiceAgreement> { : Promise<ServiceAgreement> {
const {serviceAgreement} = await Keeper.getInstance() const {serviceAgreement} = await Keeper.getInstance()
@ -76,7 +82,7 @@ export default class ServiceAgreement extends OceanBase {
} }
const executeAgreementReceipt = await serviceAgreement.executeAgreement( const executeAgreementReceipt = await serviceAgreement.executeAgreement(
service.templateId, serviceAgreementHashSignature, consumer.getId(), valueHashes, service.templateId, serviceAgreementHashSignature, consumerAddress, valueHashes,
timeoutValues, serviceAgreementId, ddo.id, publisher.getId()) timeoutValues, serviceAgreementId, ddo.id, publisher.getId())
if (executeAgreementReceipt.events.ExecuteAgreement.returnValues.state === false) { if (executeAgreementReceipt.events.ExecuteAgreement.returnValues.state === false) {
@ -87,7 +93,7 @@ export default class ServiceAgreement extends OceanBase {
executeAgreementReceipt.events.ExecuteAgreement.returnValues.serviceAgreementId, executeAgreementReceipt.events.ExecuteAgreement.returnValues.serviceAgreementId,
ddo, ddo,
publisher, publisher,
consumer, new Account(consumerAddress),
executeAgreementReceipt.events.ExecuteAgreement.returnValues.state, executeAgreementReceipt.events.ExecuteAgreement.returnValues.state,
executeAgreementReceipt.events.ExecuteAgreement.returnValues.status, executeAgreementReceipt.events.ExecuteAgreement.returnValues.status,
) )