n8n-nodes-wax
Version:
n8n Community Node Package for the WAX Blockchain
165 lines • 6.11 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.templateProperties = void 0;
exports.executeTemplateOperations = executeTemplateOperations;
const eosjs_1 = require("eosjs");
const eosjs_jssig_1 = require("eosjs/dist/eosjs-jssig");
const util_1 = require("util");
const atomic_1 = require("./atomic");
const util_2 = require("./util");
exports.templateProperties = [
{
displayName: 'Operation',
name: 'operation',
type: 'hidden',
noDataExpression: true,
displayOptions: {
show: {
resource: ['template'],
},
},
options: [
{
name: 'Create Template',
value: 'createTemplate',
description: 'Create a template in a collection under a schema',
action: 'Create a template in a collection under a schema',
},
],
default: 'createTemplate',
},
{
displayName: 'Collection Name',
name: 'collectionName',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
},
{
displayName: 'Schema Name',
name: 'schemaName',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
},
{
displayName: 'Transferable',
name: 'transferable',
type: 'boolean',
default: true,
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
description: 'Whether assets minted from this template can be transferred',
},
{
displayName: 'Burnable',
name: 'burnable',
type: 'boolean',
default: true,
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
description: 'Whether assets minted from this template can be burned',
},
{
displayName: 'Max Supply',
name: 'maxSupply',
type: 'number',
default: 0,
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
description: 'Maximum number of assets that may be minted from this template (0 = unlimited)',
},
{
displayName: 'Contract',
name: 'contract',
type: 'string',
default: 'atomicassets',
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
description: 'AtomicAssets contract account. Pin to a literal value - this is signed under your active permission.',
},
{
displayName: 'Immutable Data (JSON)',
name: 'immutableData',
type: 'json',
default: '{}',
displayOptions: {
show: {
resource: ['template'],
operation: ['createTemplate'],
},
},
description: 'Per-template data as a JSON object whose keys/types match the schema format',
},
];
async function executeTemplateOperations(items, i) {
const operation = this.getNodeParameter('operation', i);
const rawEndpoint = this.getNodeParameter('endpoint', i);
const endpoint = (0, util_2.validateEndpoint)(this, rawEndpoint, { signing: true });
if (operation === 'createTemplate') {
const credentials = await (0, util_2.getCredentials)(this);
const from = (0, util_2.requireAccountName)(this, credentials.account, 'Credential Account Name');
const key = credentials.privateKey;
const collectionName = (0, util_2.requireAccountName)(this, this.getNodeParameter('collectionName', i), 'Collection Name');
const schemaName = (0, util_2.requireAccountName)(this, this.getNodeParameter('schemaName', i), 'Schema Name');
const transferable = this.getNodeParameter('transferable', i);
const burnable = this.getNodeParameter('burnable', i);
const maxSupply = (0, atomic_1.requireMaxSupply)(this, this.getNodeParameter('maxSupply', i), 'Max Supply');
const contract = (0, util_2.requireAccountName)(this, this.getNodeParameter('contract', i), 'Contract');
const atomicRpc = (0, atomic_1.createAtomicRpc)(this, endpoint, contract);
await (0, atomic_1.ensureAuthorized)(this, atomicRpc, collectionName, from);
const format = await (0, atomic_1.fetchSchemaFormat)(this, atomicRpc, collectionName, schemaName);
const immutableData = (0, atomic_1.buildAttributeMap)(this, this.getNodeParameter('immutableData', i), format, 'Immutable Data');
const generator = (0, atomic_1.createActionGenerator)(this, contract);
const actions = await generator.createtempl([{ actor: from, permission: 'active' }], from, collectionName, schemaName, transferable, burnable, maxSupply, immutableData);
const signatureProvider = new eosjs_jssig_1.JsSignatureProvider([key]);
const rpc = new eosjs_1.JsonRpc(endpoint, { fetch });
const api = new eosjs_1.Api({
rpc,
signatureProvider,
textDecoder: new util_1.TextDecoder(),
textEncoder: new util_1.TextEncoder(),
});
const result = await api.transact({ actions }, { blocksBehind: 3, expireSeconds: 30 });
return {
returnData: {
json: {
success: true,
collection_name: collectionName,
schema_name: schemaName,
transaction: result,
},
},
};
}
return {};
}
//# sourceMappingURL=template.js.map