From cb5800c36d2936a8787b83de278a699f0a35c0b6 Mon Sep 17 00:00:00 2001 From: Bucur David Date: Tue, 6 Feb 2024 08:22:29 +0200 Subject: [PATCH 1/7] feat: update any attribute for Data Nft Refs: #95 --- src/datanft.ts | 7 +++++++ tests/datanft.test.ts | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/datanft.ts b/src/datanft.ts index 0840ac0..df84538 100644 --- a/src/datanft.ts +++ b/src/datanft.ts @@ -69,6 +69,13 @@ export class DataNft { this.overrideDataMarshalChainId = override.chainId; } + /** + * Update any attributes for DataNft + * + */ + updateDataNft(init: Partial) { + Object.assign(this, init); + } /** * Sets the network configuration for the DataNft class. * @param env 'devnet' | 'mainnet' | 'testnet' diff --git a/tests/datanft.test.ts b/tests/datanft.test.ts index 4c3fbd0..8872ada 100644 --- a/tests/datanft.test.ts +++ b/tests/datanft.test.ts @@ -133,5 +133,13 @@ describe('Data NFT test', () => { expect(dataNft.overrideDataMarshal).toBe(''); expect(dataNft.overrideDataMarshalChainId).toBe(''); + + dataNft.updateDataNft({ + overrideDataMarshal: 'overrideUrl', + overrideDataMarshalChainId: 'D' + }); + + expect(dataNft.overrideDataMarshal).toBe('overrideUrl'); + expect(dataNft.overrideDataMarshalChainId).toBe('D'); }); }); From 9b30bd612dde486e90b034d21a34ea07fdf8cdc9 Mon Sep 17 00:00:00 2001 From: Bucur David Date: Tue, 6 Feb 2024 08:43:25 +0200 Subject: [PATCH 2/7] refactor(docs): update readme with husky setup --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index d29ff14..1fd1865 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,23 @@ This SDK is currently focused on interacting with the Itheum's Data NFT technolo - work on typescript code in the `/src` folder - handy tip: when developing locally, you can do integration tests by running `npm run prepare` and the `npm install --save ../sdk-mx-data-nft` in the host project +### Dev Environment + +- create a '.husky' folder in the root of the project + Inside the folder: + - add a 'commit-msg' file with the following content: + ```bash + #!/usr/bin/env sh + . "$(dirname -- "$0")/_/husky.sh" + npx --no-install commitlint --edit $1 + ``` + - add a 'pre-commit' file with the following content: + ```bash + #!/usr/bin/env sh + . "$(dirname -- "$0")/_/husky.sh" + npm test + ``` + ### Dev Testing - Only simple dev testing added. First **Build** as below and then run `npm run test` and work on the test.mjs file for live reload From 33cf43e8f5eafd202c0bf55d7b1dfa109ceb1be4 Mon Sep 17 00:00:00 2001 From: Bucur David Date: Thu, 8 Feb 2024 09:42:07 +0200 Subject: [PATCH 3/7] chore: remove semantic releases --- .github/workflows/publish.yml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cfef5eb..8d8ed0c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,35 +1,36 @@ name: Publish on: + push: + branches: + - main workflow_dispatch: permissions: contents: write jobs: - release: - name: Release + publish-npm: runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Node.js - uses: actions/setup-node@v4 + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 with: node-version: lts/* + registry-url: https://registry.npmjs.org/ - name: Install dependencies run: npx ci - - name: Install semantic-release extra plugins - run: npm install --save-dev @semantic-release/changelog @semantic-release/git - name: Lint run: npm run lint:fix - name: Test run: npm run test --if-present - - name: Build - run: npm run build - - name: Release + - name: Create release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npm config set access public && npx semantic-release + run: | + RELEASE_TAG=v$(node -p "require('./package.json').version") + gh release create $RELEASE_TAG --target=$GITHUB_SHA --title="$RELEASE_TAG" --generate-notes + - name: Publish to npmjs + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + run: npm publish --access=public From fa558e4eb0369e673e436b770365c77d8574d1aa Mon Sep 17 00:00:00 2001 From: Bucur David Date: Thu, 8 Feb 2024 10:07:14 +0200 Subject: [PATCH 4/7] feat: implement DataNftType to abstract methods from the attributes --- src/datanft.ts | 4 ++-- src/interfaces.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/datanft.ts b/src/datanft.ts index df84538..3799187 100644 --- a/src/datanft.ts +++ b/src/datanft.ts @@ -27,10 +27,10 @@ import { ErrNetworkConfig, ErrTooManyItems } from './errors'; -import { NftType, ViewDataReturnType } from './interfaces'; +import { DataNftType, NftType, ViewDataReturnType } from './interfaces'; import BigNumber from 'bignumber.js'; -export class DataNft { +export class DataNft implements DataNftType { readonly tokenIdentifier: string = ''; readonly nftImgUrl: string = ''; readonly dataPreview: string = ''; diff --git a/src/interfaces.ts b/src/interfaces.ts index d62a520..e32571f 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,3 +1,5 @@ +import BigNumber from 'bignumber.js'; + export interface NftType { identifier: string; collection: string; @@ -44,6 +46,27 @@ export interface NftType { }[]; } +export interface DataNftType { + readonly tokenIdentifier: string; + readonly nftImgUrl: string; + readonly dataPreview: string; + readonly dataStream: string; + readonly dataMarshal: string; + readonly tokenName: string; + readonly creator: string; + readonly creationTime: Date; + readonly supply: number | BigNumber.Value; + readonly description: string; + readonly title: string; + readonly royalties: number; + readonly nonce: number; + readonly collection: string; + readonly balance: number | BigNumber.Value; + readonly owner: string; + readonly overrideDataMarshal: string; + readonly overrideDataMarshalChainId: string; +} + export enum NftEnumType { NonFungibleESDT = 'NonFungibleESDT', SemiFungibleESDT = 'SemiFungibleESDT', From e7e053ed39a61a54b850fe313d0be849afdf4dba Mon Sep 17 00:00:00 2001 From: Bucur David Date: Thu, 8 Feb 2024 11:32:23 +0200 Subject: [PATCH 5/7] refactor: update view methods && implement missing ones --- src/marketplace.ts | 88 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 6 deletions(-) diff --git a/src/marketplace.ts b/src/marketplace.ts index 2de0ebf..516047b 100644 --- a/src/marketplace.ts +++ b/src/marketplace.ts @@ -198,12 +198,24 @@ export class DataNftMarket { * Retrieves an array of `Offer` objects in an arbitrary order. * @param from first index * @param to last index + * @param senderAddress the address of the sender (optional) */ - async viewPagedOffers(from: number, to: number): Promise { - const interaction = this.contract.methodsExplicit.viewPagedOffers([ + async viewPagedOffers( + from: number, + to: number, + senderAddress?: string + ): Promise { + let interaction = this.contract.methodsExplicit.viewPagedOffers([ new U64Value(from), new U64Value(to) ]); + if (senderAddress) { + interaction = this.contract.methodsExplicit.viewPagedOffersByAddress([ + new U64Value(from), + new U64Value(to), + new AddressValue(new Address(senderAddress)) + ]); + } const query = interaction.buildQuery(); const queryResponse = await this.networkProvider.queryContract(query); const endpointDefinition = interaction.getEndpoint(); @@ -222,11 +234,37 @@ export class DataNftMarket { } } + /** + * Retrieves an `Offer` object based on the offer id + * @param offerId The id of the offer to be retrieved + */ + async viewOffer(offerId: number): Promise { + let interaction = this.contract.methodsExplicit.viewOffer([ + new U64Value(offerId) + ]); + + const query = interaction.buildQuery(); + const queryResponse = await this.networkProvider.queryContract(query); + const endpointDefinition = interaction.getEndpoint(); + const { firstValue, returnCode } = new ResultsParser().parseQueryResponse( + queryResponse, + endpointDefinition + ); + if (returnCode.isSuccess()) { + const returnValue = firstValue?.valueOf(); + const offer: Offer = parseOffer(returnValue); + return offer; + } else { + throw new ErrContractQuery('viewPagedOffers', returnCode.toString()); + } + } + /** * Retrieves an array of `Offer` objects. */ - async viewOffers(): Promise { - const interaction = this.contract.methodsExplicit.getOffers(); + async viewOffers(offerIds: number[]): Promise { + const input = offerIds.map((id) => new U64Value(id)); + const interaction = this.contract.methodsExplicit.viewOffers(input); const query = interaction.buildQuery(); const queryResponse = await this.networkProvider.queryContract(query); const endpointDefinition = interaction.getEndpoint(); @@ -416,7 +454,7 @@ export class DataNftMarket { * @param senderAddress the address of the sender * @param offerId the id of the offer to be accepted * @param amount the amount of tokens to be bought - * @param price the price of the offer (must include the buyer fee) + * @param price the price of the offer for the total amount to be bought (must include the buyer fee) * @param paymentTokenIdentifier the identifier of the payment token (default = `ITHEUM` token identifier based on the {@link EnvironmentsEnum})) */ acceptOfferWithESDT( @@ -447,11 +485,49 @@ export class DataNftMarket { return acceptTx; } + /** + * Creates a `acceptOffer` transaction with NFT/SFT tokens + * @param senderAddress the address of the sender + * @param offerId the id of the offer to be accepted + * @param amount the amount of tokens to be bought + * @param tokenIdentifier the identifier of the token for the payment + * @param nonce the nonce of the token for the payment + * @param paymentAmount the amount of the token for the payment + */ + + acceptOfferWithNFT( + senderAddress: IAddress, + offerId: number, + amount: BigNumber.Value, + tokenIdentifier: string, + nonce: number, + paymentAmount: BigNumber.Value + ): Transaction { + const offerEsdtTx = new Transaction({ + value: 0, + data: new ContractCallPayloadBuilder() + .setFunction(new ContractFunction('ESDTNFTTransfer')) + .addArg(new TokenIdentifierValue(tokenIdentifier)) + .addArg(new U64Value(nonce)) + .addArg(new BigUIntValue(paymentAmount)) + .addArg(new AddressValue(this.contract.getAddress())) + .addArg(new StringValue('acceptOffer')) + .addArg(new U64Value(offerId)) + .addArg(new BigUIntValue(amount)) + .build(), + receiver: senderAddress, + sender: senderAddress, + gasLimit: 20000000, + chainID: this.chainID + }); + return offerEsdtTx; + } + /** * Creates a `acceptOffer` transaction with EGLD * @param senderAddress the address of the sender * @param offerId the id of the offer to be accepted - * @param amount the amount of tokens to be bought + * @param amount the price of the offer for the total amount to be bought (must include the buyer fee) * @param price the price of the offer (must include the buyer fee) */ acceptOfferWithEGLD( From 9ba93285d8a842eb49d9de46fe00b44588c5bc51 Mon Sep 17 00:00:00 2001 From: Damian Date: Fri, 9 Feb 2024 08:54:32 +0200 Subject: [PATCH 6/7] chore: package version up --- package-lock.json | 11 +++-------- package.json | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index fe28400..e63d873 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,12 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "2.6.0", + "version": "0.0.0-semantic-release", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@itheum/sdk-mx-data-nft", -<<<<<<< HEAD - "version": "2.5.0", - "hasInstallScript": true, -======= - "version": "2.6.0", ->>>>>>> main + "version": "0.0.0-semantic-release", "license": "GPL-3.0-only", "dependencies": { "@multiversx/sdk-core": "12.18.0", @@ -22,7 +17,7 @@ "devDependencies": { "@commitlint/config-conventional": "18.4.4", "@types/jest": "29.5.11", - "commitlint": "^18.4.4", + "commitlint": "18.4.4", "husky": "8.0.3", "jest": "29.7.0", "ts-jest": "29.1.2", diff --git a/package.json b/package.json index a8041e6..739a253 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "0.0.0-semantic-release", + "version": "2.6.3", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js", From 75f6e67579c2b42b5ee26429dcbd455f418ec1a1 Mon Sep 17 00:00:00 2001 From: Damian Date: Thu, 22 Feb 2024 10:19:39 +0200 Subject: [PATCH 7/7] chore: npm install --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index e63d873..71e3477 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "0.0.0-semantic-release", + "version": "2.6.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@itheum/sdk-mx-data-nft", - "version": "0.0.0-semantic-release", + "version": "2.6.3", "license": "GPL-3.0-only", "dependencies": { "@multiversx/sdk-core": "12.18.0",