-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototyping: Unlocking Data NFT Delegations (#2)
* add admin native auth token generation * add data unlocking to collections endpoint
- Loading branch information
Showing
10 changed files
with
735 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
import { AdminService } from '../admin' | ||
import { config } from 'apps/api/config' | ||
import { Delegation } from '../delegation' | ||
import { Injectable } from '@nestjs/common' | ||
import { DataNft } from '@itheum/sdk-mx-data-nft/out' | ||
import { CacheService } from '@multiversx/sdk-nestjs-cache' | ||
|
||
@Injectable() | ||
export class DataService { | ||
constructor(protected readonly cachingService: CacheService) {} | ||
|
||
async mintStreamNft() { | ||
// const dataNfts = DataNft.createManyFromApi() | ||
// const tx = await dataNftMinter.mint( | ||
// this.adminService.getAccount(network).address, | ||
// 'Portable Data #1', | ||
// 'https://api.itheumcloud-stg.com/datamarshalapi/achilles/v1', | ||
// 'https://peerme.io/explore', | ||
// 'https://peerme.io/', | ||
// 5, | ||
// 1, | ||
// 'Valuable Data', | ||
// 'This is some valuable stuff here', | ||
// 500 * 10 ** 18 | ||
// ) | ||
// await this.adminService.signAndSend(tx as any, network) | ||
// console.log(`Minted DataNFT on ${network} with tx: ${tx.getHash().toString()}`) | ||
constructor( | ||
protected readonly cachingService: CacheService, | ||
protected readonly adminServie: AdminService | ||
) { | ||
DataNft.setNetworkConfig(config().app.env) | ||
} | ||
|
||
async unlockDelegationData(delegations: Delegation[]): Promise<Delegation[]> { | ||
const nativeAuthToken = await this.adminServie.generateNativeAuthToken() | ||
const unlockables = await DataNft.createManyFromApi(delegations.map((d) => ({ tokenIdentifier: d.collection, nonce: d.nonce }))) | ||
|
||
const viewDataRequestOptions = this.getDataViewRequestOptions(nativeAuthToken) | ||
const unlocks = unlockables.map((u) => u.viewDataViaMVXNativeAuth(viewDataRequestOptions)) | ||
const unlockResults = await Promise.all(unlocks) | ||
|
||
// TODO: add filtering based on status checks, and potentially trigger automatic undelegations | ||
|
||
const contentResults = await Promise.all(unlockResults.map((x) => x.data.text())) | ||
|
||
const unlockedDelegations = delegations.map((del, i) => { | ||
del.content = contentResults[i] | ||
return del | ||
}) | ||
|
||
return unlockedDelegations | ||
} | ||
|
||
private getDataViewRequestOptions(nativeAuthToken: string) { | ||
return { | ||
mvxNativeAuthOrigins: config().services.chain.nativeAuth.acceptedOrigins, | ||
mvxNativeAuthMaxExpirySeconds: config().services.chain.nativeAuth.maxExpirySeconds, | ||
fwdHeaderMapLookup: { | ||
authorization: `Bearer ${nativeAuthToken}`, | ||
}, | ||
asDeputyOnAppointerAddr: config().contracts.aggregator, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ export type Delegation = { | |
collection: string | ||
nonce: number | ||
segment: string | ||
content?: any | ||
} |
Oops, something went wrong.