UNPKG

@waves/node-state

Version:
70 lines 3.02 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.exec = exports.run = exports.broadcastAndWait = void 0; const waves_transactions_1 = require("@waves/waves-transactions"); const constants_1 = require("./constants"); const child_process_1 = require("child_process"); const console_1 = __importDefault(require("./utils/console")); function broadcastAndWait(tx) { return __awaiter(this, void 0, void 0, function* () { try { yield waves_transactions_1.broadcast(tx, constants_1.NODE_URL); yield waves_transactions_1.waitForTx(tx.id, { apiBase: constants_1.NODE_URL }); } catch (e) { console_1.default.error(`Can't send transaction! ${JSON.stringify(tx, null, 4)}` + '\n' + `Error: ${e.message}`); } }); } exports.broadcastAndWait = broadcastAndWait; exports.run = (command, args, options) => { console_1.default.log(`${command} ${args.join(' ')}`); const log = options && options.log || console_1.default.log; const error = options && options.error || console_1.default.error; const process = child_process_1.spawn(command, args); process.stdout.on('data', data => { log(String(data)); }); process.stderr.on('data', data => { error(data); }); process.on('close', (code) => { console_1.default.info(`Child process "${command} ${args.join(' ')}" exited with code ${code}`); }); return process; }; exports.exec = (command, args, options) => { console_1.default.log(`Exec "${command} ${args.join(' ')}"`); let data = ''; const process = child_process_1.spawn(command, args, options); process.stdout.on('data', chunk => { data += chunk; }); process.stderr.on('data', chunk => { data += chunk; }); return new Promise((resolve, reject) => { process.on('close', code => { if (code === 0) { resolve(data); } else { console_1.default.error(data); reject(`Child process "${command} ${args.join(' ')}" exited with code ${code}`); } }); }); }; //# sourceMappingURL=utils.js.map