Skip to content

Commit

Permalink
Merge pull request #740 from nevermined-io/feat/return-tx-hash
Browse files Browse the repository at this point in the history
Feat/return tx hash
  • Loading branch information
eruizgar91 authored Jan 8, 2025
2 parents 7e290fc + 22cb335 commit 6d19581
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v3.4.5](https://github.com/nevermined-io/sdk-js/compare/v3.0.46-rc0...v3.4.5)

> 13 December 2024
#### [v3.0.46-rc0](https://github.com/nevermined-io/sdk-js/compare/v3.0.44...v3.0.46-rc0)

> 7 January 2025
- feat: add search endpoint [`#735`](https://github.com/nevermined-io/sdk-js/pull/735)
- docs: updating documentation [skip actions] [`dd39011`](https://github.com/nevermined-io/sdk-js/commit/dd39011cca2077c7bd523ee0d1875e4981658fff)
- docs: updating documentation [skip actions] [`214a92d`](https://github.com/nevermined-io/sdk-js/commit/214a92dcb9714f95b6d0153a00b32db4a8a4856a)
- feat: return tx hash [`5fd7d6f`](https://github.com/nevermined-io/sdk-js/commit/5fd7d6ffa1293f33ec9d82711333bf2ab6957c70)

#### [v3.0.44](https://github.com/nevermined-io/sdk-js/compare/v3.0.43...v3.0.44)

> 22 November 2024
Expand Down
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",
"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 6d19581

Please sign in to comment.