Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// https://runkit.com/y12/58ada40ff01e960014715192
var request = require('request')
var bitcore = require("bitcore-lib")
var _ = require("lodash")
var Unit = bitcore.Unit
const coindeskapi = 'https://api.coindesk.com/v1/bpi/currentprice/TWD.json'
const feeapi = 'https://bitcoinfees.21.co/api/v1/fees/recommended'
// https://bitcoinfees.21.co/api
const avgbytes = 250
function saToBtc(satoshis) {
return Unit.fromSatoshis(satoshis).toBTC()
}
function getTwdFee(cb) {
request({
url: feeapi,
json: true
}, (err, resp, fee) => {
// console.log(fee)
// { fastestFee: 160, halfHourFee: 160, hourFee: 140 }
'use strict';
var _ = require('lodash');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var chai = require('chai');
var should = chai.should();
var spawn = require('child_process').spawn;
var async = require('async');
var bitcore = require('bitcore-lib');
var Unit = bitcore.Unit;
var CLTVTransaction = require('../lib/transaction/transaction');
var Transaction = bitcore.Transaction;
var PrivateKey = bitcore.PrivateKey;
var BitcoinRPC = require('bitcoind-rpc');
var Consumer = require('../lib/consumer');
var Provider = require('../lib/provider');
var Script = require('../lib/transaction/script');
var rpcConfig = {
protocol: 'http',
user: 'bitcoin',
pass: 'local321',
host: '127.0.0.1',
port: '58332',
rejectUnauthorized: false
};
'use strict';
var bitcore = require('bitcore-lib');
var _ = require('lodash');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var fs = require('fs');
var async = require('async');
var spawn = require('child_process').spawn;
var http = require('http');
var Unit = bitcore.Unit;
var Transaction = bitcore.Transaction;
var PrivateKey = bitcore.PrivateKey;
var assert = require('assert');
var Utils = function(opts) {
this.opts = opts;
};
Utils.prototype.writeConfigFile = function(fileStr, obj) {
fs.writeFileSync(fileStr, JSON.stringify(obj));
};
Utils.prototype.toArgs = function(opts) {
return Object.keys(opts).map(function(key) {
return '-' + key + '=' + opts[key];
});
.then((fee) => {
fee = JSON.parse(fee);
const txFee = bitcore.Unit.fromBTC(fee[blocks]).toSatoshis();
console.log(`data.txFee${txFee}`);
resolve(txFee);
})
.catch((err) => {
"use strict";
const fs = require('fs');
let qrcode = require('qrcode-terminal');
let unit = require('bitcore-lib').Unit;
let intl = require('intl');
const PrivateWalletService_1 = require('../Services/PrivateWalletService');
const IceWallet_1 = require('./IceWallet');
const PrivateWalletInfo_1 = require('../Models/PrivateWalletInfo');
const inquirer = require('inquirer');
class IceWalletPrivate extends IceWallet_1.default {
loadWalletFromInfo(callback) {
inquirer.prompt({
name: 'password',
type: 'password',
message: 'enter your password to open the wallet',
})
.then((answers) => {
let password = answers['password'].toString();
console.log('loading and decrypting wallet info from' + this.pathToWalletInfo);
console.log('this might take a minute');
PrivateWalletService.prototype.verifyTransaction = function (transaction, fee, callback) {
console.log('Please verify this transaction');
transaction.outputs.forEach(function (output) {
console.log('Send: ' + bitcore.Unit.fromSatoshis(output._satoshis).toBTC());
console.log('To: ' + output._script.toAddress().toString());
});
console.log('Fee: ' + bitcore.Unit.fromSatoshis(fee).toBTC());
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('answer y/n\n', function (answer) {
rl.close();
if (answer == 'y') {
return callback(null);
}
else if (answer == 'n') {
return callback('user declined transaction');
}
else {
console.log('answer either "y" or "n"');
return callback('invalid answer');
}
"use strict";
const fs = require('fs');
let unit = require('bitcore-lib').Unit;
let intl = require('intl');
const inquirer = require('inquirer');
const PublicWalletService_1 = require('../Services/PublicWalletService');
const PublicWalletInfo_1 = require('../Models/PublicWalletInfo');
const IceWallet_1 = require('./IceWallet');
class IceWalletPublic extends IceWallet_1.default {
createNewWallet(callback) {
inquirer.prompt([
{
name: 'password1',
type: 'password',
message: 'create a password',
validate: (password) => { if (!password)
return 'Password required';
else
return true; }
async getFee(blocks = NB_BLOCKS, toBTC) {
const url = `${this.network}/utils/estimatefee?nbBlocks=${blocks}`;
const response = await axios.get(url);
if (response.status === 200) {
let txFee = '';
if (toBTC) {
txFee = bitcore.Unit.fromBTC(response.data[blocks]).toBTC();
} else {
txFee = bitcore.Unit.fromBTC(response.data[blocks]).toSatoshis();
}
return txFee;
}
return false;
}
'use strict';
var BaseService = require('../../service');
var inherits = require('util').inherits;
var async = require('async');
var index = require('../../');
var log = index.log;
var bitcore = require('bitcore-lib');
var Unit = bitcore.Unit;
var _ = bitcore.deps._;
var lodash = require('lodash');
var Encoding = require('./encoding');
var Transform = require('stream').Transform;
var assert = require('assert');
var utils = require('../../utils');
var AddressService = function(options) {
BaseService.call(this, options);
this._header = this.node.services.header;
this._block = this.node.services.block;
this._timestamp = this.node.services.timestamp;
this._transaction = this.node.services.transaction;
this._network = this.node.network;
this._db = this.node.services.db;
async getFee(blocks = NB_BLOCKS, toBTC) {
const url = `${this.network}/utils/estimatefee?nbBlocks=${blocks}`;
const response = await axios.get(url);
if (response.status === 200) {
let txFee = '';
if (toBTC) {
txFee = bitcore.Unit.fromBTC(response.data[blocks]).toBTC();
} else {
txFee = bitcore.Unit.fromBTC(response.data[blocks]).toSatoshis();
}
return txFee;
}
return false;
}