@@ -7,6 +7,11 @@ const debug = require('debug')('coinFuncs');
77
88let hexChars = new RegExp ( "[0-9a-f]+" ) ;
99
10+ function handleRpcError ( err , body , callback ) {
11+ console . error ( JSON . stringify ( body ) ) ;
12+ callback ( new Error ( `${ err } RPC: ${ JSON . stringify ( body ) } ` ) )
13+ }
14+
1015function Coin ( data ) {
1116 this . bestExchange = global . config . payout . bestExchange ;
1217 this . data = data ;
@@ -42,37 +47,28 @@ function Coin(data){
4247
4348 this . niceHashDiff = 400000 ;
4449
45- this . getBlockHeaderByID = function ( blockId , callback ) {
46- global . support . rpcDaemon ( 'getblockheaderbyheight' , { "height" : blockId } , function ( body ) {
47- if ( body . hasOwnProperty ( 'result' ) ) {
48- return callback ( null , body . result . block_header ) ;
49- } else {
50- console . error ( JSON . stringify ( body ) ) ;
51- return callback ( true , body ) ;
52- }
53- } ) ;
50+ this . getBlockHeaderByHeight = ( height , callback ) => { // unused
51+ global . support . rpcDaemon ( 'getblockheaderbyheight' , { height } , ( body ) =>
52+ ( body && body , result && body . result . status === 'OK' && body . result . block_header )
53+ ? callback ( null , body . result . block_header )
54+ : handleRpcError ( `RPC 'getblockheaderbyheight' to monero daemon failed to return the block header.` , body , callback )
55+ ) ;
5456 } ;
5557
56- this . getBlockHeaderByHash = function ( blockHash , callback ) {
57- global . support . rpcDaemon ( 'getblockheaderbyhash' , { "hash" : blockHash } , function ( body ) {
58- if ( typeof ( body ) !== 'undefined' && body . hasOwnProperty ( 'result' ) ) {
59- return callback ( null , body . result . block_header ) ;
60- } else {
61- console . error ( JSON . stringify ( body ) ) ;
62- return callback ( true , body ) ;
63- }
64- } ) ;
58+ this . getBlockHeaderByHash = ( hash , callback ) => {
59+ global . support . rpcDaemon ( 'getblockheaderbyhash' , { hash } , ( body ) =>
60+ ( body && body , result && body . result . status === 'OK' && body . result . block_header )
61+ ? callback ( null , body . result . block_header )
62+ : handleRpcError ( `RPC 'getblockheaderbyhash' to monero daemon failed to return the block header.` , body , callback )
63+ ) ;
6564 } ;
6665
67- this . getLastBlockHeader = function ( callback ) {
68- global . support . rpcDaemon ( 'getlastblockheader' , [ ] , function ( body ) {
69- if ( typeof ( body ) !== 'undefined' && body . hasOwnProperty ( 'result' ) ) {
70- return callback ( null , body . result . block_header ) ;
71- } else {
72- console . error ( JSON . stringify ( body ) ) ;
73- return callback ( true , body ) ;
74- }
75- } ) ;
66+ this . getLastBlockHeader = ( callback ) => {
67+ global . support . rpcDaemon ( 'getlastblockheader' , { } , ( body ) =>
68+ ( body && body . result && body . result . status === 'OK' && body . result . block_header )
69+ ? callback ( null , body . result . block_header )
70+ : handleRpcError ( `RPC 'getlastblockheader' to monero daemon failed to return the block header.` , body , callback )
71+ ) ;
7672 } ;
7773
7874 this . getBlockTemplate = function ( walletAddress , callback ) {
0 commit comments