bitverse-atomicals-js
Version:
Atomicals Javascript Library and CLI - atomicals.xyz
95 lines (94 loc) • 4.16 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleResultLogging = exports.resolveWalletAliasNew = void 0;
const chalk = require("chalk");
const _1 = require(".");
const validate_wallet_storage_1 = require("./utils/validate-wallet-storage");
const quotes = require("success-motivational-quotes");
const qrcode = require("qrcode-terminal");
function resolveWalletAliasNew(walletInfo, alias, defaultValue) {
if (!alias) {
return defaultValue;
}
if (walletInfo[alias]) {
return walletInfo[alias];
}
if (walletInfo.imported[alias]) {
return walletInfo.imported[alias];
}
throw 'No wallet alias or valid address found: ' + alias;
}
exports.resolveWalletAliasNew = resolveWalletAliasNew;
function printSuccess(data, showDonation) {
console.log(JSON.stringify(data, null, 2));
if (!showDonation) {
return;
}
if (process.env.DISABLE_DONATE_QUOTE && process.env.DISABLE_DONATE_QUOTE === 'true') {
return;
}
console.log(chalk.blue("\n\n------------------------------------------------------------------------------"));
let q = 'Recommend to your children virtue; that alone can make them happy, not gold.';
let by = 'Ludwig van Beethoven';
try {
const quoteObj = quotes.getTodaysQuote();
q = quoteObj.body;
by = quoteObj.by;
}
catch (ex) {
// Lib not installed
}
console.log(chalk.green(q));
console.log(chalk.green('- ' + by));
console.log(chalk.blue("------------------------------------------------------------------------------\n"));
const donate = 'bc1pl6k2z5ra403zfeyevzsu7llh0mdqqn4802p4uqfhz6l7qzddq2mqduqvc6';
console.log('Thank you for your support and contributions to Atomicals CLI development! ❤️');
console.log(`Donation address: ${donate}\n`);
console.log(`Even a little goes a long way!\n`);
console.log(`Scan QR Code to Donate:`);
qrcode.generate(donate, { small: true });
}
function printFailure(data) {
console.log(JSON.stringify(data, null, 2));
}
function handleResultLogging(result, showDonation) {
if (!result || !result.success || !result.data) {
printFailure(result);
}
else {
printSuccess(result.data, showDonation);
}
}
exports.handleResultLogging = handleResultLogging;
function mintDft(ticker, options) {
return __awaiter(this, void 0, void 0, function* () {
try {
const walletInfo = yield (0, validate_wallet_storage_1.validateWalletStorage)();
console.log(walletInfo, 'walletInfo');
ticker = ticker.toLowerCase();
const atomicals = new _1.Atomicals(_1.ElectrumApi.createClient(process.env.ELECTRUMX_PROXY_BASE_URL || ''));
let walletRecord = resolveWalletAliasNew(walletInfo, options.initialowner, walletInfo.primary);
let fundingRecord = resolveWalletAliasNew(walletInfo, options.funding, walletInfo.funding);
const result = yield atomicals.mintDftInteractive({
rbf: options.rbf,
satsbyte: parseInt(options.satsbyte),
disableMiningChalk: options.disablechalk,
}, walletRecord.address, ticker, fundingRecord.WIF);
console.log(result, 'result');
// handleResultLogging(result, true);
}
catch (error) {
console.log(error, 'error');
}
});
}
mintDft('neutron', { satsbyte: '80' });