Ripple-lib提交错误'UnhandledPromiseRejectionWarning:DisconnectedError:not opened'

时间:2018-04-19 14:46:40

标签: javascript node.js websocket ripple cryptocurrency

我无法使用ripple-lib和波纹服务器发送Ripple XRP 如果我使用已签名的付款对象提交,则会显示UnhandledPromiseRejectionWarning: DisconnectedError: not opened错误。

这是我的代码:

const instructions = {maxLedgerVersionOffset: 5, fee: fee};
const payment = {
   'source': {
     'address': from,
     'maxAmount': {
     'value': send_amount,
       'currency': 'XRP'
     }
  },
   'destination': {
     'address': to_address,
     'tag': to_tag,
     'amount': {
     'value': send_amount,
       'currency': 'XRP'
     }
   }
};
ripple_api.connect().then(() => {
   ripple_api.preparePayment(from, payment, instructions).then(prepared => {
     const {signedTransaction, id} = ripple_api.sign(prepared.txJSON, privateKey);
     ripple_api.submit(signedTransaction).then(result => {
       if(result.resultCode == 'tesSUCCESS'){
         res.send(JSON.stringify({status: 'success', txid : id}));
       }else{
         res.send(JSON.stringify({status: 'error', msg : result.resultMessage}));
       }
     }).catch(console.error);
   }).catch(console.error);
}).then(() => {
   return ripple_api.disconnect();
}).catch(console.error);

在此代码之后,错误显示如下:

(node:46089) UnhandledPromiseRejectionWarning: DisconnectedError: not opened
    at _ws.send.error (/var/www/web3app/node_modules/ripple-lib/dist/npm/common/connection.js:355:28)
    at WebSocket.send (/var/www/web3app/node_modules/ws/lib/WebSocket.js:359:15)
    at Promise (/var/www/web3app/node_modules/ripple-lib/dist/npm/common/connection.js:353:22)
    at new Promise (<anonymous>)
    at RestrictedConnection._send (/var/www/web3app/node_modules/ripple-lib/dist/npm/common/connection.js:352:16)
    at Promise (/var/www/web3app/node_modules/ripple-lib/dist/npm/common/connection.js:407:34)
    at new Promise (<anonymous>)
    at RestrictedConnection.request (/var/www/web3app/node_modules/ripple-lib/dist/npm/common/connection.js:364:16)
    at RestrictedConnection.request (/var/www/web3app/node_modules/ripple-lib/dist/npm/api.js:56:22)
    at RippleAPI.submit (/var/www/web3app/node_modules/ripple-lib/dist/npm/transaction/submit.js:31:28)
    at ripple_api.preparePayment.then.prepared (/var/www/web3app/routes/index.js:316:18)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:118:7)
(node:46089) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:46089) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 个答案:

答案 0 :(得分:0)

我认为你应该在

回复承诺
return ripple_api.preparePayment(from, payment, instructions).then(...)

这样你可以链接多个then语句 ripple_api.connect()