Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features from 1.10.0 (project) #81

Merged
merged 6 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 96 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
"author": "Itheum Protocol",
"license": "GPL-3.0-only",
"dependencies": {
"@multiversx/sdk-core": "12.11.0",
"@multiversx/sdk-network-providers": "2.0.0",
"@multiversx/sdk-core": "12.17.0",
"@multiversx/sdk-network-providers": "2.2.0",
"bignumber.js": "9.1.2",
"nft.storage": "7.1.1"
},
"devDependencies": {
"@types/jest": "29.5.4",
"@types/jest": "29.5.11",
"jest": "29.7.0",
"ts-jest": "29.1.1",
"tslint": "6.1.3",
"typedoc": "0.25.1",
"typescript": "5.2.2"
"typedoc": "0.25.4",
"typescript": "5.3.3"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/common/mint-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NFTStorage, File } from 'nft.storage';
import { File, NFTStorage } from 'nft.storage';

export async function dataNFTDataStreamAdvertise(
dataNFTStreamUrl: string,
Expand Down
5 changes: 3 additions & 2 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js';
import { DataNft } from '../datanft';
import { NftEnumType, NftType, Offer } from '../interfaces';
import { ErrFetch, ErrMissingTrait, ErrMissingValueForTrait } from '../errors';
import { NftEnumType, NftType, Offer } from '../interfaces';

export function numberToPaddedHex(value: BigNumber.Value) {
let hex = new BigNumber(value).toString(16);
Expand Down Expand Up @@ -56,6 +56,7 @@ export function parseDataNft(value: NftType): DataNft {
nonce: value.nonce,
collection: value.collection,
balance: value.balance ? Number(value.balance) : 0,
owner: value.owner ? value.owner : '',
...DataNft.decodeAttributes(value.attributes)
});
}
Expand Down Expand Up @@ -362,7 +363,7 @@ export function validateSpecificParamsMint(params: {
datasetDescription?: string | undefined;
royalties?: number | undefined;
supply?: number | undefined;
antiSpamTax?: number | undefined;
antiSpamTax?: BigNumber.Value | undefined;
_mandatoryParamsList: string[]; // a pure JS fallback way to validate mandatory params, as typescript rules for mandatory can be bypassed by client app
}): {
allPassed: boolean;
Expand Down
45 changes: 33 additions & 12 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ import {
BinaryCodec,
SignableMessage
} from '@multiversx/sdk-core/out';
import minterAbi from './abis/datanftmint.abi.json';
import {
checkStatus,
createNftIdentifier,
numberToPaddedHex,
parseDataNft,
validateSpecificParamsViewData
} from './common/utils';
import {
Config,
EnvironmentsEnum,
apiConfiguration,
dataNftTokenIdentifier,
networkConfiguration
} from './config';
import {
createNftIdentifier,
numberToPaddedHex,
parseDataNft,
validateSpecificParamsViewData,
checkStatus
} from './common/utils';
import minterAbi from './abis/datanftmint.abi.json';
import { NftType, ViewDataReturnType } from './interfaces';
import {
ErrAttributeNotSet,
ErrDataNftCreate,
ErrDecodeAttributes,
ErrFetch,
ErrNetworkConfig
} from './errors';
import { NftType, ViewDataReturnType } from './interfaces';
import BigNumber from 'bignumber.js';

export class DataNft {
readonly tokenIdentifier: string = '';
Expand All @@ -36,13 +36,14 @@ export class DataNft {
readonly tokenName: string = '';
readonly creator: string = '';
readonly creationTime: Date = new Date();
readonly supply: number = 0;
readonly supply: BigNumber.Value = 0;
readonly description: string = '';
readonly title: string = '';
readonly royalties: number = 0;
readonly nonce: number = 0;
readonly collection: string = '';
readonly balance: number = 0;
readonly balance: BigNumber.Value = 0;
readonly owner: string = ''; // works if tokenIdentifier is an NFT

static networkConfiguration: Config;
static apiConfiguration: string;
Expand Down Expand Up @@ -227,6 +228,26 @@ export class DataNft {
return dataNfts;
}

/**
* Returns an array of `{address:string,balance:number}` representing the addresses that own the token
*/
async getOwners(): Promise<{ address: string; balance: number }[]> {
if (!this.tokenIdentifier && !this.nonce) {
throw new ErrAttributeNotSet('tokenIdentifier, nonce');
}
const identifier = createNftIdentifier(this.tokenIdentifier, this.nonce);

const response = await fetch(
`${DataNft.apiConfiguration}/nfts/${identifier}/accounts`
);

checkStatus(response);

const data = await response.json();

return data;
}

/**
* Gets the message to sign from the data marshal of the DataNft
*/
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './marketplace';
export * from './config';
export * from './interfaces';
export * from './datanft';
export * from './interfaces';
export * from './marketplace';
export * from './minter';
export * from './nft-minter';
export * from './sft-minter';
Loading