diff options
| author | Adam Soltys <[email protected]> | 2019-04-18 22:28:22 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2019-04-18 22:28:22 -0700 |
| commit | 88e123e44884e1c0676c84627bf25b2b27a38e59 (patch) | |
| tree | e0d9b7bf3bc006f5a54b5b1bf52fd8c9752afe9d | |
| parent | 2d20ab4b5859ac4b1b05e85a6c08ad5c888ff78e (diff) | |
| download | coinos-server-88e123e44884e1c0676c84627bf25b2b27a38e59.tar.gz coinos-server-88e123e44884e1c0676c84627bf25b2b27a38e59.zip | |
logging
| -rw-r--r-- | index.js | 142 |
1 files changed, 18 insertions, 124 deletions
@@ -547,6 +547,7 @@ const authy = new Client({ key: config.authy.key }); app.post('/sendPayment', auth, async (req, res) => { let hash = req.body.payreq let payreq = bolt11.decode(hash) + l("sending lightning", req.user.username, payreq.satoshis) if (seen.includes(hash)) { return res.status(500).send("Invoice has been paid, can't pay again") @@ -695,6 +696,8 @@ const authy = new Client({ key: config.authy.key }); let { address, amount } = req.body + l("sending coins", req.user.username, amount, address) + if (amount === req.user.balance) { amount = req.user.balance - MINFEE } @@ -711,7 +714,8 @@ const authy = new Client({ key: config.authy.key }); ) if (amount > balance) { - throw new Error() + l("amount exceeds balance", amount, balance) + throw new Error("insufficient funds") } req.user.balance -= parseInt(amount) + 10000 @@ -723,10 +727,12 @@ const authy = new Client({ key: config.authy.key }); try { await bc.walletPassphrase(config.bitcoin.walletpass, 300) + l("sending transaction") let txid = await bc.sendToAddress( address, (amount / 100000000).toFixed(8) ) + l("transaction sent", txid) let txhex = await bc.getRawTransaction(txid) let tx = bitcoin.Transaction.fromHex(txhex) @@ -954,131 +960,19 @@ const authy = new Client({ key: config.authy.key }); }) app.get('/currencies', async (req, res) => { - res.send([ - 'ARS', - 'TTD', - 'EUR', - 'LBP', - 'LTC', - 'KZT', - 'PGK', - 'MAD', - 'RWF', - 'XOF', - 'AFN', - 'MDL', - 'SZL', - 'BGN', - 'CNH', - 'IQD', - 'RON', - 'UZS', - 'MYR', - 'MWK', - 'BOB', - 'XRP', - 'RSD', - 'KRW', - 'LKR', - 'VES', - 'PAB', - 'BWP', - 'ISK', - 'CUC', - 'LSL', - 'KHR', - 'USD', - 'UAH', - 'MMK', - 'SAR', - 'XAG', - 'DZD', - 'ETH', - 'NZD', - 'ZMW', - 'ALL', - 'PEN', - 'ILS', - 'CAD', - 'HKD', - 'THB', - 'BND', - 'UYU', - 'TND', - 'COP', - 'MXN', - 'EGP', - 'AUD', - 'BYN', - 'TZS', - 'KWD', - 'SEK', - 'PHP', - 'DASH', - 'JOD', - 'HUF', - 'INR', - 'SGD', - 'PLN', - 'GGP', - 'VND', - 'CLP', - 'XMR', - 'BHD', - 'XAR', - 'JPY', - 'XAU', - 'GHS', - 'AMD', - 'BAM', - 'OMR', - 'KGS', - 'CHF', - 'IRR', - 'GEL', - 'DKK', - 'CZK', - 'XAF', - 'BDT', - 'MUR', - 'GIP', - 'BIF', - 'PYG', - 'NPR', - 'NGN', - 'VEF', - 'GBP', - 'CRC', - 'GTQ', - 'PKR', - 'NAD', - 'AOA', - 'HNL', - 'MZN', - 'QAR', - 'JMD', - 'ETB', - 'BYR', - 'NOK', - 'TWD', - 'KES', - 'MOP', - 'HRK', - 'CNY', - 'AED', - 'RUB', - 'BRL', - 'TRY', - 'DOP', - 'UGX', - 'ZAR', - 'IDR', - 'CDF', - 'MGA', - 'AZN', - ]) + res.send(['CAD', 'USD']) }) + app.get('/balance/:address', async (req, res) => { + let network = config.bitcoin.network === 'mainnet' ? 'main' : 'test3' + let { address } = req.params + + res.send( + await axios.get( + `https://api.blockcypher.com/v1/btc/${network}/addrs/${address}/balance` + ) + ) + app.use(function (err, req, res, next) { res.status(500) res.send('An error occurred') |
