1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
require=function e(t,n,r){function o(f,s){if(!n[f]){if(!t[f]){var a="function"==typeof require&&require;if(!s&&a)return a(f,!0);if(i)return i(f,!0);var u=new Error("Cannot find module '"+f+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[f]={exports:{}};t[f][0].call(c.exports,function(e){var n=t[f][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[f].exports}for(var i="function"==typeof require&&require,f=0;f<r.length;f++)o(r[f]);return o}({1:[function(e,t){var n=e("./web3"),r=function(e,t){for(var n=!1,r=0;r<e.length&&!n;r++)n=t(e[r]);return n?r-1:-1},o=function(e,t){return r(e,function(e){return e.name===t})},i=function(e,t,n){return new Array(t-e.length+1).join(n?n:"0")+e},f=function(e){return function(t){return 0===t.indexOf(e)}},s=function(e){return function(t){return e===t}},a=function(){var e=function(e){var t=64;return e=e instanceof BigNumber?e.lessThan(0)?new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16).plus(e).plus(1).toString(16):e.toString(16):"number"==typeof e?0>e?new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16).plus(e).plus(1).toString(16):new BigNumber(e).toString(16):0===e.indexOf("0x")?e.substr(2):"string"==typeof e?new BigNumber(e).toString(16):(+e).toString(16),i(e,t)},t=function(e){return n.fromAscii(e,32).substr(2)},r=function(e){return"000000000000000000000000000000000000000000000000000000000000000"+(e?"1":"0")};return[{type:f("uint"),format:e},{type:f("int"),format:e},{type:f("hash"),format:e},{type:f("string"),format:t},{type:f("real"),format:e},{type:f("ureal"),format:e},{type:s("address"),format:e},{type:s("bool"),format:r}]},u=a(),c=function(e,t,n){var r="",i=o(e,t);if(-1!==i){for(var f=e[i],s=0;s<f.inputs.length;s++){for(var a=!1,c=0;c<u.length&&!a;c++)a=u[c].type(f.inputs[s].type,n[s]);a||console.error("input parser does not support type: "+f.inputs[s].type);var l=u[c-1].format;r+=l?l(n[s]):n[s]}return r}},l=function(){var e=function(e){return"f"===e.substr(0,1).toLowerCase()?new BigNumber(e,16).minus(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16)).minus(1):new BigNumber(e,16)},t=function(e){return new BigNumber(e,16)},r=function(e){return"0x"+e},o=function(e){return"0000000000000000000000000000000000000000000000000000000000000001"===e?!0:!1},i=function(e){return n.toAscii(e)},a=function(e){return"0x"+e.slice(e.length-40,e.length)};return[{type:f("uint"),format:t},{type:f("int"),format:e},{type:f("hash"),format:r},{type:f("string"),format:i},{type:f("real"),format:e},{type:f("ureal"),format:e},{type:s("address"),format:a},{type:s("bool"),format:o}]},h=l(),p=function(e,t,n){var r=o(e,t);if(-1!==r){n=n.slice(2);for(var i=[],f=e[r],s=64,a=0;a<f.outputs.length;a++){for(var u=!1,c=0;c<h.length&&!u;c++)u=h[c].type(f.outputs[a].type);if(u){var l=n.slice(0,s),p=h[c-1].format;i.push(p?p(l):"0x"+l),n=n.slice(s)}else console.error("output parser does not support type: "+f.outputs[a].type)}return i}},d=function(e){var t={};return e.forEach(function(n){t[n.name]=function(){var t=Array.prototype.slice.call(arguments);return c(e,n.name,t)}}),t},v=function(e){var t={};return e.forEach(function(n){t[n.name]=function(t){return p(e,n.name,t)}}),t},g=function(e,t){var r=e[o(e,t)],i=t+"(",f=r.inputs.map(function(e){return e.type});return i+=f.join(","),i+=")",n.sha3(n.fromAscii(i))};t.exports={inputParser:d,outputParser:v,methodSignature:g}},{"./web3":8}],2:[function(e,t){var n=function(e){if(!web3.haveProvider()){if(this.sendQueue=[],this.onmessageQueue=[],navigator.qt)return void(this.provider=new web3.providers.QtProvider);e=e||{};var t={httprpc:e.httprpc||"http://localhost:8080",websockets:e.websockets||"ws://localhost:40404/eth"},n=this,r=function(e){o.close(),e?n.provider=new web3.providers.WebSocketProvider(t.websockets):(n.provider=new web3.providers.HttpRpcProvider(t.httprpc),n.poll=n.provider.poll.bind(n.provider)),n.sendQueue.forEach(function(e){n.provider(e)}),n.onmessageQueue.forEach(function(e){n.provider.onmessage=e})},o=new WebSocket(t.websockets);o.onopen=function(){r(!0)},o.onerror=function(){r(!1)}}};n.prototype.send=function(e){return this.provider?void this.provider.send(e):void this.sendQueue.push(e)},Object.defineProperty(n.prototype,"onmessage",{set:function(e){return this.provider?void(this.provider.onmessage=e):void this.onmessageQueue.push(e)}}),t.exports=n},{}],3:[function(e,t){var n=e("./web3"),r=e("./abi"),o=4,i=function(e,t){var i=r.inputParser(t),f=r.outputParser(t),s={};return t.forEach(function(a){s[a.name]=function(){var s=Array.prototype.slice.call(arguments),u=i[a.name].apply(null,s),c=function(e){return f[a.name](e)};return{call:function(i){return i=i||{},i.to=e,r.methodSignature(t,a.name).then(function(e){return i.data=e.slice(0,2+2*o)+u,n.eth.call(i).then(c)})},transact:function(i){return i=i||{},i.to=e,r.methodSignature(t,a.name).then(function(e){return i.data=e.slice(0,2+2*o)+u,n.eth.transact(i).then(c)})}}}}),s};t.exports=i},{"./abi":1,"./web3":8}],4:[function(e,t){var n=e("./web3"),r=function(e,t){this.impl=t,this.callbacks=[];var r=this;this.promise=t.newFilter(e),this.promise.then(function(e){r.id=e,n.on(t.changed,e,r.trigger.bind(r)),n.provider.startPolling({call:t.changed,args:[e]},e)})};r.prototype.arrived=function(e){this.changed(e)},r.prototype.changed=function(e){var t=this;this.promise.then(function(){t.callbacks.push(e)})},r.prototype.trigger=function(e){for(var t=0;t<this.callbacks.length;t++)this.callbacks[t].call(this,e)},r.prototype.uninstall=function(){var e=this;this.promise.then(function(t){e.impl.uninstallFilter(t),n.provider.stopPolling(t),n.off(impl.changed,t)})},r.prototype.messages=function(){var e=this;return this.promise.then(function(t){return e.impl.getMessages(t)})},r.prototype.logs=function(){return this.messages()},t.exports=r},{"./web3":8}],5:[function(e,t){function n(e){return{jsonrpc:"2.0",method:e.call,params:e.args,id:e._id}}function r(e){var t=JSON.parse(e);return{_id:t.id,data:t.result,error:t.error}}var o=function(e){this.handlers=[],this.host=e};o.prototype.sendRequest=function(e,t){var r=n(e),o=new XMLHttpRequest;o.open("POST",this.host,!0),o.send(JSON.stringify(r)),o.onreadystatechange=function(){4===o.readyState&&t&&t(o)}},o.prototype.send=function(e){var t=this;this.sendRequest(e,function(e){t.handlers.forEach(function(n){n.call(t,r(e.responseText))})})},o.prototype.poll=function(e,t){var n=this;this.sendRequest(e,function(r){var o=JSON.parse(r.responseText);!o.error&&(o.result instanceof Array?0!==o.result.length:o.result)&&n.handlers.forEach(function(r){r.call(n,{_event:e.call,_id:t,data:o.result})})})},Object.defineProperty(o.prototype,"onmessage",{set:function(e){this.handlers.push(e)}}),t.exports=o},{}],6:[function(e,t){var n=e("./web3"),r=function(){this.queued=[],this.polls=[],this.ready=!1,this.provider=void 0,this.id=1;var e=this,t=function(){e.provider&&e.provider.poll&&e.polls.forEach(function(t){t.data._id=e.id,e.id++,e.provider.poll(t.data,t.id)}),setTimeout(t,12e3)};t()};r.prototype.send=function(e,t){e._id=this.id,t&&(n._callbacks[e._id]=t),e.args=e.args||[],this.id++,void 0!==this.provider?this.provider.send(e):(console.warn("provider is not set"),this.queued.push(e))},r.prototype.set=function(e){void 0!==this.provider&&void 0!==this.provider.unload&&this.provider.unload(),this.provider=e,this.ready=!0},r.prototype.sendQueued=function(){for(var e=0;this.queued.length;e++)this.send(this.queued[e])},r.prototype.installed=function(){return void 0!==this.provider},r.prototype.startPolling=function(e,t){this.provider&&this.provider.poll&&this.polls.push({data:e,id:t})},r.prototype.stopPolling=function(e){for(var t=this.polls.length;t--;){var n=this.polls[t];n.id===e&&this.polls.splice(t,1)}},t.exports=r},{"./web3":8}],7:[function(e,t){var n=function(){this.handlers=[];var e=this;navigator.qt.onmessage=function(t){e.handlers.forEach(function(n){n.call(e,JSON.parse(t.data))})}};n.prototype.send=function(e){navigator.qt.postMessage(JSON.stringify(e))},Object.defineProperty(n.prototype,"onmessage",{set:function(e){this.handlers.push(e)}}),t.exports=n},{}],8:[function(e,t){function n(e){return e instanceof Promise?Promise.resolve(e):e instanceof Array?new Promise(function(t){var r=e.map(function(e){return n(e)});return Promise.all(r).then(function(n){for(var r=0;r<e.length;r++)e[r]=n[r];t(e)})}):e instanceof Object?new Promise(function(t){var r=Object.keys(e),o=r.map(function(t){return n(e[t])});return Promise.all(o).then(function(n){for(var o=0;o<r.length;o++)e[r[o]]=n[o];t(e)})}):Promise.resolve(e)}function r(e){if(void 0!==e._event)return void v.trigger(e._event,e._id,e.data);if(e._id){var t=v._callbacks[e._id];t&&(t.call(this,e.error,e.data),delete v._callbacks[e._id])}}var o=function(){return[{name:"sha3",call:"web3_sha3"}]},i=function(){var e=function(e){return"string"==typeof e[0]?"eth_blockByHash":"eth_blockByNumber"},t=function(e){return"string"==typeof e[0]?"eth_transactionByHash":"eth_transactionByNumber"},n=function(e){return"string"==typeof e[0]?"eth_uncleByHash":"eth_uncleByNumber"},r=[{name:"balanceAt",call:"eth_balanceAt"},{name:"stateAt",call:"eth_stateAt"},{name:"storageAt",call:"eth_storageAt"},{name:"countAt",call:"eth_countAt"},{name:"codeAt",call:"eth_codeAt"},{name:"transact",call:"eth_transact"},{name:"call",call:"eth_call"},{name:"block",call:e},{name:"transaction",call:t},{name:"uncle",call:n},{name:"compilers",call:"eth_compilers"},{name:"lll",call:"eth_lll"},{name:"solidity",call:"eth_solidity"},{name:"serpent",call:"eth_serpent"},{name:"logs",call:"eth_logs"}];return r},f=function(){return[{name:"coinbase",getter:"eth_coinbase",setter:"eth_setCoinbase"},{name:"listening",getter:"eth_listening",setter:"eth_setListening"},{name:"mining",getter:"eth_mining",setter:"eth_setMining"},{name:"gasPrice",getter:"eth_gasPrice"},{name:"account",getter:"eth_account"},{name:"accounts",getter:"eth_accounts"},{name:"peerCount",getter:"eth_peerCount"},{name:"defaultBlock",getter:"eth_defaultBlock",setter:"eth_setDefaultBlock"},{name:"number",getter:"eth_number"}]},s=function(){return[{name:"put",call:"db_put"},{name:"get",call:"db_get"},{name:"putString",call:"db_putString"},{name:"getString",call:"db_getString"}]},a=function(){return[{name:"post",call:"shh_post"},{name:"newIdentity",call:"shh_newIdentity"},{name:"haveIdentity",call:"shh_haveIdentity"},{name:"newGroup",call:"shh_newGroup"},{name:"addToGroup",call:"shh_addToGroup"}]},u=function(){var e=function(e){return"string"==typeof e[0]?"eth_newFilterString":"eth_newFilter"};return[{name:"newFilter",call:e},{name:"uninstallFilter",call:"eth_uninstallFilter"},{name:"getMessages",call:"eth_filterLogs"}]},c=function(){return[{name:"newFilter",call:"shh_newFilter"},{name:"uninstallFilter",call:"shh_uninstallFilter"},{name:"getMessage",call:"shh_getMessages"}]},l=function(e,t){t.forEach(function(t){e[t.name]=function(){return n(Array.prototype.slice.call(arguments)).then(function(e){var n="function"==typeof t.call?t.call(e):t.call;return{call:n,args:e}}).then(function(e){return new Promise(function(t,n){v.provider.send(e,function(e,r){return e?void n(e):void t(r)})})}).catch(function(e){console.error(e)})}})},h=function(e,t){t.forEach(function(t){var r={};r.get=function(){return new Promise(function(e,n){v.provider.send({call:t.getter},function(t,r){return t?void n(t):void e(r)})})},t.setter&&(r.set=function(e){return n([e]).then(function(e){return new Promise(function(n){v.provider.send({call:t.setter,args:e},function(e,t){return e?void reject(e):void n(t)})})}).catch(function(e){console.error(e)})}),Object.defineProperty(e,t.name,r)})},p=function(e){return parseInt(e,16).toString()},d=function(e){return parseInt(e).toString(16)},v={_callbacks:{},_events:{},providers:{},toHex:function(e){for(var t="",n=0;n<e.length;n++){var r=e.charCodeAt(n).toString(16);t+=r.length<2?"0"+r:r}return t},toAscii:function(e){var t="",n=0,r=e.length;for("0x"===e.substring(0,2)&&(n=2);r>n;n+=2){var o=parseInt(e.substr(n,2),16);if(0===o)break;t+=String.fromCharCode(o)}return t},fromAscii:function(e,t){t=void 0===t?0:t;for(var n=this.toHex(e);n.length<2*t;)n+="00";return"0x"+n},toDecimal:function(e){return p(e.substring(2))},fromDecimal:function(e){return"0x"+d(e)},toEth:function(e){for(var t="string"==typeof e?0===e.indexOf("0x")?parseInt(e.substr(2),16):parseInt(e):e,n=0,r=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];t>3e3&&n<r.length-1;)t/=1e3,n++;for(var o=t.toString().length<t.toFixed(2).length?t.toString():t.toFixed(2),i=function(e,t,n){return t+","+n};;){var f=o;if(o=o.replace(/(\d)(\d\d\d[\.\,])/,i),f===o)break}return o+" "+r[n]},eth:{watch:function(e){return new v.filter(e,g)}},db:{},shh:{watch:function(e){return new v.filter(e,m)}},on:function(e,t,n){return void 0===v._events[e]&&(v._events[e]={}),v._events[e][t]=n,this},off:function(e,t){return void 0!==v._events[e]&&delete v._events[e][t],this},trigger:function(e,t,n){var r=v._events[e];if(r&&r[t]){var o=r[t];o(n)}},haveProvider:function(){return!!v.provider.provider}};l(v,o()),l(v.eth,i()),h(v.eth,f()),l(v.db,s()),l(v.shh,a());var g={changed:"eth_changed"};l(g,u());var m={changed:"shh_changed"};l(m,c()),v.setProvider=function(e){e.onmessage=r,v.provider.set(e),v.provider.sendQueued()},t.exports=v},{}],9:[function(e,t){var n=function(e){this.handlers=[],this.queued=[],this.ready=!1,this.ws=new WebSocket(e);var t=this;this.ws.onmessage=function(e){for(var n=0;n<t.handlers.length;n++)t.handlers[n].call(t,JSON.parse(e.data),e)},this.ws.onopen=function(){t.ready=!0;for(var e=0;e<t.queued.length;e++)t.send(t.queued[e])}};n.prototype.send=function(e){if(this.ready){var t=JSON.stringify(e);this.ws.send(t)}else this.queued.push(e)},n.prototype.onMessage=function(e){this.handlers.push(e)},n.prototype.unload=function(){this.ws.close()},Object.defineProperty(n.prototype,"onmessage",{set:function(e){this.onMessage(e)}}),"undefined"!=typeof t&&(t.exports=n)},{}],web3:[function(e,t){var n=e("./lib/web3"),r=e("./lib/providermanager");n.provider=new r,n.filter=e("./lib/filter"),n.providers.WebSocketProvider=e("./lib/websocket"),n.providers.HttpRpcProvider=e("./lib/httprpc"),n.providers.QtProvider=e("./lib/qt"),n.providers.AutoProvider=e("./lib/autoprovider"),n.eth.contract=e("./lib/contract"),t.exports=n},{"./lib/autoprovider":2,"./lib/contract":3,"./lib/filter":4,"./lib/httprpc":5,"./lib/providermanager":6,"./lib/qt":7,"./lib/web3":8,"./lib/websocket":9}]},{},["web3"]); |