Skip to content

Commit

Permalink
feat: return tx hash
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Jan 7, 2025
1 parent 7e290fc commit 5fd7d6f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "3.0.45",
"version": "3.0.46-rc0",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
22 changes: 14 additions & 8 deletions src/keeper/contracts/templates/BaseTemplate.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { TxParameters } from '../../../models/Transactions'
import { isValidAddress } from '../../../nevermined/utils/BlockchainViemUtils'
import { ConditionState } from '../../../types/ContractTypes'
import {
Service,
ServicePlugin,
ServiceType,
MetaData,
ServiceAttributes,
PricedMetadataInformation,
Service,
ServiceAttributes,
serviceIndex,
ServicePlugin,
ServiceType,
ValidationParams,
} from '../../../types/DDOTypes'
import { zeroX } from '../../../utils/ConversionTypeHelpers'
Expand Down Expand Up @@ -127,8 +127,8 @@ export abstract class BaseTemplate<Params, S extends Service>
params: ValidationParams,
from: NvmAccount,
txparams?: TxParameters,
): Promise<void> {
await this.validateAgreement(
): Promise<void | { [key: string]: any }> {
return await this.validateAgreement(
params.agreement_id,
params.did,
await this.paramsGen(params),
Expand All @@ -145,7 +145,7 @@ export abstract class BaseTemplate<Params, S extends Service>
from: NvmAccount,
extra: any = {},
txparams?: TxParameters,
): Promise<void> {
): Promise<void | { [key: string]: any }> {
const ddo = await this.nevermined.assets.resolve(did)
if (!ddo) {
throw new Error(`Asset ${did} not found`)
Expand All @@ -166,12 +166,16 @@ export abstract class BaseTemplate<Params, S extends Service>
)
}

const results: { [key: string]: any } = {}

for (const a of this.conditions()) {
const condInstance = agreementData.instances.find(
(c) => c.condition === a.contractName,
) as ConditionInstance<any>

await a.fulfillWithNode(condInstance, extra, from, txparams)
const result = await a.fulfillWithNode(condInstance, extra, from, txparams)
results[a.contractName] = result

const lock_state = await this.nevermined.keeper.conditionStoreManager.getCondition(
condInstance.id,
)
Expand All @@ -182,5 +186,7 @@ export abstract class BaseTemplate<Params, S extends Service>
)
}
}

return results
}
}
7 changes: 4 additions & 3 deletions src/keeper/contracts/templates/NFTAccessTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class NFTAccessTemplate extends BaseTemplate<NFTAccessTemplateParams, Ser
params: ValidationParams,
from: NvmAccount,
txparams?: TxParameters,
): Promise<void> {
await this.validateAgreement(
): Promise<void | { [key: string]: any }> {
return await this.validateAgreement(
params.agreement_id,
params.did,
await this.paramsGen(params),
Expand All @@ -120,13 +120,14 @@ export class NFTAccessTemplate extends BaseTemplate<NFTAccessTemplateParams, Ser
from: NvmAccount,
extra: any = {},
txparams?: TxParameters,
): Promise<void> {
): Promise<void | { [key: string]: any }> {
const ddo = await this.nevermined.assets.resolve(did)
const metadataService = ddo.findServiceByType('metadata')
const isNft1155Credit =
(metadataService.attributes.main.nftType as string) ===
NeverminedNFT1155Type.nft1155Credit.toString()
if (isNft1155Credit) return

return this.validateAgreement(agreement_id, did, params, from, extra, txparams)
}

Expand Down
6 changes: 3 additions & 3 deletions src/nevermined/AccessService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class AccessService extends Instantiable implements ServicePlugin<Service
params: ValidationParams,
from: NvmAccount,
txparams?: TxParameters,
): Promise<void> {
): Promise<void | { [key: string]: any }> {
return this.normal.process(params, from, txparams)
}
public async accept(params: ValidationParams): Promise<boolean> {
Expand Down Expand Up @@ -105,7 +105,7 @@ export class NFTAccessService extends Instantiable implements ServicePlugin<Serv
params: ValidationParams,
from: NvmAccount,
txparams?: TxParameters,
): Promise<void> {
): Promise<void | { [key: string]: any }> {
const ddo = await this.nevermined.assets.resolve(params.did)
const metadata = ddo.findServiceByType('metadata').attributes.main
return this.select(metadata).process(params, from, txparams)
Expand Down Expand Up @@ -162,7 +162,7 @@ export class NFTSalesService extends Instantiable implements ServicePlugin<Servi
params: ValidationParams,
from: NvmAccount,
txparams?: TxParameters,
): Promise<void> {
): Promise<void | { [key: string]: any }> {
const ddo = await this.nevermined.assets.resolve(params.did)
const metadata = ddo.findServiceByType('metadata').attributes.main
return this.select(metadata).process(params, from, txparams)
Expand Down
6 changes: 5 additions & 1 deletion src/types/DDOTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,11 @@ export interface ServicePlugin<T extends Service> {
pricedData?: PricedMetadataInformation,
): T
// Process agreement for provider
process(params: ValidationParams, from: NvmAccount, txparams?: TxParameters): Promise<void>
process(
params: ValidationParams,
from: NvmAccount,
txparams?: TxParameters,
): Promise<void | { [key: string]: any }>
// Check if service can be granted without agreement
accept(params: ValidationParams): Promise<boolean>
// It registers the usage of a service
Expand Down

0 comments on commit 5fd7d6f

Please sign in to comment.