n8n-nodes-wax
Version:
n8n Community Node Package for the WAX Blockchain
138 lines • 6.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaxGetAssets = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const dist_1 = require("@waxio/waxjs/dist");
const util_1 = require("../Wax/resources/util");
class WaxGetAssets {
constructor() {
this.description = {
hidden: true,
displayName: 'WAX Get Assets',
name: 'waxGetAssets',
icon: 'file:wax.svg',
group: ['transform'],
version: 1,
description: 'Get NFTs for an account',
defaults: {
name: 'Get Assets',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Account Name',
name: 'account',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Template ID (Optional)',
name: 'templateId',
type: 'string',
default: '',
description: 'Comma-separated list of template IDs',
},
{
displayName: 'Collection (Optional)',
name: 'collection',
type: 'string',
default: '',
description: 'Comma-separated list of collections',
},
{
displayName: 'Schema (Optional)',
name: 'schema',
type: 'string',
default: '',
description: 'Comma-separated list of schemas',
},
{
displayName: 'Code',
name: 'code',
type: 'string',
default: 'atomicassets',
required: true,
},
{
displayName: 'API Endpoint',
name: 'endpoint',
type: 'string',
default: 'https://wax.greymass.com',
required: true,
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
const account = (0, util_1.requireAccountName)(this, this.getNodeParameter('account', i), 'Account Name');
const templateIdInput = this.getNodeParameter('templateId', i);
const collectionInput = this.getNodeParameter('collection', i);
const schemaInput = this.getNodeParameter('schema', i);
const code = (0, util_1.requireAccountName)(this, this.getNodeParameter('code', i), 'Code');
const rawEndpoint = this.getNodeParameter('endpoint', i);
const endpoint = (0, util_1.validateEndpoint)(this, rawEndpoint);
const templateIds = templateIdInput ? templateIdInput.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id)) : [];
const collections = collectionInput ? collectionInput.split(',').map(c => c.trim()).filter(c => c !== '') : [];
const schemas = schemaInput ? schemaInput.split(',').map(s => s.trim()).filter(s => s !== '') : [];
const wax = new dist_1.WaxJS(endpoint);
const assets = new Array();
let result = { next_key: null, more: true };
let iterations = 0;
let lastKey = null;
do {
if (++iterations > util_1.MAX_PAGINATION_ITERATIONS) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `get_table_rows pagination exceeded ${util_1.MAX_PAGINATION_ITERATIONS} iterations`);
}
result = await wax.rpc.get_table_rows({
json: true,
code,
scope: account,
table: 'assets',
lower_bound: result.next_key,
limit: 1000,
reverse: false,
show_payer: false,
});
if (result.more && result.next_key !== null && result.next_key === lastKey) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'get_table_rows pagination did not advance');
}
lastKey = result.next_key;
if (!result) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Empty response from get_table_rows');
}
if (!result.hasOwnProperty('rows')) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Response missing rows property: ' + JSON.stringify(result));
}
if (result.rows && Array.isArray(result.rows)) {
result.rows.forEach((asset) => {
if ((templateIds.length > 0 && !templateIds.includes(asset.template_id)) ||
(collections.length > 0 && !collections.includes(asset.collection_name)) ||
(schemas.length > 0 && !schemas.includes(asset.schema_name))) {
return;
}
assets.push({
asset_id: asset.asset_id,
template_id: asset.template_id,
collection_name: asset.collection_name,
schema_name: asset.schema_name,
});
});
}
} while (result.more && result.rows);
returnData.push({
json: {
account,
assets
}
});
}
return [returnData];
}
}
exports.WaxGetAssets = WaxGetAssets;
//# sourceMappingURL=WaxGetAssets.node.js.map