UNPKG

smart-rpc

Version:

Block and Transaction Real-Time Broadcasting in JavaScript.

1 lines 6.23 kB
module.exports=function(e){var t={};function n(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(o,s,function(t){return e[t]}.bind(null,s));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){e.exports=require("util")},function(e,t){e.exports=require("events")},function(e,t,n){var o=n(3),s=n(0),i=n(1).EventEmitter;function r(){i.call(this)}r.prototype={create:function(e){return new o(e)},listen:function(e){Array.isArray(e)||(e=[e]);var t=this;this.clients=[];for(let t=0;t<e.length;t++){var n=e[t],o=this.create(Object.assign(n,{listen:1}));this.clients.push(o)}for(let e=0;e<this.clients.length;e++){const n=this.clients[e];n.on("error",function(e){t.emit("error",n,e)}),n.on("hashblock",function(e){t.emit("hashblock",n,e)}),n.on("block",function(e){t.emit("block",n,e)}),n.on("rawtx",function(e){t.emit("rawtx",n,e)}),n.on("tx",function(e){t.emit("tx",n,e)})}}},s.inherits(r,i),e.exports=new r},function(e,t,n){"use strict";var o=n(4),s=n(0),i=n(5),r=n(6),c=n(7),a=n(8),l=n(1).EventEmitter;function d(e){l.call(this),i.setLevel("info"),this.opts=e,this.id=e.id||e._id,this.apis=["abandonTransaction","addMultiSigAddress","addNode","backupWallet","clearBanned","createMultiSig","createRawTransaction","debug","decodeRawTransaction","decodeScript","disconnectNode","dumpPrivKey","dumpWallet","encryptWallet","estimateFee","estimatePriority","estimateSmartFee","estimateSmartPriority","fundRawTransaction","generate","getAccount","getAccountAddress","getAddressMempool","getAddressUtxos","getAddressBalance","getAddressDeltas","getAddressTxids","getAddressesByAccount","getAddedNodeInfo","getBalance","getBestBlockHash","getBlock","getBlockchainInfo","getBlockCount","getBlockHashes","getBlockHash","getBlockHeader","getBlockHeaders","getBlockTemplate","getConnectionCount","getChainTips","getDifficulty","getGenerate","getGovernanceInfo","getGovernanceInfo","getInfo","getMemPoolInfo","getMiningInfo","getNewAddress","getNetTotals","getNetworkInfo","getNetworkHashps","getPeerInfo","getPoolInfo","getRawMemPool","getRawChangeAddress","getRawTransaction","getReceivedByAccount","getReceivedByAddress","getSpentInfo","getSuperBlockBudget","getTransaction","getTxOut","getTxOutProof","getTxOutSetInfo","getWalletInfo","help","importAddress","instantSendToAddress","gobject","invalidateBlock","importPrivKey","importPubKey","importElectrumWallet","importWallet","keyPoolRefill","listAccounts","listAddressGroupings","listBanned","listReceivedByAccount","listReceivedByAddress","listSinceBlock","listTransactions","listUnspent","listLockUnspent","lockUnspent","masternode","masternodeBroadcast","masternodeList","mnsync","move","ping","prioritiseTransaction","privateSend","reconsiderBlock","resendWalletTransactions","sendFrom","sendMany","sendRawTransaction","sendToAddress","sentinelPing","setAccount","setBan","setGenerate","setTxFee","setMockTime","spork","signMessage","signRawTransaction","stop","submitBlock","validateAddress","verifyMessage","verifyChain","verifyTxOutProof","voteRaw","walletLock","walletPassPhrase","walletPassphraseChange"],this.transactions=c(5e3),this.transactionLocks=c(5e3),this.blocks=c(50),this.retry=0,this.axios=o.create(e.rpc),this.axios.interceptors.response.use(function(e){return e&&e.data?e.data.result:null},function(e){return Promise.reject(e&&e.response?e.response.data:e)}),this.init(),e.ready&&this.ready(),e.listen&&e.socket&&this.listen()}d.prototype={init:function(){for(let e=0;e<this.apis.length;e++){const t=this.apis[e];this[t]=function(){var e=[].slice.call(arguments);return this.axios.request({data:{jsonrpc:"2.0",method:t.toLowerCase(),params:e,id:(new Date).getTime()},maxContentLength:5e7,timeout:6e4})}}},ready:function(){var e=this;e.retry+=1,i.info("Check %s Daemon Ready",e.id,new Date),this.getBestBlockHash().then(t=>{e.getBlock(t).then(t=>{e.emit("ready"),i.info("%s Daemon Ready",e.id)}).catch(t=>{setTimeout(function(){e.ready()},5e3*e.retry)})}).catch(t=>{setTimeout(function(){e.ready()},5e3*e.retry)})},listen:function(){var e=this;this.socket=r.socket("sub"),this.socket.on("connect",function(t,n){e.retry=0,i.info("%s ZMQ connected to:",e.id,n)}),this.socket.on("connect_delay",function(t,n){i.warn("%s ZMQ connection delay:",e.id,n)}),this.socket.on("disconnect",function(t,n){i.warn("%s ZMQ disconnect:",e.id,n)}),this.socket.on("monitor_error",function(t){e.retry+=1,i.error("Error in monitoring: %s, will restart monitoring in 5 seconds",t),setTimeout(function(){e.socket.monitor(500,0)},5e3*e.retry)}),this.socket.subscribe("hashblock"),this.socket.subscribe("rawtx"),this.socket.subscribe("rawtxlock"),this.socket.on("message",function(t,n){switch(t.toString("utf8")){case"rawtxlock":var o=n.toString("hex"),s=a.md5(o);e.transactionLocks.get(s)||(e.transactionLocks.set(s,!0),e.decodeRawTransaction(o).then(t=>{e.emit("txlock",t)}));break;case"rawtx":o=n.toString("hex"),s=a.md5(o);e.transactions.get(s)||(e.transactions.set(s,!0),e.emit("rawtx",n),e.decodeRawTransaction(o).then(t=>{e.emit("tx",t)}));break;case"hashblock":o=n.toString("hex");e.blocks.get(o)||(e.blocks.set(o,!0),e.emit("hashblock",o),e.getBlock(o).then(t=>{e.emit("block",t)}))}}),i.info("Start monitoring..."),this.socket.monitor(500,0),this.socket.connect(this.opts.socket)}},s.inherits(d,l),e.exports=d},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("loglevel")},function(e,t){e.exports=require("zeromq")},function(e,t){e.exports=require("lru-cache")},function(e,t){e.exports=require("mix-hash")}]);