@ -1,35 +1,34 @@
var request = require ( 'request -promise ') ;
var request = require ( 'request ') ;
var options = require ( "../connect" ) ;
var common = require ( '../common' ) ;
var logger = require ( './logger' ) ;
exports . operateWallet = ( req , res , next ) => {
var requestBody = {
var requestBody = {
wallet _password : Buffer . from ( req . body . wallet _password ) . toString ( 'base64' )
} ;
if ( undefined === req . params . operation || req . params . operation === 'unlock' ) {
options . url = common . lnd _server _url + '/unlockwallet' ;
options . form = JSON . stringify ( requestBody ) ;
err _message = 'Unlocking wallet failed! Verify that lnd is running !';
err _message = 'Unlocking wallet failed! Verify that lnd is running and the wallet is locked !';
} else {
options . url = common . lnd _server _url + '/initwallet' ;
options . form = JSON . stringify ( requestBody ) ;
err _message = 'Initializing wallet failed!' ;
}
options . qs = req . query ;
request . post ( options ) . then ( ( body ) => {
request . post ( options , ( error , response , body ) => {
logger . info ( '\r\nWallet: 20: ' + JSON . stringify ( Date . now ( ) ) + ': INFO: Unlock Wallet Response: ' + JSON . stringify ( body ) ) ;
const body _str = ( undefined === body ) ? '' : JSON . stringify ( body ) ;
const search _idx = ( undefined === body ) ? - 1 : body _str . search ( 'Not Found' ) ;
if ( undefined === body ) {
res . status ( 500 ) . json ( {
message : err _message ,
error : 'Unlocking wallet failed! Verify that lnd is running!'
error : err _message
} ) ;
} else if ( search _idx > - 1 ) {
res . status ( 500 ) . json ( {
message : err _message ,
error : 'Unlocking wallet failed! Verify that lnd is running!'
error : err _message
} ) ;
} else if ( body . error ) {
if ( ( body . code === 1 && body . error === 'context canceled' ) || ( body . code === 14 && body . error === 'transport is closing' ) ) {
@ -43,15 +42,5 @@ exports.operateWallet = (req, res, next) => {
} else {
res . status ( 201 ) . json ( { wallet : 'successful' } ) ;
}
} )
. catch ( function ( err ) {
if ( ( err . error . code === 1 && err . error . error === 'context canceled' ) || ( err . error . code === 14 && err . error . error === 'transport is closing' ) ) {
res . status ( 201 ) . json ( { wallet : 'successful' } ) ;
} else {
res . status ( 500 ) . json ( {
message : err _message ,
error : err . error . error
} ) ;
}
} ) ;
} ;