1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.AtomicAssetsService = void 0;
|
4 | const antelope_1 = require("@wharfkit/antelope");
|
5 | const atomicassets_1 = require("atomicassets");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | class AtomicAssetsService {
|
15 | constructor(client) {
|
16 | this.client = client;
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | this.getAccountAssets = async (account) => {
|
23 | const { rows } = await this.client.eos.v1.chain.get_table_rows({
|
24 | code: this.client.config.atomicAssetsContract,
|
25 | scope: account,
|
26 | table: 'assets',
|
27 | limit: 100
|
28 | });
|
29 | return rows;
|
30 | };
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | this.getAsset = async (account, assetId, deserializeAsset = true) => {
|
38 | try {
|
39 | const { rows } = await this.client.eos.v1.chain.get_table_rows({
|
40 | code: this.client.config.atomicAssetsContract,
|
41 | scope: account,
|
42 | table: 'assets',
|
43 | limit: 1,
|
44 | lower_bound: antelope_1.UInt128.from(assetId),
|
45 | upper_bound: antelope_1.UInt128.from(assetId)
|
46 | });
|
47 | const [asset] = rows;
|
48 | if (deserializeAsset) {
|
49 | const schema = await this.getSchema(asset.collection_name, asset.schema_name);
|
50 | const objectSchema = (0, atomicassets_1.ObjectSchema)(schema.format);
|
51 | const mutable_deserialized_data = (0, atomicassets_1.deserialize)(asset.mutable_serialized_data, objectSchema);
|
52 | const immutable_deserialized_data = (0, atomicassets_1.deserialize)(asset.immutable_serialized_data, objectSchema);
|
53 | return { ...asset, immutable_deserialized_data, mutable_deserialized_data };
|
54 | }
|
55 | else {
|
56 | return asset;
|
57 | }
|
58 | }
|
59 | catch (error) {
|
60 | console.error(error);
|
61 | throw error;
|
62 | }
|
63 | };
|
64 |
|
65 | this.getCollection = async (collectionName) => {
|
66 | const { rows } = await this.client.eos.v1.chain.get_table_rows({
|
67 | code: this.client.config.atomicAssetsContract,
|
68 | scope: collectionName,
|
69 | table: 'collections',
|
70 | limit: 100,
|
71 | });
|
72 |
|
73 | return rows;
|
74 | };
|
75 | this.getSchema = async (collectionName, schemaName) => {
|
76 | const { rows } = await this.client.eos.v1.chain.get_table_rows({
|
77 | code: this.client.config.atomicAssetsContract,
|
78 | scope: collectionName,
|
79 | table: 'schemas',
|
80 | limit: 100
|
81 | });
|
82 | const schema = rows.find((schema) => schema.schema_name === schemaName);
|
83 | return schema;
|
84 | };
|
85 | |
86 |
|
87 |
|
88 |
|
89 | this.mintAsset = async () => { };
|
90 | }
|
91 | }
|
92 | exports.AtomicAssetsService = AtomicAssetsService;
|
93 |
|
\ | No newline at end of file |