Skip to content

Instantly share code, notes, and snippets.

const f = async (param, callback=false) => {
try {
const data = await request.get(url);
if(callback) callback(null, data); // If callback, then call it
return data; // Then return data, it returns as a promise.resolve automatically
} catch(err) {
if(callback) callback(err); // If callback, then call it
throw err; // Then throw, it returns promise.reject automatically
}
}
const keyHash = (params) => {
let hash = '';
_.each(params, (val, key) => {
hash+=`${key}:${val}`;
});
return hash;
}
const execQueryCached = async (params) => {
const hash = keyHash(params);
const keyHash = (params) => {
let hash = '';
_.each(params, (val, key) => {
hash+=`${key}:${val}`;
});
return hash;
}
const genericRead = async (params, callback = false) => {
const hash = keyHash(method, params);
const secureRandom = require('secure-random');
const bip39 = require('bip39');
const hdkey = require('hdkey');
const ripemd160 = require('ripemd160');
const sha256 = require('js-sha256');
const bitcoin = require("bitcoinjs-lib")
const SEED = bip39.generateMnemonic(256, secureRandom.randomBuffer, bip39.wordlists.english); //generates string
console.log(SEED);
const seed = bip39.mnemonicToSeedSync(SEED);
const auth = () => {
let token;
if (secrets.length > 0) {
const idx = Math.floor(Math.random() * secrets.length);
token = jwt.sign({ key: secrets[idx].API_KEY, nonce: moment().valueOf() }, secrets[idx].API_SECRET);
} else {
token = jwt.sign({ key: API_KEY, nonce: moment().valueOf() }, API_SECRET);
}
return { 'Authorization': `bearer ${token}`, 'Content-Type': 'application/json' };
};
pragma solidity 0.4.18;
interface tokenRecipient {function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external;}
contract owned {
address public owner;
function owned() internal {
owner = msg.sender;
}