@effectai/effect-js
Version:
Effect Network Javscript/Typescript SDK (for [https://effect.network](https://effect.network))
93 lines • 3.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AtomicAssetsService = void 0;
const antelope_1 = require("@wharfkit/antelope");
const atomicassets_1 = require("atomicassets");
/**
* AtomicAssetsService
*
* This service is used to interact with the atomicassets contract.
*
* Read more on the atomicassets contracts here:
* https://github.com/pinknetworkx/atomicassets-contract/wiki/
*/
class AtomicAssetsService {
constructor(client) {
this.client = client;
/**
* Retrieve atomic assets from the atomicassets contract for the given account
* @param account eosio account name
* @returns {Promise<AtomicAsset[]>} Returns an array of atomic assets
*/
this.getAccountAssets = async (account) => {
const { rows } = await this.client.eos.v1.chain.get_table_rows({
code: this.client.config.atomicAssetsContract,
scope: account,
table: 'assets',
limit: 100
});
return rows;
};
/**
* Retrieve atomic assets from the atomicassets contract
* @param account eosio account name
* @param assetId
* @returns {Promise<AtomicAsset>} Returns the atomic asset config
*/
this.getAsset = async (account, assetId, deserializeAsset = true) => {
try {
const { rows } = await this.client.eos.v1.chain.get_table_rows({
code: this.client.config.atomicAssetsContract,
scope: account,
table: 'assets',
limit: 1,
lower_bound: antelope_1.UInt128.from(assetId),
upper_bound: antelope_1.UInt128.from(assetId)
});
const [asset] = rows;
if (deserializeAsset) {
const schema = await this.getSchema(asset.collection_name, asset.schema_name);
const objectSchema = (0, atomicassets_1.ObjectSchema)(schema.format);
const mutable_deserialized_data = (0, atomicassets_1.deserialize)(asset.mutable_serialized_data, objectSchema);
const immutable_deserialized_data = (0, atomicassets_1.deserialize)(asset.immutable_serialized_data, objectSchema);
return { ...asset, immutable_deserialized_data, mutable_deserialized_data };
}
else {
return asset;
}
}
catch (error) {
console.error(error);
throw error;
}
};
// TODO: Figure out if there is a collection that ever has a schema with more than 100 rows
this.getCollection = async (collectionName) => {
const { rows } = await this.client.eos.v1.chain.get_table_rows({
code: this.client.config.atomicAssetsContract,
scope: collectionName,
table: 'collections',
limit: 100,
});
// console.debug('getCollection', rows)
return rows;
};
this.getSchema = async (collectionName, schemaName) => {
const { rows } = await this.client.eos.v1.chain.get_table_rows({
code: this.client.config.atomicAssetsContract,
scope: collectionName,
table: 'schemas',
limit: 100
});
const schema = rows.find((schema) => schema.schema_name === schemaName);
return schema;
};
/**
* TODO
* Mint an asset to the given account
*/
this.mintAsset = async () => { };
}
}
exports.AtomicAssetsService = AtomicAssetsService;
//# sourceMappingURL=atomic.js.map