n8n-nodes-wax
Version:
n8n Community Node Package for the WAX Blockchain
97 lines • 3.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaxVerifyAddress = void 0;
const axios_1 = __importDefault(require("axios"));
const util_1 = require("../Wax/resources/util");
class WaxVerifyAddress {
constructor() {
this.description = {
hidden: true,
displayName: 'WAX Verify Address',
name: 'waxVerifyAddress',
icon: 'file:wax.svg',
group: ['transform'],
version: 1,
description: 'Verify an address exists on the WAX blockchain',
defaults: {
name: 'Verify Address',
},
inputs: ['main'],
outputs: ['main', 'main'],
outputNames: ['valid', 'invalid'],
properties: [
{
displayName: 'Account Name',
name: 'account',
type: 'string',
default: '',
required: true,
description: 'WAX account name to verify',
},
{
displayName: 'API Endpoint',
name: 'endpoint',
type: 'string',
default: 'https://wax.greymass.com',
required: true,
}
],
};
}
async execute() {
const items = this.getInputData();
const validData = [];
const invalidData = [];
for (let i = 0; i < items.length; i++) {
const rawAccount = this.getNodeParameter('account', i);
const rawEndpoint = this.getNodeParameter('endpoint', i);
const endpoint = (0, util_1.validateEndpoint)(this, rawEndpoint);
let account;
try {
account = (0, util_1.requireAccountName)(this, rawAccount, 'Account Name');
}
catch {
invalidData.push({
json: {
account: rawAccount,
message: 'Account name is not a valid WAX account name',
},
});
continue;
}
try {
const result = await axios_1.default.post((0, util_1.buildUrl)(endpoint, '/v1/chain/get_account'), { account_name: account });
validData.push({
json: {
account,
created: result.data.created,
message: 'Account exists on the WAX blockchain'
}
});
}
catch (error) {
let message = 'Account does not exist on the WAX blockchain';
if (axios_1.default.isAxiosError(error) && error.response) {
if (error.response.status === 404) {
message = 'Account not found (404)';
}
else if (error.response.data && error.response.data.error) {
message = `Account verification failed: ${error.response.data.error.what || error.response.data.error}`;
}
}
invalidData.push({
json: {
account,
message
}
});
}
}
return [validData, invalidData];
}
}
exports.WaxVerifyAddress = WaxVerifyAddress;
//# sourceMappingURL=WaxVerifyAddress.node.js.map