forked from metaplex-foundation/js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Nft.ts
65 lines (57 loc) · 2.65 KB
/
Nft.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { PublicKey } from '@safecoin/web3.js';
import { Model } from '@/shared';
import { MetadataAccount, MasterEditionAccount } from '@/programs/tokenMetadata';
import { TokenStandard, Collection, Uses, Creator } from '@leda-mint-io/lpl-token-metadata';
import { bignum } from '@j0nnyboi/beet';
import { JsonMetadata } from './JsonMetadata';
import { removeEmptyChars } from '@/utils';
export class Nft extends Model {
/** The Metadata PDA account defining the NFT. */
public readonly metadataAccount: MetadataAccount;
/** The optional Metadata Edition PDA account associated with the NFT. */
public readonly masterEditionAccount: MasterEditionAccount | null;
/** The JSON metadata from the URI. */
public readonly metadata: JsonMetadata | null;
/** Data from the Metadata account. */
public readonly updateAuthority: PublicKey;
public readonly mint: PublicKey;
public readonly name: string;
public readonly symbol: string;
public readonly uri: string;
public readonly sellerFeeBasisPoints: number;
public readonly creators: Creator[] | null;
public readonly primarySaleHappened: boolean;
public readonly isMutable: boolean;
public readonly editionNonce: number | null;
public readonly tokenStandard: TokenStandard | null;
public readonly collection: Collection | null;
public readonly uses: Uses | null;
/** Data from the MasterEdition account. */
public readonly supply: bignum | null;
public readonly maxSupply: bignum | null;
constructor(
metadataAccount: MetadataAccount,
masterEditionAccount: MasterEditionAccount | null = null,
metadata: JsonMetadata | null = null
) {
super();
this.metadataAccount = metadataAccount;
this.masterEditionAccount = masterEditionAccount;
this.metadata = metadata;
this.updateAuthority = metadataAccount.data.updateAuthority;
this.mint = metadataAccount.data.mint;
this.name = removeEmptyChars(metadataAccount.data.data.name);
this.symbol = removeEmptyChars(metadataAccount.data.data.symbol);
this.uri = removeEmptyChars(metadataAccount.data.data.uri);
this.sellerFeeBasisPoints = metadataAccount.data.data.sellerFeeBasisPoints;
this.creators = metadataAccount.data.data.creators;
this.primarySaleHappened = metadataAccount.data.primarySaleHappened;
this.isMutable = metadataAccount.data.isMutable;
this.editionNonce = metadataAccount.data.editionNonce;
this.tokenStandard = metadataAccount.data.tokenStandard;
this.collection = metadataAccount.data.collection;
this.uses = metadataAccount.data.uses;
this.supply = masterEditionAccount?.data.supply ?? null;
this.maxSupply = masterEditionAccount?.data.maxSupply ?? null;
}
}