plugeth/dist/ethereum.min.js
2015-01-21 21:22:05 +01:00

1 line
12 KiB
JavaScript

require=function t(e,n,r){function i(a,f){if(!n[a]){if(!e[a]){var u="function"==typeof require&&require;if(!f&&u)return u(a,!0);if(o)return o(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(t,e){var n=t("./web3");BigNumber.config({ROUNDING_MODE:BigNumber.ROUND_DOWN});var r=32,i=4,o=function(t,e){for(var n=!1,r=0;r<t.length&&!n;r++)n=e(t[r]);return n?r-1:-1},a=function(t,e){return o(t,function(t){return t.name===e})},f=function(t,e,n){return new Array(e-t.length+1).join(n?n:"0")+t},u=function(t){return function(e){return 0===e.indexOf(t)}},s=function(t){return function(e){return t===e}},c=function(t){return"[]"===t.slice(-2)},l=function(t){var e=2*r;return t instanceof BigNumber||"number"==typeof t?("number"==typeof t&&(t=new BigNumber(t)),t=t.round(),t.lessThan(0)&&(t=new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16).plus(t).plus(1)),t=t.toString(16)):t=0===t.indexOf("0x")?t.substr(2):"string"==typeof t?l(new BigNumber(t)):(+t).toString(16),f(t,e)},p=function(t){return n.fromAscii(t,r).substr(2)},h=function(t){return"000000000000000000000000000000000000000000000000000000000000000"+(t?"1":"0")},d=function(t){return l(new BigNumber(t).times(new BigNumber(2).pow(128)))},m=function(t,e){return c(t)||u("string")(t)?l(e.length):""},g=function(){return[{type:u("uint"),format:l},{type:u("int"),format:l},{type:u("hash"),format:l},{type:u("string"),format:p},{type:u("real"),format:d},{type:u("ureal"),format:d},{type:s("address"),format:l},{type:s("bool"),format:h}]},v=g(),b=function(t,e,n){var r="",i=a(t,e);if(-1!==i){var o=t[i];return o.inputs.forEach(function(t,e){r+=m(t.type,n[e])}),o.inputs.forEach(function(t,e){for(var i=!1,a=0;a<v.length&&!i;a++)i=v[a].type(o.inputs[e].type,n[e]);i||console.error("input parser does not support type: "+o.inputs[e].type);var f=v[a-1].format,u="";u=c(o.inputs[e].type)?n[e].reduce(function(t,e){return t+f(e)},""):f(n[e]),r+=u}),r}},y=function(t){return"1"===new BigNumber(t.substr(0,1),16).toString(2).substr(0,1)},_=function(t){return y(t)?new BigNumber(t,16).minus(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16)).minus(1):new BigNumber(t,16)},w=function(t){return new BigNumber(t,16)},N=function(t){return _(t).dividedBy(new BigNumber(2).pow(128))},x=function(t){return w(t).dividedBy(new BigNumber(2).pow(128))},B=function(t){return"0x"+t},A=function(t){return"0000000000000000000000000000000000000000000000000000000000000001"===t?!0:!1},S=function(t){return n.toAscii(t)},O=function(t){return"0x"+t.slice(t.length-40,t.length)},P=function(t){return c(t)||u("string")(t)?2*r:0},E=function(){return[{type:u("uint"),format:w},{type:u("int"),format:_},{type:u("hash"),format:B},{type:u("string"),format:S},{type:u("real"),format:N},{type:u("ureal"),format:x},{type:s("address"),format:O},{type:s("bool"),format:A}]},F=E(),k=function(t,e,n){var i=a(t,e);if(-1!==i){n=n.slice(2);var o=[],f=t[i],s=2*r,l=f.outputs.reduce(function(t,e){return t+P(e.type)},0),p=n.slice(0,l);return n=n.slice(l),f.outputs.forEach(function(t,e){for(var r=!1,i=0;i<F.length&&!r;i++)r=F[i].type(f.outputs[e].type);r||console.error("output parser does not support type: "+f.outputs[e].type);var a=F[i-1].format;if(c(f.outputs[e].type)){var l=w(p.slice(0,s));p=p.slice(s);for(var h=[],d=0;l>d;d++)h.push(a(n.slice(0,s))),n=n.slice(s);o.push(h)}else u("string")(f.outputs[e].type)?(p=p.slice(s),o.push(a(n.slice(0,s))),n=n.slice(s)):(o.push(a(n.slice(0,s))),n=n.slice(s))}),o}},D=function(t){var e=t.indexOf("(");return-1!==e?t.substr(0,e):t},I=function(t){var e=t.indexOf("(");return-1!==e?t.substr(e+1,t.length-1-(e+1)):""},M=function(t){var e={};return t.forEach(function(n){var r=D(n.name),i=I(n.name),o=function(){var e=Array.prototype.slice.call(arguments);return b(t,n.name,e)};void 0===e[r]&&(e[r]=o),e[r][i]=o}),e},T=function(t){var e={};return t.forEach(function(n){var r=D(n.name),i=I(n.name),o=function(e){return k(t,n.name,e)};void 0===e[r]&&(e[r]=o),e[r][i]=o}),e},C=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*i)};e.exports={inputParser:M,outputParser:T,methodSignature:C,methodDisplayName:D,methodTypeName:I}},{"./web3":6}],2:[function(t,e){var n=t("./web3"),r=t("./abi"),i=function(t,e){var i=r.inputParser(e),o=r.outputParser(e),a={};return e.forEach(function(f){var u=r.methodDisplayName(f.name),s=r.methodTypeName(f.name),c=function(){var a=Array.prototype.slice.call(arguments),c=i[u][s].apply(null,a),l=r.methodSignature(f.name);return{call:function(e){e=e||{},e.to=t,e.data=l+c;var r=n.eth.call(e);return o[u][s](r)},transact:function(r){r=r||{},r.to=t,r.data=l+c,n._currentContractAbi=e,n._currentContractAddress=t;var i=n.eth.transact(r);return o[u][s](i)}}};void 0===a[u]&&(a[u]=c),a[u][s]=c}),a};e.exports=i},{"./abi":1,"./web3":6}],3:[function(t,e){var n=t("./web3"),r=function(t,e){this.impl=e,this.callbacks=[];var r=this;this.promise=e.newFilter(t),this.promise.then(function(t){r.id=t,n.on(e.changed,t,r.trigger.bind(r)),n.provider.startPolling({call:e.changed,args:[t]},t)})};r.prototype.arrived=function(t){this.changed(t)},r.prototype.changed=function(t){var e=this;this.promise.then(function(){e.callbacks.push(t)})},r.prototype.trigger=function(t){for(var e=0;e<this.callbacks.length;e++)this.callbacks[e].call(this,t)},r.prototype.uninstall=function(){var t=this;this.promise.then(function(e){t.impl.uninstallFilter(e),n.provider.stopPolling(e),n.off(impl.changed,e)})},r.prototype.messages=function(){var t=this;return this.promise.then(function(e){return t.impl.getMessages(e)})},r.prototype.logs=function(){return this.messages()},e.exports=r},{"./web3":6}],4:[function(t,e){function n(t){return{jsonrpc:"2.0",method:t.call,params:t.args,id:t._id}}var r=function(t){this.handlers=[],this.host=t||"http://localhost:8080"};r.prototype.send=function(t){var e=n(t),r=new XMLHttpRequest;return r.open("POST",this.host,!1),r.send(JSON.stringify(e)),r.responseText},e.exports=r},{}],5:[function(t,e){var n=(t("./web3"),function(){this.queued=[],this.polls=[],this.ready=!1,this.provider=void 0,this.id=1;var t=this,e=function(){t.provider&&t.provider.poll&&t.polls.forEach(function(e){e.data._id=t.id,t.id++,t.provider.poll(e.data,e.id)}),setTimeout(e,12e3)};e()});n.prototype.send=function(t){if(t.args=t.args||[],t._id=this.id++,void 0===this.provider)return void console.error("provider is not set");var e=this.provider.send(t);return e=JSON.parse(e),e.result},n.prototype.set=function(t){void 0!==this.provider&&void 0!==this.provider.unload&&this.provider.unload(),this.provider=t,this.ready=!0},n.prototype.installed=function(){return void 0!==this.provider},n.prototype.startPolling=function(t,e){this.provider&&this.provider.poll&&this.polls.push({data:t,id:e})},n.prototype.stopPolling=function(t){for(var e=this.polls.length;e--;){var n=this.polls[e];n.id===t&&this.polls.splice(e,1)}},e.exports=n},{"./web3":6}],6:[function(t,e){var n=function(){return[{name:"sha3",call:"web3_sha3"}]},r=function(){var t=function(t){return"string"==typeof t[0]?"eth_blockByHash":"eth_blockByNumber"},e=function(t){return"string"==typeof t[0]?"eth_transactionByHash":"eth_transactionByNumber"},n=function(t){return"string"==typeof t[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:t},{name:"transaction",call:e},{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},i=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"}]},o=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"}]},f=function(){var t=function(t){return"string"==typeof t[0]?"eth_newFilterString":"eth_newFilter"};return[{name:"newFilter",call:t},{name:"uninstallFilter",call:"eth_uninstallFilter"},{name:"getMessages",call:"eth_filterLogs"}]},u=function(){return[{name:"newFilter",call:"shh_newFilter"},{name:"uninstallFilter",call:"shh_uninstallFilter"},{name:"getMessage",call:"shh_getMessages"}]},s=function(t,e){e.forEach(function(e){t[e.name]=function(){var t=Array.prototype.slice.call(arguments),n="function"==typeof e.call?e.call(t):e.call;return h.provider.send({call:n,args:t})}})},c=function(t,e){e.forEach(function(e){var n={};n.get=function(){return h.provider.send({call:e.getter})},e.setter&&(n.set=function(t){return h.provider.send({call:e.setter,args:[t]})}),Object.defineProperty(t,e.name,n)})},l=function(t){return parseInt(t,16).toString()},p=function(t){return parseInt(t).toString(16)},h={_callbacks:{},_events:{},providers:{},toHex:function(t){for(var e="",n=0;n<t.length;n++){var r=t.charCodeAt(n).toString(16);e+=r.length<2?"0"+r:r}return e},toAscii:function(t){var e="",n=0,r=t.length;for("0x"===t.substring(0,2)&&(n=2);r>n;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},fromAscii:function(t,e){e=void 0===e?0:e;for(var n=this.toHex(t);n.length<2*e;)n+="00";return"0x"+n},toDecimal:function(t){return l(t.substring(2))},fromDecimal:function(t){return"0x"+p(t)},toEth:function(t){for(var e="string"==typeof t?0===t.indexOf("0x")?parseInt(t.substr(2),16):parseInt(t):t,n=0,r=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];e>3e3&&n<r.length-1;)e/=1e3,n++;for(var i=e.toString().length<e.toFixed(2).length?e.toString():e.toFixed(2),o=function(t,e,n){return e+","+n};;){var a=i;if(i=i.replace(/(\d)(\d\d\d[\.\,])/,o),a===i)break}return i+" "+r[n]},eth:{watch:function(t){return new h.filter(t,d)}},db:{},shh:{watch:function(t){return new h.filter(t,m)}},on:function(t,e,n){return void 0===h._events[t]&&(h._events[t]={}),h._events[t][e]=n,this},off:function(t,e){return void 0!==h._events[t]&&delete h._events[t][e],this},trigger:function(t,e,n){var r=h._events[t];if(r&&r[e]){var i=r[e];i(n)}},haveProvider:function(){return!!h.provider.provider}};s(h,n()),s(h.eth,r()),c(h.eth,i()),s(h.db,o()),s(h.shh,a());var d={changed:"eth_changed"};s(d,f());var m={changed:"shh_changed"};s(m,u()),h.setProvider=function(t){h.provider.set(t)},e.exports=h},{}],web3:[function(t,e){var n=t("./lib/web3"),r=t("./lib/providermanager");n.provider=new r,n.filter=t("./lib/filter"),n.providers.HttpSyncProvider=t("./lib/httpsync"),n.eth.contract=t("./lib/contract"),n.abi=t("./lib/abi"),e.exports=n},{"./lib/abi":1,"./lib/contract":2,"./lib/filter":3,"./lib/httpsync":4,"./lib/providermanager":5,"./lib/web3":6}]},{},["web3"]);