UNPKG

ripplelib

Version:

A JavaScript API for interacting with Ripple in Node.js and the browser

2 lines 475 kB
var ripple=function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){var r=e[t];i(r.prototype).forEach(function(t){var e=/([A-Z]{1})[a-z]+/g;if(e.test(t)){var n=t.replace(e,function(t){return"_"+t.toLowerCase()});r.prototype[n]=r.prototype[t]}})}var i=r(28)["default"];e.Remote=r(1).Remote,e.Request=r(2).Request,e.Amount=r(3).Amount,e.Account=r(4).Account,e.Transaction=r(5).Transaction,e.Currency=r(6).Currency,e.Base=r(7).Base,e.UInt128=r(8).UInt128,e.UInt160=r(9).UInt160,e.UInt256=r(10).UInt256,e.Seed=r(11).Seed,e.KeyPair=r(12).KeyPair,e.Meta=r(13).Meta,e.SerializedObject=r(14).SerializedObject,e.RippleError=r(15).RippleError,e.Message=r(16).Message,e.binformat=r(17),e.utils=r(18),e.Server=r(19).Server,e.Ledger=r(20).Ledger,e.TransactionQueue=r(21).TransactionQueue,e.RangeSet=r(22).RangeSet,e.convertBase=r(23),e._test={Log:r(24),PathFind:r(25).PathFind,TransactionManager:r(26).TransactionManager},e.sjcl=r(18).sjcl,e.types=r(27),["Remote","Request","Transaction","Account","Server"].forEach(n)},function(t,e,r){"use strict";function n(){function t(t,e){if(f.contains(n.TRANSACTION_EVENTS,e))switch(t){case"add":1===++r._transaction_listeners&&r.requestSubscribe("transactions").request();break;case"remove":0===--r._transaction_listeners&&r.requestUnsubscribe("transactions").request()}}var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];s.call(this);var r=this;if(f.merge(this,f.defaults(e,n.DEFAULTS)),this.state="offline",this._server_fatal=!1,this._stand_alone=void 0,this._testnet=void 0,this._ledger_current_index=void 0,this._ledger_hash=void 0,this._ledger_time=void 0,this._connection_count=0,this._connected=!1,this._should_connect=!0,this._transaction_listeners=0,this._received_tx=new c({max:100}),this._cur_path_find=null,this.local_signing&&(this.local_sequence=!0,this.local_fee=!0),this._servers=[],this._primary_server=void 0,this.accounts={},this._accounts={},this._books={},this.secrets={},this.keyPairs={},this.ledgers={current:{account_root:{}}},"boolean"!=typeof this.trusted)throw new TypeError("trusted must be a boolean");if("boolean"!=typeof this.trace)throw new TypeError("trace must be a boolean");if("boolean"!=typeof this.allow_partial_history)throw new TypeError("allow_partial_history must be a boolean");if("number"!=typeof this.max_fee)throw new TypeError("max_fee must be a number");if("number"!=typeof this.max_attempts)throw new TypeError("max_attempts must be a number");if("number"!=typeof this.fee_cushion)throw new TypeError("fee_cushion must be a number");if("boolean"!=typeof this.local_signing)throw new TypeError("local_signing must be a boolean");if("boolean"!=typeof this.local_fee)throw new TypeError("local_fee must be a boolean");if("boolean"!=typeof this.local_sequence)throw new TypeError("local_sequence must be a boolean");if("boolean"!=typeof this.canonical_signing)throw new TypeError("canonical_signing must be a boolean");if("number"!=typeof this.submission_timeout)throw new TypeError("submission_timeout must be a number");if("number"!=typeof this.last_ledger_offset)throw new TypeError("last_ledger_offset must be a number");if("number"!=typeof this.orderbook_limit)throw new TypeError("orderbook_limit must be a number");if(!Array.isArray(this.servers))throw new TypeError("servers must be an array");this.setMaxListeners(this.max_listeners),this.servers.forEach(function(t){var e=r.addServer(t);e.setMaxListeners(r.max_listeners)}),this.on("newListener",function(e){t("add",e)}),this.on("removeListener",function(e){t("remove",e)})}function i(t){var e=void 0;f.isPlainObject(t)?e=f.merge({},t):(x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties"),e={src_account:arguments[0],dst_account:arguments[1],dst_amount:arguments[2],src_currencies:arguments[3]});var r=new w(this,e.src_account,e.dst_account,e.dst_amount,e.src_currencies);return this._cur_path_find&&this._cur_path_find.notify_superceded(),r.create(),this._cur_path_find=r,r}var o=r(28)["default"],s=r(40).EventEmitter,a=r(41),u=r(43),c=r(48),h=r(47),f=r(44),l=r(19).Server,p=r(2).Request,d=r(3).Amount,_=r(6).Currency,m=r(9).UInt160,g=r(10).UInt256,y=r(5).Transaction,v=r(4).Account,b=r(13).Meta,E=r(30).OrderBook,w=r(25).PathFind,A=r(14).SerializedObject,S=r(15).RippleError,T=r(18),O=r(31),x=r(24).internal.sub("remote"),L=r(11).Seed,R=r(12).KeyPair;a.inherits(n,s),n.DEFAULTS={trusted:!1,trace:!1,allow_partial_history:!0,local_sequence:!0,local_fee:!0,local_signing:!0,canonical_signing:!0,fee_cushion:1.2,max_fee:1e6,max_attempts:10,submission_timeout:2e4,last_ledger_offset:3,orderbook_limit:100,servers:[],max_listeners:0},n.TRANSACTION_EVENTS=["transaction","transaction_all"],n.flags={account_root:{PasswordSpent:65536,RequireDestTag:131072,RequireAuth:262144,DisallowXRP:524288,DisableMaster:1048576,DefaultRipple:8388608,NoFreeze:2097152,GlobalFreeze:4194304},offer:{Passive:65536,Sell:131072},state:{LowReserve:65536,HighReserve:131072,LowAuth:262144,HighAuth:524288,LowNoRipple:1048576,HighNoRipple:2097152,LowFreeze:4194304,HighFreeze:8388608}},n.isValidMessage=function(t){return"object"==typeof t&&"string"==typeof t.type},n.isValidLedgerData=function(t){return"object"==typeof t&&"number"==typeof t.fee_base&&"number"==typeof t.fee_ref&&"string"==typeof t.ledger_hash&&"number"==typeof t.ledger_index&&"number"==typeof t.ledger_time&&"number"==typeof t.reserve_base&&"number"==typeof t.reserve_inc},n.isValidLoadStatus=function(t){return"number"==typeof t.load_base&&"number"==typeof t.load_factor},n.isValidated=function(t){return t&&"object"==typeof t&&t.validated===!0},n.prototype._setState=function(t){if(this.state!==t)switch(this.trace&&x.info("set_state:",t),this.state=t,this.emit("state",t),t){case"online":this._online_state="open",this._connected=!0,this.emit("connect"),this.emit("connected");break;case"offline":this._online_state="closed",this._connected=!1,this.emit("disconnect"),this.emit("disconnected")}},n.prototype.setServerFatal=function(){this._server_fatal=!0},n.prototype.setTrace=function(t){return this.trace=void 0===t||t,this},n.prototype._trace=function(){this.trace&&x.info.apply(x,arguments)},n.prototype.setSecret=function(t,e,r){this.secrets[t]=e,this.setKey(t,this.generateKey(e,r))},n.prototype.generateKey=n.prototype.generateKeyPair=function(t,e){try{return L.from_json(t).get_key(e)}catch(r){throw new Error("Invalid Secret!")}},n.prototype.setKey=n.prototype.setKeyPair=function(t,e){if(e=R.from_json(e),!e.is_valid())throw new Error("Invalid private/keyPair!");this.keyPairs[t]=e},n.prototype.getKey=n.prototype.getKeyPair=function(t){var e=this.keyPairs[t];return e||(e=this.keyPairs[t]=this.generateKey(this.secrets[t])),e},n.prototype.addServer=function(t){function e(t){i._handleMessage(t,o)}function r(){i._connection_count+=1,t.primary&&i._setPrimaryServer(o),1===i._connection_count&&i._setState("online"),i._connection_count===i._servers.length&&i.emit("ready")}function n(){i._connection_count--,0===i._connection_count&&i._setState("offline")}var i=this,o=new l(this,t);return o.on("message",e),o.on("connect",r),o.on("disconnect",n),this._servers.push(o),o},n.prototype.reconnect=function(){this._should_connect&&(x.info("reconnecting"),this._servers.forEach(function(t){t.reconnect()}))},n.prototype.connect=function(t){if(!this._servers.length)throw new Error("No servers available.");return"function"!=typeof t&&(t=function(){}),this.isConnected()?(t(),this):(this.once("connect",t),this._should_connect=!0,this._servers.forEach(function(t){t.connect()}),this)},n.prototype.disconnect=function(t){if(!this._servers.length)throw new Error("No servers available, not disconnecting");var e=f.isFunction(t)?t:function(){};return this._should_connect=!1,this.isConnected()?(this.once("disconnect",e),this._servers.forEach(function(t){t.disconnect()}),this._set_state("offline"),this):(e(),this)},n.prototype._handleMessage=function(t,e){if(!n.isValidMessage(t)){var r=new S("remoteUnexpected","Unexpected response from remote: "+JSON.stringify(t));return this.emit("error",r),void x.error(r)}switch(t.type){case"ledgerClosed":this._handleLedgerClosed(t,e);break;case"serverStatus":this._handleServerStatus(t,e);break;case"transaction":this._handleTransaction(t,e);break;case"path_find":this._handlePathFind(t,e);break;default:this.trace&&x.info(t.type+": ",t)}},n.prototype.getLedgerSequence=function(){if(!this._ledger_current_index)throw new Error("Ledger sequence has not yet been initialized");return this._ledger_current_index},n.prototype._handleLedgerClosed=function(t,e){var r=this;if(n.isValidLedgerData(t)){var i=t.ledger_index>=this._ledger_current_index;(isNaN(this._ledger_current_index)||i)&&(this._ledger_time=t.ledger_time,this._ledger_hash=t.ledger_hash,this._ledger_current_index=t.ledger_index+1,this.isConnected()?this.emit("ledger_closed",t,e):this.once("connect",function(){r.emit("ledger_closed",t,e)}))}},n.prototype._handleServerStatus=function(t,e){this.emit("server_status",t,e)},n.prototype._handleTransaction=function(t,e){var r=t.transaction.hash;if(!this._received_tx.get(r)){t.validated&&this._received_tx.set(r,!0),this.trace&&x.info("tx:",t);var n=t.meta||t.metadata;n?(t.mmeta=new b(n),t.mmeta.getAffectedAccounts().forEach(function(e){this._accounts[e]&&this._accounts[e].notify(t)},this),t.mmeta.getAffectedBooks().forEach(function(e){this._books[e]&&this._books[e].notify(t)},this)):["Account","Destination"].forEach(function(e){this._accounts[t.transaction[e]]&&this._accounts[t.transaction[e]].notify(t)},this),this.emit("transaction",t,e),this.emit("transaction_all",t,e)}},n.prototype._handlePathFind=function(t,e){this._cur_path_find&&this._cur_path_find.notify_update(t),this.emit("path_find_all",t,e)},n.prototype.getLedgerHash=function(){return this._ledger_hash},n.prototype._setPrimaryServer=n.prototype.setPrimaryServer=function(t){this._primary_server&&(this._primary_server._primary=!1),this._primary_server=t,this._primary_server._primary=!0},n.prototype.isConnected=function(){return this._connected},n.prototype.getConnectedServers=function(){return this._servers.filter(function(t){return t.isConnected()})},n.prototype._getServer=n.prototype.getServer=function(){if(this._primary_server&&this._primary_server.isConnected())return this._primary_server;if(!this._servers.length)return null;var t=this.getConnectedServers();if(0===t.length||!t[0])return null;for(var e=t[0],r=e._score+e._fee,n=1;n<t.length;n++){var i=t[n],o=i._score+i._fee;r>o&&(e=i,r=o)}return e},n.prototype.request=function(t){var e=t;if("string"==typeof e){if(/^request_/.test(e)||(e="request_"+e),"function"==typeof this[e]){var r=Array.prototype.slice.call(arguments,1);return this[e].apply(this,r)}throw new Error("Command does not exist: "+e)}if(!(e instanceof p))throw new Error("Argument is not a Request");if(!this._servers.length)return e.emit("error",new Error("No servers available"));if(!this.isConnected())return this.once("connect",this.request.bind(this,e));if(null===e.server)return e.emit("error",new Error("Server does not exist"));var n=e.server||this.getServer();n?n._request(e):e.emit("error",new Error("No servers available"))},n.prototype.ping=n.prototype.requestPing=function(t,e){var r=new p(this,"ping"),n=e;switch(typeof t){case"function":n=t;break;case"string":r.setServer(t)}var i=Date.now();return r.once("success",function(){r.emit("pong",Date.now()-i)}),r.callback(n,"pong"),r},n.prototype.requestServerInfo=function(t){return new p(this,"server_info").callback(t)},n.prototype.requestLedger=function(t,e){var r=new p(this,"ledger"),n=e;switch(typeof t){case"undefined":break;case"function":n=t;break;case"object":if(!t)break;o(t).forEach(function(e){switch(e){case"full":case"expand":case"transactions":case"accounts":r.message[e]=t[e]?!0:!1;break;case"ledger":r.selectLedger(t.ledger);break;case"ledger_index":case"ledger_hash":r.message[e]=t[e];break;case"closed":case"current":case"validated":r.message.ledger_index=e}},t);break;default:r.selectLedger(t)}return r.callback(n),r},n.prototype.requestLedgerClosed=n.prototype.requestLedgerHash=function(t){return new p(this,"ledger_closed").callback(t)},n.prototype.requestLedgerHeader=function(t){return new p(this,"ledger_header").callback(t)},n.prototype.requestLedgerCurrent=function(t){return new p(this,"ledger_current").callback(t)},n.prototype.requestLedgerData=function(t,e){var r=new p(this,"ledger_data");return r.message.binary=t.binary!==!1,r.selectLedger(t.ledger),r.message.limit=t.limit,r.once("success",function(e){function i(t,e){h.setImmediate(function(){e(null,n.parseBinaryLedgerData(t))})}function o(t,n){t?r.emit("error",t):(e.state=n,r.emit("state",e))}return t.binary===!1?void r.emit("state",e):void h.mapSeries(e.state,i,o)}),r.callback(e,"state"),r},n.prototype.requestLedgerEntry=function(t,e){var r=this,n=new p(this,"ledger_entry"),i=f.isFunction(t)?t:e;return"account_root"===t&&(n.request_default=n.request,n.request=function(){var e=!0;if(!r._ledger_hash&&"account_root"===t){var i=r.ledgers.current.account_root;i||(i=r.ledgers.current.account_root={});var o=r.ledgers.current.account_root[n.message.account_root];if(o)n.emit("success",{node:o}),e=!1;else switch(t){case"account_root":n.once("success",function(t){r.ledgers.current.account_root[t.node.Account]=t.node})}}e&&n.request_default()}),n.callback(i),n},n.prototype.requestSubscribe=function(t,e){var r=new p(this,"subscribe");return t&&(r.message.streams=Array.isArray(t)?t:[t]),r.callback(e),r},n.prototype.requestUnsubscribe=function(t,e){var r=new p(this,"unsubscribe");return t&&(r.message.streams=Array.isArray(t)?t:[t]),r.callback(e),r},n.prototype.requestTransactionEntry=function(t,e){var r=void 0,n=e;if(f.isPlainObject(t))r=f.merge({ledger:t.ledger_index||t.ledger_hash},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var i=Array.prototype.slice.call(arguments);f.isFunction(f.last(i))&&(n=i.pop()),r={hash:i.shift(),ledger:i.shift()}}var o=new p(this,"transaction_entry");switch(o.txHash(r.hash),typeof r.ledger){case"string":case"number":o.selectLedger(r.ledger);break;case"undefined":o.ledgerIndex("validated");break;default:throw new Error("ledger must be a ledger index or hash")}return o.callback(n),o},n.prototype.requestTransaction=n.prototype.requestTx=function(t,e){var r=void 0,i=e;if(f.isPlainObject(t))r=f.merge({},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var o=Array.prototype.slice.call(arguments);f.isFunction(f.last(o))&&(i=o.pop()),r={hash:o.shift(),binary:o.shift()}}var s=new p(this,"tx");return s.message.binary=r.binary!==!1,s.message.transaction=r.hash,s.once("success",function(t){return r.binary===!1?void s.emit("transaction",t):void s.emit("transaction",n.parseBinaryTransaction(t))}),s.callback(i,"transaction"),s},n.accountRequest=function(t,e,r){var n=void 0,i=r;if(f.isPlainObject(e))n=f.merge({},e);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var o=Array.prototype.slice.call(arguments);f.isFunction(f.last(o))&&(i=o.pop()),n={account:o.shift(),peer:o.shift(),ledger:o.shift(),limit:o.shift(),marker:o.shift()}}var s=n,a=s.account,u=s.ledger,c=s.peer,h=s.limit,l=s.marker;if(l&&!(Number(u)>0||g.is_valid(u)))throw new Error("A ledger_index or ledger_hash must be provided when using a marker");var d=new p(this,t);return a&&(a=m.json_rewrite(a),d.message.account=a),d.selectLedger(u),m.is_valid(c)&&(d.message.peer=m.json_rewrite(c)),isNaN(h)||(h=Number(h),h>1e9&&(h=1e9),0>h&&(h=0),d.message.limit=h),l&&(d.message.marker=l),["strict","queue","signer_lists"].forEach(function(t){s.hasOwnProperty(t)&&(d.message[t]=s[t])}),d.callback(i),d},n.prototype.requestAccountInfo=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var i=["account_info"].concat(e);return n.accountRequest.apply(this,i)},n.prototype.requestAccountCurrencies=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var i=["account_currencies"].concat(e);return n.accountRequest.apply(this,i)},n.prototype.requestAccountLines=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var i=["account_lines"].concat(e);return n.accountRequest.apply(this,i)},n.prototype.requestAccountOffers=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var i=["account_offers"].concat(e);return n.accountRequest.apply(this,i)},n.prototype.requestAccountTransactions=n.prototype.requestAccountTx=function(t,e){var r=new p(this,"account_tx");return t.binary=t.binary!==!1,void 0!==t.min_ledger&&(t.ledger_index_min=t.min_ledger),void 0!==t.max_ledger&&(t.ledger_index_max=t.max_ledger),t.binary&&void 0===t.parseBinary&&(t.parseBinary=!0),o(t).forEach(function(t){switch(t){case"account":case"ledger_index_min":case"ledger_index_max":case"binary":case"count":case"descending":case"offset":case"limit":case"forward":case"marker":r.message[t]=this[t]}},t),r.once("success",function(e){function i(t,e){h.setImmediate(function(){e(null,n.parseBinaryAccountTransaction(t))})}function o(t,n){t?r.emit("error",t):(e.transactions=n,r.emit("transactions",e))}return t.parseBinary?void h.mapSeries(e.transactions,i,o):void r.emit("transactions",e)}),r.callback(e,"transactions"),r},n.parseBinaryAccountTransaction=function(t){var e=new A(t.tx_blob),r=e.to_json(),n=new A(t.meta).to_json(),i={validated:t.validated};if(i.meta=n,i.tx=r,i.tx.hash=e.hash(O.HASH_TX_ID).to_hex(),i.tx.ledger_index=t.ledger_index,i.tx.inLedger=t.ledger_index,"object"==typeof n.DeliveredAmount)i.meta.delivered_amount=n.DeliveredAmount;else switch(typeof r.Amount){case"string":case"object":i.meta.delivered_amount=r.Amount}return i},n.parseBinaryTransaction=function(t){var e=new A(t.tx).to_json(),r=new A(t.meta).to_json(),n=e;switch(n.date=t.date,n.hash=t.hash,n.inLedger=t.inLedger,n.ledger_index=t.ledger_index,n.meta=r,n.validated=t.validated,typeof r.DeliveredAmount){case"string":case"object":n.meta.delivered_amount=r.DeliveredAmount;break;default:switch(typeof e.Amount){case"string":case"object":n.meta.delivered_amount=e.Amount}}return n},n.parseBinaryLedgerData=function(t){var e=new A(t.data).to_json();return e.index=t.index,e},n.prototype.requestTransactionHistory=n.prototype.requestTxHistory=function(t,e){var r=new p(this,"tx_history"),n=t,i=e;return f.isPlainObject(n)?n=n.start:x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties"),r.message.start=n,r.callback(i),r},n.prototype.requestBookOffers=function(t,e){var r=void 0,n=e;if(t.gets||t.taker_gets)r=f.merge({pays:t.taker_pays,gets:t.taker_gets},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var i=Array.prototype.slice.call(arguments);f.isFunction(f.last(i))&&(n=i.pop()),r={gets:i.shift(),pays:i.shift(),taker:i.shift(),ledger:i.shift(),limit:i.shift()}}var o=r,s=o.gets,a=o.pays,u=o.taker,c=o.ledger,h=o.limit,l=new p(this,"book_offers");return l.message.taker_gets={currency:_.json_rewrite(s.currency,{force_hex:!0})},_.from_json(l.message.taker_gets.currency).is_native()||(l.message.taker_gets.issuer=m.json_rewrite(s.issuer)),l.message.taker_pays={currency:_.json_rewrite(a.currency,{force_hex:!0})},_.from_json(l.message.taker_pays.currency).is_native()||(l.message.taker_pays.issuer=m.json_rewrite(a.issuer)),l.message.taker=u?u:m.ACCOUNT_ONE,l.selectLedger(c),isNaN(h)?l.message.limit=this.orderbook_limit:(h=Number(h),h>1e9&&(h=1e9),0>h&&(h=0),l.message.limit=h),l.callback(n),l},n.prototype.requestWalletAccounts=function(t,e){T.assert(this.trusted);var r=void 0,n=e;f.isPlainObject(t)?r=f.merge({},t):(x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties"),r={seed:arguments[0]});var i=new p(this,"wallet_accounts");return i.message.seed=r.seed,i.callback(n),i},n.prototype.requestSign=function(t,e){T.assert(this.trusted);var r=void 0,n=e;f.isPlainObject(t)?r=f.merge({},t):(x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties"),r={secret:arguments[0],tx_json:arguments[1]},n=arguments[2]);var i=new p(this,"sign");return i.message.secret=r.secret,i.message.tx_json=r.tx_json,i.callback(n),i},n.prototype.requestSubmit=function(t){return new p(this,"submit").callback(t)},n.prototype._serverPrepareSubscribe=function(t,e){function r(e){n._stand_alone=!!e.stand_alone,n._testnet=!!e.testnet,n._handleLedgerClosed(e,t),n.emit("subscribed")}var n=this,i=["ledger","server"],o=f.isFunction(t)?t:e;this._transaction_listeners&&i.push("transactions");var s=this.requestSubscribe(i);return s.on("error",function(t){n.trace&&x.info("Initial server subscribe failed",t)}),s.once("success",r),n.emit("prepare_subscribe",s),s.callback(o,"subscribed"),s},n.prototype.ledgerAccept=n.prototype.requestLedgerAccept=function(t){var e=new p(this,"ledger_accept");return this._stand_alone?(this.once("ledger_closed",function(t){e.emit("ledger_closed",t)}),e.callback(t,"ledger_closed"),e.request(),e):void this.emit("error",new S("notStandAlone"))},n.accountRootRequest=function(t,e,r,n){var i=void 0,o=n;if(f.isPlainObject(r))i=f.merge({},r);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var s=Array.prototype.slice.call(arguments);f.isFunction(f.last(s))&&(o=s.pop()),i={account:s.shift(),ledger:s.shift()}}var a=this.requestLedgerEntry("account_root");return a.accountRoot(i.account),a.selectLedger(i.ledger),a.once("success",function(r){a.emit(t,e(r))}),a.callback(o,t),a},n.prototype.requestAccountBalance=function(){function t(t){return d.from_json(t.node.Balance)}for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];var o=["account_balance",t].concat(r);return n.accountRootRequest.apply(this,o)},n.prototype.requestAccountFlags=function(){function t(t){return t.node.Flags}for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];var o=["account_flags",t].concat(r);return n.accountRootRequest.apply(this,o)},n.prototype.requestOwnerCount=function(){function t(t){return t.node.OwnerCount}for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];var o=["owner_count",t].concat(r);return n.accountRootRequest.apply(this,o)},n.prototype.getAccount=function(t){return this._accounts[m.json_rewrite(t)]},n.prototype.addAccount=function(t){var e=new v(this,t);return e.isValid()&&(this._accounts[t]=e),e},n.prototype.account=n.prototype.findAccount=function(t){var e=this.getAccount(t);return e?e:this.addAccount(t)},n.prototype.pathFind=n.prototype.createPathFind=i,n.prepareTrade=function(t,e){var r=_.from_json(t).is_native()?"":"/"+e;return t+r},n.prototype.book=n.prototype.createOrderBook=function(t){var e=void 0;1===arguments.length?e=f.merge({},t):(x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties"),e={currency_gets:arguments[0],issuer_gets:arguments[1],currency_pays:arguments[2],issuer_pays:arguments[3]});var r=n.prepareTrade(e.currency_gets,e.issuer_gets),i=n.prepareTrade(e.currency_pays,e.issuer_pays),o=r+":"+i;if(this._books.hasOwnProperty(o))return this._books[o];var s=new E(this,e.currency_gets,e.issuer_gets,e.currency_pays,e.issuer_pays,o);return s.is_valid()&&(this._books[o]=s),s},n.prototype.accountSeq=n.prototype.getAccountSequence=function(t,e){var r=m.json_rewrite(t),n=this.accounts[r];if(!n)return 0/0;var i=n.seq,o={ADVANCE:1,REWIND:-1}[e.toUpperCase()]||0;return n.seq+=o,i},n.prototype.setAccountSequence=n.prototype.setAccountSeq=function(t,e){var r=m.json_rewrite(t);this.accounts.hasOwnProperty(r)||(this.accounts[r]={}),this.accounts[r].seq=e},n.prototype.accountSeqCache=function(t,e){function r(t){delete a.caching_seq_request;var e=t.node.Sequence;a.seq=e,u.emit("success_cache",t)}function n(t){delete a.caching_seq_request,u.emit("error_cache",t)}var i=void 0,o=e;if(f.isPlainObject(t))i=f.merge({},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var s=Array.prototype.slice.call(arguments);f.isFunction(f.last(s))&&(o=s.pop()),i={account:s.shift(),ledger:s.shift()}}this.accounts.hasOwnProperty(i.account)||(this.accounts[i.account]={});var a=this.accounts[i.account],u=a.caching_seq_request;return u||(u=this.requestLedgerEntry("account_root"),u.accountRoot(i.account),f.isUndefined(i.ledger)||u.selectLedger(i.ledger),u.once("success",r),u.once("error",n),a.caching_seq_request=u),u.callback(o,"success_cache","error_cache"),u},n.prototype.dirtyAccountRoot=function(t){var e=m.json_rewrite(t);delete this.ledgers.current.account_root[e]},n.prototype.requestOffer=function(t,e){var r=this.requestLedgerEntry("offer");return t.account&&t.sequence?r.offerId(t.account,t.sequence):t.index&&r.offerIndex(t.index),r.ledgerSelect(t.ledger),r.once("success",function(t){r.emit("offer",t)}),r.callback(e,"offer"),r},n.prototype.requestRippleBalance=function(t,e){function r(t){var e=t.node,r=d.from_json(e.LowLimit),o=d.from_json(e.HighLimit),s=e.Flags,u=n.flags.state,c=d.from_json(e.Balance),h=m.from_json(i.account).equals(o.issuer());a.emit("ripple_state",{account_balance:(h?c.negate():c.clone()).parse_issuer(i.issuer),peer_balance:(h?c.clone():c.negate()).parse_issuer(i.account),account_limit:(h?o:r).clone().parse_issuer(i.issuer),peer_limit:(h?r:o).clone().parse_issuer(i.account),account_quality_in:h?e.HighQualityIn:e.LowQualityIn,peer_quality_in:h?e.LowQualityIn:e.HighQualityIn,account_quality_out:h?e.HighQualityOut:e.LowQualityOut,peer_quality_out:h?e.LowQualityOut:e.HighQualityOut,account_no_ripple:Boolean(h?u.HighNoRipple&s:u.LowNoRipple&s),peer_no_ripple:Boolean(h?u.LowNoRipple&s:u.HighNoRipple&s),account_freeze:Boolean(h?u.HighFreeze&s:u.LowFreeze&s),peer_freeze:Boolean(h?u.LowFreeze&s:u.HighFreeze&s),account_authorized:Boolean(h?u.HighAuth&s:u.LowAuth&s),peer_authorized:Boolean(h?u.LowAuth&s:u.HighAuth&s)})}var i=void 0,o=e;if(f.isPlainObject(t))i=f.merge({},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var s=Array.prototype.slice.call(arguments);f.isFunction(f.last(s))&&(o=s.pop()),i={account:s.shift(),issuer:s.shift(),currency:s.shift(),ledger:s.shift()}}var a=this.requestLedgerEntry("ripple_state");return a.rippleState(i.account,i.issuer,i.currency),f.isUndefined(i.ledger)||a.selectLedger(i.ledger),a.once("success",r),a.callback(o,"ripple_state"),a},n.prepareCurrency=n.prepareCurrencies=function(t){var e={};return t.hasOwnProperty("issuer")&&(e.issuer=m.json_rewrite(t.issuer)),t.hasOwnProperty("currency")&&(e.currency=_.json_rewrite(t.currency,{force_hex:!0})),e},n.prototype.requestRipplePathFind=function(t,e){var r=void 0,i=e;if(f.isPlainObject(t))r=f.merge({source_account:t.src_account,destination_account:t.dst_account,destination_amount:t.dst_amount,source_currencies:t.src_currencies},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var o=Array.prototype.slice.call(arguments);f.isFunction(f.last(o))&&(i=o.pop()),r={source_account:o.shift(),destination_account:o.shift(),destination_amount:o.shift(),source_currencies:o.shift()}}var s=new p(this,"ripple_path_find");return s.message.source_account=m.json_rewrite(r.source_account),s.message.destination_account=m.json_rewrite(r.destination_account),s.message.destination_amount=d.json_rewrite(r.destination_amount),Array.isArray(r.source_currencies)&&(s.message.source_currencies=r.source_currencies.map(n.prepareCurrency)),s.callback(i),s},n.prototype.requestPathFindCreate=function(t,e){var r=void 0,i=e;if(f.isPlainObject(t))r=f.merge({source_account:t.src_account,destination_account:t.dst_account,destination_amount:t.dst_amount,source_currencies:t.src_currencies},t);else{x.warn("DEPRECATED: First argument to request constructor should be an object containing request properties");var o=Array.prototype.slice.call(arguments);f.isFunction(f.last(o))&&(i=o.pop()),r={source_account:o.shift(),destination_account:o.shift(),destination_amount:o.shift(),source_currencies:o.shift()}}var s=new p(this,"path_find");return s.message.subcommand="create",s.message.source_account=m.json_rewrite(r.source_account),s.message.destination_account=m.json_rewrite(r.destination_account),s.message.destination_amount=d.json_rewrite(r.destination_amount),Array.isArray(r.source_currencies)&&(s.message.source_currencies=r.source_currencies.map(n.prepareCurrency)),s.callback(i),s},n.prototype.requestPathFindClose=function(t){var e=new p(this,"path_find");return e.message.subcommand="close",e.callback(t),e},n.prototype.requestUnlList=function(t){return new p(this,"unl_list").callback(t)},n.prototype.requestUnlAdd=function(t,e,r){var n=new p(this,"unl_add");return n.message.node=t,e&&(n.message.comment=void 0),n.callback(r),n},n.prototype.requestUnlDelete=function(t,e){var r=new p(this,"unl_delete");return r.message.node=t,r.callback(e),r},n.prototype.requestPeers=function(t){return new p(this,"peers").callback(t)},n.prototype.requestConnect=function(t,e,r){var n=new p(this,"connect");return n.message.ip=t,e&&(n.message.port=e),n.callback(r),n},n.prototype.requestGatewayBalances=function(t,e){u(f.isObject(t),"Options missing"),u(t.account,"Account missing");var r=new p(this,"gateway_balances");return r.message.account=m.json_rewrite(t.account),f.isUndefined(t.hotwallet)||(r.message.hotwallet=t.hotwallet),f.isUndefined(t.strict)||(r.message.strict=t.strict),f.isUndefined(t.ledger)||r.selectLedger(t.ledger),r.callback(e),r},n.prototype.transaction=n.prototype.createTransaction=function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=new y(this);if(0===arguments.length)return r;u.strictEqual(typeof t,"string","TransactionType must be a string");var n={Payment:r.payment,AccountSet:r.accountSet,TrustSet:r.trustSet,OfferCreate:r.offerCreate,OfferCancel:r.offerCancel,SetRegularkey:r.setRegularKey},i=n[t];if(!i)throw new Error("TransactionType must be a valid transaction type");return i.call(r,e)},n.prototype.feeTx=function(t){var e=this.getServer();if(!e)throw new Error("No connected servers");return e._feeTx(t)},n.prototype.feeTxUnit=function(){var t=this.getServer();if(!t)throw new Error("No connected servers");return t._feeTxUnit()},n.prototype.reserve=function(t){var e=this.getServer();if(!e)throw new Error("No connected servers");return e._reserve(t)},e.Remote=n},function(t,e,r){"use strict";function n(t,e){i.call(this),this.remote=t,this.requested=!1,this.reconnectTimeout=3e3,this.successEvent="success",this.errorEvent="error",this.message={command:e,id:void 0}}var i=r(40).EventEmitter,o=r(41),s=r(47),a=r(9).UInt160,u=r(6).Currency,c=r(15).RippleError;o.inherits(n,i),n.prototype.request=function(t,e){return this.emit("before"),this.callback(e),this.requested?this:(this.requested=!0,this.on("error",function(){}),this.emit("request",this.remote),Array.isArray(t)?t.forEach(function(t){this.setServer(t),this.remote.request(this)},this):this.remote.request(this),this)},n.prototype.filter=n.prototype.addFilter=n.prototype.broadcast=function(){function t(e,s){function a(){clearTimeout(o[u]),o[u]=null,t(e,s)}if(e.isConnected())return n.on("proposed",function(t,n){n===e&&(i=t,s(r(t)))}),e._request(n);var u=e.getServerID();o[u]=setTimeout(function(){e.removeListener("connect",a),s(!1)},n.reconnectTimeout),e.once("connect",a)}function e(t){a.call(n,t?"success":"error",i)}var r=arguments.length<=0||void 0===arguments[0]?Boolean:arguments[0],n=this;if(!this.requested)return this.once("before",function(){n.requested=!0,n.broadcast(r)}),this;var i=new Error("No servers available"),o={},a=this.emit; this.emit=function(t,e,r){switch(t){case"success":case"error":a.call(n,"proposed",e,r);break;default:a.apply(n,arguments)}};var u=this.remote._servers.filter(function(t){return!(!t.isConnected()&&!t._shouldConnect||n.message.hasOwnProperty("ledger_index")&&!t.hasLedger(n.message.ledger_index)||n.message.hasOwnProperty("ledger_index_min")&&-1!==n.message.ledger_index_min&&!t.hasLedger(n.message.ledger_index_min)||n.message.hasOwnProperty("ledger_index_max")&&-1!==n.message.ledger_index_max&&!t.hasLedger(n.message.ledger_index_max))});return s.some(u,t,e),this},n.prototype.cancel=function(){return this.removeAllListeners(),this.on("error",function(){}),this},n.prototype.setCallback=function(t){return"function"==typeof t&&this.callback(t),this},n.prototype.setReconnectTimeout=function(t){return"number"!=typeof t||isNaN(t)||(this.reconnectTimeout=t),this},n.prototype.callback=function(t,e,r){function n(e){s||(s=!0,t.call(o,null,e))}function i(e){s||(s=!0,e instanceof c?t.call(o,e):t.call(o,new c(e)))}var o=this;if("function"!=typeof t)return this;"string"==typeof e&&(this.successEvent=e),"string"==typeof r&&(this.errorEvent=r);var s=!1;return this.once(this.successEvent,n),this.once(this.errorEvent,i),this.request(),this},n.prototype.timeout=function(t,e){function r(){n.timeout(t,e)}var n=this;if(!this.requested)return this.once("request",r);var i=this.emit,o=!1,s=setTimeout(function(){o=!0,"function"==typeof e&&e(),i.call(n,"timeout"),n.cancel()},t);return this.emit=function(){o||(clearTimeout(s),i.apply(n,arguments))},this},n.prototype.setServer=function(t){var e=null;switch(typeof t){case"object":e=t;break;case"string":for(var r=this.remote._servers,n=0,i=void 0;i=r[n];n++)if(i._url===t){e=i;break}}return this.server=e,this},n.prototype.buildPath=function(t){if(this.remote.local_signing)throw new Error("`build_path` is completely ignored when doing local signing as `Paths` is a component of the signed blob. The `tx_blob` is signed,sealed and delivered, and the txn unmodified after");return t?this.message.build_path=!0:delete this.message.build_path,this},n.prototype.ledgerChoose=function(t){return t?this.message.ledger_index=this.remote._ledger_current_index:this.message.ledger_hash=this.remote._ledger_hash,this},n.prototype.ledgerHash=function(t){return this.message.ledger_hash=t,this},n.prototype.ledgerIndex=function(t){return this.message.ledger_index=t,this},n.prototype.selectLedger=n.prototype.ledgerSelect=function(t){switch(t){case"current":case"closed":case"validated":this.message.ledger_index=t;break;default:Number(t)&&isFinite(Number(t))?this.message.ledger_index=Number(t):/^[A-F0-9]{64}$/.test(t)&&(this.message.ledger_hash=t)}return this},n.prototype.accountRoot=function(t){return this.message.account_root=a.json_rewrite(t),this},n.prototype.index=function(t){return this.message.index=t,this},n.prototype.offerId=function(t,e){return this.message.offer={account:a.json_rewrite(t),seq:e},this},n.prototype.offerIndex=function(t){return this.message.offer=t,this},n.prototype.secret=function(t){return t&&(this.message.secret=t),this},n.prototype.txHash=function(t){return this.message.tx_hash=t,this},n.prototype.txJson=function(t){return this.message.tx_json=t,this},n.prototype.txBlob=function(t){return this.message.tx_blob=t,this},n.prototype.rippleState=function(t,e,r){return this.message.ripple_state={currency:r,accounts:[a.json_rewrite(t),a.json_rewrite(e)]},this},n.prototype.setAccounts=n.prototype.accounts=function(t,e){var r=Array.isArray(t)?t:[t],n=r.map(function(t){return a.json_rewrite(t)});return e?this.message.accounts_proposed=n:this.message.accounts=n,this},n.prototype.addAccount=function(t,e){if(Array.isArray(t))return t.forEach(this.addAccount,this),this;var r=a.json_rewrite(t),n=e===!0?"accounts_proposed":"accounts";return this.message[n]=(this.message[n]||[]).concat(r),this},n.prototype.setAccountsProposed=n.prototype.rtAccounts=n.prototype.accountsProposed=function(t){return this.accounts(t,!0)},n.prototype.addAccountProposed=function(t){return Array.isArray(t)?(t.forEach(this.addAccountProposed,this),this):this.addAccount(t,!0)},n.prototype.setBooks=n.prototype.books=function(t,e){this.message.books=[];for(var r=0,n=t.length;n>r;r++){var i=t[r];this.addBook(i,e)}return this},n.prototype.addBook=function(t,e){function r(e){if(!t[e])throw new Error("Missing "+e);var r=n[e]={currency:u.json_rewrite(t[e].currency,{force_hex:!0})};u.from_json(r.currency).is_native()||(r.issuer=a.json_rewrite(t[e].issuer))}if(Array.isArray(t))return t.forEach(this.addBook,this),this;var n={};return["taker_gets","taker_pays"].forEach(r),"boolean"!=typeof e?n.snapshot=!0:e?n.snapshot=!0:delete n.snapshot,t.both&&(n.both=!0),this.message.books=(this.message.books||[]).concat(n),this},n.prototype.addStream=function(t,e){if(Array.isArray(e))switch(t){case"accounts":this.addAccount(e);break;case"accounts_proposed":this.addAccountProposed(e);break;case"books":this.addBook(e)}else if(arguments.length>1){for(var r in arguments)this.addStream(arguments[r]);return this}return Array.isArray(this.message.streams)||(this.message.streams=[]),-1===this.message.streams.indexOf(t)&&this.message.streams.push(t),this},e.Request=n},function(t,e,r){"use strict";function n(t){return new l(t).toPower(-1)}function i(){this._value=new l(0/0),this._is_native=!0,this._currency=new h,this._issuer=new u}var o=r(43),s=r(42),a=r(18),u=r(9).UInt160,c=r(11).Seed,h=r(6).Currency,f=r(49),l=f.another({ROUNDING_MODE:f.ROUND_HALF_UP,DECIMAL_PLACES:40});i.strict_mode=!0;var p={currency_xns:0,currency_one:1,xns_precision:6,bi_5:new l(5),bi_7:new l(7),bi_10:new l(10),bi_1e14:new l(1e14),bi_1e16:new l(1e16),bi_1e17:new l(1e17),bi_1e32:new l(1e32),bi_man_max_value:new l("9999999999999999"),bi_man_min_value:new l(1e15),bi_xns_max:new l(1e17),bi_xns_min:new l(-1e17),bi_xns_unit:new l(1e6),cMinOffset:-96,cMaxOffset:80,max_value:"9999999999999999e80",min_value:"-1000000000000000e-96"},d=new l(1e11),_=new l(p.max_value),m=new l(p.min_value).abs();s(i,p),e.consts=p,i.text_full_rewrite=function(t){return i.from_json(t).to_text_full()},i.json_rewrite=function(t){return i.from_json(t).to_json()},i.from_number=function(t){return(new i).parse_number(t)},i.from_json=function(t){return(new i).parse_json(t)},i.from_quality=function(t,e,r,n){return(new i).parse_quality(t,e,r,n)},i.from_human=function(t,e){return(new i).parse_human(t,e)},i.is_valid=function(t){return i.from_json(t).is_valid()},i.is_valid_full=function(t){return i.from_json(t).is_valid_full()},i.NaN=function(){var t=new i;return t._value=new l(0/0),t},i.prototype._set_value=function(t,e){o(t instanceof l),this._value=t.isZero()&&t.isNegative()?t.negated():t,this.canonicalize(e),this._check_limits()},i.prototype.abs=function(){return this.clone(this.is_negative())},i.prototype.add=function(t){var e=i.from_json(t);return this.is_comparable(e)?this._copy(this._value.plus(e._value)):new i(0/0)},i.prototype.subtract=function(t){return this.add(i.from_json(t).negate())},i.prototype.multiply=function(t){var e=i.from_json(t),r=e.is_native()?e._value.times(i.bi_xns_unit):e._value;return this._copy(this._value.times(r))},i.prototype.scale=function(t){return this._copy(this._value.times(t))},i.prototype.divide=function(t){var e=i.from_json(t);if(!this.is_valid())throw new Error("Invalid dividend");if(!e.is_valid())throw new Error("Invalid divisor");if(e.is_zero())throw new Error("divide by zero");var r=e.is_native()?e._value.times(i.bi_xns_unit):e._value;return this._copy(this._value.dividedBy(r))},i.prototype.ratio_human=function(t,e){e=s({},e);var r=this.clone();return t=i.from_json(t),r.is_valid()&&t.is_valid()?t.is_zero()?new i(0/0):(e.reference_date&&(t=t.applyInterest(e.reference_date)),t._is_native&&r._set_value(r._value.times(i.bi_xns_unit)),r.divide(t)):new i(0/0)},i.prototype.product_human=function(t,e){if(e=e||{},t=i.from_json(t),!this.is_valid()||!t.is_valid())return new i(0/0);e.reference_date&&(t=t.applyInterest(e.reference_date));var r=this.multiply(t);return t._is_native&&r._set_value(r._value.dividedBy(i.bi_xns_unit)),r},i.prototype._invert=function(){return this._set_value(n(this._value)),this},i.prototype.invert=function(){return this.clone()._invert()},i.prototype.canonicalize=function(t){this._value=this._is_native?this._value.round(6,l.ROUND_DOWN):new l(t?this._value.toPrecision(16,t):this._value.toPrecision(16))},i.prototype._check_limits=function(){if(!i.strict_mode)return this;if(this._value.isNaN()||this._value.isZero())return this;var t=this._value.absoluteValue();if(this._is_native){if(t.greaterThan(d))throw new Error("Exceeding max value of "+d.toString())}else{if(t.lessThan(m))throw new Error("Exceeding min value of "+m.toString());if(t.greaterThan(_))throw new Error("Exceeding max value of "+_.toString())}return this},i.prototype.clone=function(t){return this.copyTo(new i,t)},i.prototype._copy=function(t){var e=this.clone();return e._set_value(t),e},i.prototype.compareTo=function(t){var e=i.from_json(t);return this.is_comparable(e)?this._value.comparedTo(e._value):0},i.prototype.copyTo=function(t,e){return t._value=e?this._value.negated():this._value,t._is_native=this._is_native,t._currency=this._currency,t._issuer=this._issuer,t},i.prototype.currency=function(){return this._currency},i.prototype.equals=function(t,e){return t instanceof i?this.is_valid()&&t.is_valid()&&this._is_native===t._is_native&&this._value.equals(t._value)&&(this._is_native||this._currency.equals(t._currency)&&(e||this._issuer.equals(t._issuer))):this.equals(i.from_json(t))},i.prototype.is_comparable=function(t){return this.is_valid()&&t.is_valid()&&this._is_native===t._is_native},i.prototype.is_native=function(){return this._is_native},i.prototype.is_negative=function(){return this._value.isNegative()},i.prototype.is_positive=function(){return!this.is_zero()&&!this.is_negative()},i.prototype.is_valid=function(){return!this._value.isNaN()},i.prototype.is_valid_full=function(){return this.is_valid()&&this._currency.is_valid()&&this._issuer.is_valid()},i.prototype.is_zero=function(){return this._value.isZero()},i.prototype.issuer=function(){return this._issuer},i.prototype.negate=function(){return this.clone("NEGATE")},i.prototype.parse_human=function(t,e){function r(t){return isFinite(t)&&""!==t&&null!==t}e=e||{};var n,o,s=/^[a-fA-F0-9]{40}$/,a=/^([a-zA-Z]{3}|[0-9]{3})$/,u=t.split(" ").filter(function(t){return""!==t});if(1===u.length){if(r(u[0]))n=u[0],o="XRP";else if(n=u[0].slice(0,-3),o=u[0].slice(-3),!r(n)||!o.match(a))return new i(0/0)}else{if(2!==u.length)return new i(0/0);if(r(u[0])&&u[1].match(s))n=u[0],o=u[1];else if(u[0].match(a)&&r(u[1]))n=u[1],o=u[0];else{if(!r(u[0])||!u[1].match(a))return new i(0/0);n=u[0],o=u[1]}}if(o=o.toUpperCase(),this.set_currency(o),this._is_native="XRP"===o,this._set_value(new l(n)),e.reference_date&&this._currency.has_interest()){var c=this._currency.get_interest_at(e.reference_date);this._set_value(this._value.dividedBy(c.toString()))}return this},i.prototype.parse_issuer=function(t){return this._issuer=u.from_json(t),this},i.prototype.parse_quality=function(t,e,r,o){o=o||{};var s=h.from_json(o.base_currency),a=t.substring(t.length-14),c=t.substring(t.length-16,t.length-14),f=new l(a,16),p=parseInt(c,16)-100,d=new l(f.toString()+"e"+p.toString());if(this._currency=h.from_json(e),this._issuer=u.from_json(r),this._is_native=this._currency.is_native(),this._is_native&&s.is_native())throw new Error("XRP/XRP quality is not allowed");var _=o.inverse?n(d):d,m=_;if(o.xrp_as_drops||(this._is_native?m=_.div(i.bi_xns_unit):s.is_valid()&&s.is_native()&&(m=_.times(i.bi_xns_unit))),this._set_value(m),o.reference_date&&s.is_valid()&&s.has_interest()){var g=s.get_interest_at(o.reference_date);this._set_value(this._value.dividedBy(g.toString()))}return this},i.prototype.parse_number=function(t){return this._is_native=!1,this._currency=h.from_json(1),this._issuer=u.from_json(1),this._set_value(new l(t)),this},i.prototype.parse_json=function(t){switch(typeof t){case"string":var e=t.match(/^([^\/]+)\/([^\/]+)(?:\/(.+))?$/);e?(this._currency=h.from_json(e[2]),this._issuer=u.from_json(e[3]?e[3]:"1"),this.parse_value(e[1])):(this.parse_native(t),this._currency=h.from_json("0"),this._issuer=u.from_json("0"));break;case"number":this.parse_json(String(t));break;case"object":if(null===t)break;t instanceof i?t.copyTo(this):t.hasOwnProperty("value")&&(this._currency.parse_json(t.currency,!0),"string"==typeof t.issuer&&this._issuer.parse_json(t.issuer),this.parse_value(t.value));break;default:this._set_value(new l(0/0))}return this},i.prototype.parse_native=function(t){if(t&&"string"==typeof t&&!isNaN(t)){if(t.indexOf(".")>=0)throw new Error("Native amounts must be specified in integer drops");var e=new l(t);this._is_native=!0,this._set_value(e.dividedBy(i.bi_xns_unit))}else this._set_value(new l(0/0));return this},i.prototype.parse_value=function(t){return this._is_native=!1,this._set_value(new l(t),l.ROUND_DOWN),this},i.prototype.set_currency=function(t){return this._currency=h.from_json(t),this._is_native=this._currency.is_native(),this},i.prototype.set_issuer=function(t){return this._issuer=t instanceof u?t:u.from_json(t),this},i.prototype.to_number=function(){return Number(this.to_text())},i.prototype.to_text=function(){if(!this.is_valid())return"NaN";if(this._is_native)return this._value.times(i.bi_xns_unit).toString();var t=this._value.e-15,e=this._value.isNegative()?"-":"",r=a.getMantissaDecimalString(this._value.absoluteValue());if(0!==t&&(-25>t||t>-4))return e+r.toString()+"e"+t.toString();var n="000000000000000000000000000"+r.toString()+"00000000000000000000000",o=n.substring(0,t+43),s=n.substring(t+43),u=o.match(/[1-9].*$/),c=s.match(/[1-9]0*$/);return e+(u?u[0]:"0")+(c?"."+s.substring(0,1+s.length-c[0].length):"")},i.prototype.applyInterest=function(t){if(!this._currency.has_interest())return this;var e=this._currency.get_interest_at(t);return this._copy(this._value.times(e.toString()))},i.prototype.to_human=function(t){if(t=t||{},!this.is_valid())return"NaN";var e=this;t.reference_date&&(e=this.applyInterest(t.reference_date));var r=e._value.isNegative(),n=e._value.abs().toFixed(),i=n.split("."),o=i[0],s=2===i.length?i[1]:"";if(o=o.replace(/^0*/,""),s=s.replace(/0*$/,""),s.length||!t.skip_empty_fraction){if("number"==typeof t.precision){var u=Math.max(0,t.precision);u=Math.min(u,s.length);var c=Number("0."+s).toFixed(u);for(1>c?s=c.substring(2):(o=(Number(o)+1).toString(),s="");s.length<u;)s="0"+s}if("number"==typeof t.max_sig_digits){var h=0===Number(o),f=h?0:o.length,l=h?s.replace(/^0*/,""):s;f+=l.length;var p=f-t.max_sig_digits;p=Math.max(p,0),p=Math.min(p,s.length),p>0&&(s=s.slice(0,-p))}if("number"==typeof t.min_precision)for(t.min_precision=Math.max(0,t.min_precision);s.length<t.min_precision;)s+="0"}if(t.group_sep!==!1){var d="string"==typeof t.group_sep?t.group_sep:",",_=a.chunkString(o,t.group_width||3,!0);o=_.join(d)}var m="";return r&&t.signed!==!1&&(m+="-"),m+=o.length?o:"0",m+=s.length?"."+s:""},i.prototype.to_human_full=function(t){t=t||{};var e=this.to_human(t),r=this._currency.to_human(),n=this._issuer.to_json(t),i=e+"/"+r;return this.is_native()?i:i+"/"+n},i.prototype.to_json=function(){if(this._is_native)return this.to_text();var t={value:this.to_text(),currency:this._currency.has_interest()?this._currency.to_hex():this._currency.to_json()};return this._issuer.is_valid()&&(t.issuer=this._issuer.to_json()),t},i.prototype.to_text_full=function(t){return this.is_valid()?this._is_native?this.to_human()+"/XRP":this.to_text()+"/"+this._currency.to_json()+"/"+this._issuer.to_json(t):"NaN"},i.prototype.not_equals_why=function(t,e){if("string"==typeof t)return this.not_equals_why(i.from_json(t));if(!(t instanceof i))return"Not an Amount";if(!this.is_valid()||!t.is_valid())return"Invalid amount.";if(this._is_native!==t._is_native)return"Native mismatch.";var r=this._is_native?"XRP":"Non-XRP";if(!this._value.isZero()&&this._value.negated().equals(t._value))return r+" sign differs.";if(!this._value.equals(t._value))return r+" value differs.";if(!this._is_native){if(!this._currency.equals(t._currency))return"Non-XRP currency differs.";if(!e&&!this._issuer.equals(t._issuer))return"Non-XRP issuer differs: "+t._issuer.to_json()+"/"+this._issuer.to_json()}},e.Amount=i,e.Currency=h,e.Seed=c,e.UInt160=u},function(t,e,r){"use strict";function n(t,e){function r(t){~n.subscribeEvents.indexOf(t)&&(!l._subs&&l._remote._connected&&l._remote.request_subscribe().add_account(l._account_id).broadcast().request(),l._subs+=1)}function o(t){~n.subscribeEvents.indexOf(t)&&(l._subs-=1,!l._subs&&l._remote._connected&&l._remote.request_unsubscribe().add_account(l._account_id).broadcast().request())}function s(t){l._account.is_valid()&&l._subs&&t.add_account(l._account_id)}function c(t){if(t.mmeta){var e=!1;t.mmeta.each(function(t){var r=t.fields.Account===l._account_id,n=r&&"AccountRoot"===t.entryType;if(n&&(a(l._entry,t.fieldsNew,t.fieldsFinal),i(t.fieldsPrev).forEach(function(e){t.fieldsFinal.hasOwnProperty(e)||delete l._entry[e]}),e=!0),"SignerList"===t.entryType){switch(t.nodeType){case"CreatedNode":case"ModifiedNode":l._entry.signer_lists&&l._entry.signer_lists[0]||(l._entry.signer_lists=[{}]),a(l._entry.signer_lists[0],t.fieldsNew,t.fieldsFinal);break;case"DeletedNode":l._entry.signer_lists=[]}e=!0}}),e&&l.emit("entry",l._entry,t.ledger_index)}}u.call(this);var l=this;return this._remote=t,this._account=h.from_json(e),this._account_id=this._account.to_json(),this._subs=0,this._entry={},this.on("newListener",r),this.on("removeListener",o),this._remote.on("prepare_subscribe",s),this.on("transaction",c),this._listener=new d(this),this._transactionManager=new f(this),this}var i=r(28)["default"],o=r(47),s=r(41),a=r(42),u=r(40).EventEmitter,c=r(3).Amount,h=r(9).UInt160,f=r(26).TransactionManager,l=r(18).sjcl,p=r(7).Base,d=r(29);s.inherits(n,u),n.subscribeEvents=["transaction","entry"],n.prototype.getStream=function(){r