mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-24 12:37:16 +00:00
4 lines
17 KiB
Go
4 lines
17 KiB
Go
package jsre
|
|
|
|
const Ethereum_JS = `require=function t(n,e,r){function o(i,u){if(!e[i]){if(!n[i]){var f="function"==typeof require&&require;if(!u&&f)return f(i,!0);if(a)return a(i,!0);var s=new Error("Cannot find module '"+i+"'");throw s.code="MODULE_NOT_FOUND",s}var c=e[i]={exports:{}};n[i][0].call(c.exports,function(t){var e=n[i][1][t];return o(e?e:t)},c,c.exports,t,n,e,r)}return e[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(t,n){var e=t("./web3"),r=t("./utils"),o=t("./types"),a=t("./const"),i=t("./formatters"),u=function(t){console.error("parser does not support type: "+t)},f=function(t){return"[]"===t.slice(-2)},s=function(t,n){return f(t)||"string"===t?i.formatInputInt(n.length):""},c=o.inputTypes(),l=function(t,n){{var e="";2*a.ETH_PADDING}return t.forEach(function(t,r){e+=s(t.type,n[r])}),t.forEach(function(r,o){for(var a=!1,i=0;i<c.length&&!a;i++)a=c[i].type(t[o].type,n[o]);a||u(t[o].type);var s=c[i-1].format,l="";l=f(t[o].type)?n[o].reduce(function(t,n){return t+s(n)},""):s(n[o]),e+=l}),e},p=function(t){return f(t)||"string"===t?2*a.ETH_PADDING:0},m=o.outputTypes(),h=function(t,n){n=n.slice(2);var e=[],r=2*a.ETH_PADDING,s=t.reduce(function(t,n){return t+p(n.type)},0),c=n.slice(0,s);return n=n.slice(s),t.forEach(function(a,s){for(var l=!1,p=0;p<m.length&&!l;p++)l=m[p].type(t[s].type);l||u(t[s].type);var h=m[p-1].format;if(f(t[s].type)){var d=i.formatOutputUInt(c.slice(0,r));c=c.slice(r);for(var g=[],v=0;d>v;v++)g.push(h(n.slice(0,r))),n=n.slice(r);e.push(g)}else o.prefixedType("string")(t[s].type)?(c=c.slice(r),e.push(h(n.slice(0,r))),n=n.slice(r)):(e.push(h(n.slice(0,r))),n=n.slice(r))}),e},d=function(t){var n={};return t.forEach(function(t){var e=r.extractDisplayName(t.name),o=r.extractTypeName(t.name),a=function(){var n=Array.prototype.slice.call(arguments);return l(t.inputs,n)};void 0===n[e]&&(n[e]=a),n[e][o]=a}),n},g=function(t){var n={};return t.forEach(function(t){var e=r.extractDisplayName(t.name),o=r.extractTypeName(t.name),a=function(n){return h(t.outputs,n)};void 0===n[e]&&(n[e]=a),n[e][o]=a}),n},v=function(t){return e.sha3(e.fromAscii(t)).slice(0,2+2*a.ETH_SIGNATURE_LENGTH)},y=function(t){return e.sha3(e.fromAscii(t))};n.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:h,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":8,"./types":14,"./utils":15,"./web3":17}],2:[function(t,n){var e=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];n.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_UNITS:e,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN},ETH_POLLING_TIMEOUT:1e3}},{}],3:[function(t,n){var e=t("./web3"),r=t("./abi"),o=t("./utils"),a=t("./event"),i=(t("./filter"),function(t){e._currentContractAbi=t.abi,e._currentContractAddress=t.address,e._currentContractMethodName=t.method,e._currentContractMethodParams=t.params}),u=function(t){t.call=function(n){return t._isTransact=!1,t._options=n,t},t.transact=function(n){return t._isTransact=!0,t._options=n,t},t._options={},["gas","gasPrice","value","from"].forEach(function(n){t[n]=function(e){return t._options[n]=e,t}})},f=function(t,n,a){var u=r.inputParser(n),f=r.outputParser(n);o.filterFunctions(n).forEach(function(s){var c=o.extractDisplayName(s.name),l=o.extractTypeName(s.name),p=function(){var o=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(s.name),m=u[c][l].apply(null,o),h=t._options||{};h.to=a,h.data=p+m;var d=t._isTransact===!0||t._isTransact!==!1&&!s.constant,g=h.collapse!==!1;if(t._options={},t._isTransact=null,d)return i({abi:n,address:a,method:s.name,params:o}),void e.eth.transact(h);var v=e.eth.call(h),y=f[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},s=function(t,n,e){t.address=e,t._onWatchEventResult=function(t){var e=event.getMatchingEvent(o.filterEvents(n)),r=a.outputParser(e);return r(t)},Object.defineProperty(t,"topic",{get:function(){return o.filterEvents(n).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,n,i){o.filterEvents(n).forEach(function(n){var u=function(){var t=Array.prototype.slice.call(arguments),o=r.eventSignatureFromAscii(n.name),u=a.inputParser(i,o,n),f=u.apply(null,t),s=function(t){var e=a.outputParser(n);return e(t)};return e.eth.watch(f,void 0,void 0,s)};u._isEvent=!0;var f=o.extractDisplayName(n.name),s=o.extractTypeName(n.name);void 0===t[f]&&(t[f]=u),t[f][s]=u})},l=function(t,n){n.forEach(function(t){if(-1===t.name.indexOf("(")){var n=t.name,e=t.inputs.map(function(t){return t.type}).join();t.name=n+"("+e+")"}});var e={};return u(e),f(e,n,t),s(e,n,t),c(e,n,t),e};n.exports=l},{"./abi":1,"./event":6,"./filter":7,"./utils":15,"./web3":17}],4:[function(t,n){var e=function(){return[{name:"put",call:"db_put"},{name:"get",call:"db_get"},{name:"putString",call:"db_putString"},{name:"getString",call:"db_getString"}]};n.exports={methods:e}},{}],5:[function(t,n){var e=function(){var t=function(t){return"string"==typeof t[0]?"eth_blockByHash":"eth_blockByNumber"},n=function(t){return"string"==typeof t[0]?"eth_transactionByHash":"eth_transactionByNumber"},e=function(t){return"string"==typeof t[0]?"eth_uncleByHash":"eth_uncleByNumber"},r=function(t){return"string"==typeof t[0]?"eth_transactionCountByHash":"eth_transactionCountByNumber"},o=function(t){return"string"==typeof t[0]?"eth_uncleCountByHash":"eth_uncleCountByNumber"};return[{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:n},{name:"uncle",call:e},{name:"compilers",call:"eth_compilers"},{name:"flush",call:"eth_flush"},{name:"lll",call:"eth_lll"},{name:"solidity",call:"eth_solidity"},{name:"serpent",call:"eth_serpent"},{name:"logs",call:"eth_logs"},{name:"transactionCount",call:r},{name:"uncleCount",call:o}]},r=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:"accounts",getter:"eth_accounts"},{name:"peerCount",getter:"eth_peerCount"},{name:"defaultBlock",getter:"eth_defaultBlock",setter:"eth_setDefaultBlock"},{name:"number",getter:"eth_number"}]};n.exports={methods:e,properties:r}},{}],6:[function(t,n){var e=t("./abi"),r=t("./utils"),o=function(t,n){return t.filter(function(t){return t.indexed===n})},a=function(t,n){var e=r.findIndex(t,function(t){return t.name===n});return-1===e?void console.error("indexed param with name "+n+" not found"):t[e]},i=function(t,n){return Object.keys(n).map(function(r){var i=[a(o(t.inputs,!0),r)],u=n[r];return u instanceof Array?u.map(function(t){return e.formatInput(i,[t])}):e.formatInput(i,[u])})},u=function(t,n,e){return function(r,o){var a=o||{};return a.address=t,a.topic=[],a.topic.push(n),r&&(a.topic=a.topic.concat(i(e,r))),a}},f=function(t,n,e){n.slice(),e.slice();return t.reduce(function(t,r){var o;return o=r.indexed?n.splice(0,1)[0]:e.splice(0,1)[0],t[r.name]=o,t},{})},s=function(t){return function(n){var a={event:r.extractDisplayName(t.name),number:n.number,args:{}};if(n.topics=n.topic,!n.topic)return a;var i=o(t.inputs,!0),u="0x"+n.topic.slice(1,n.topic.length).map(function(t){return t.slice(2)}).join(""),s=e.formatOutput(i,u),c=o(t.inputs,!1),l=e.formatOutput(c,n.data);return a.args=f(t.inputs,s,l),a}},c=function(t,n){for(var r=0;r<t.length;r++){var o=e.eventSignatureFromAscii(t[r].name);if(o===n.topic[0])return t[r]}return void 0};n.exports={inputParser:u,outputParser:s,getMatchingEvent:c}},{"./abi":1,"./utils":15}],7:[function(t,n){var e=function(t){return!!t&&"function"==typeof t.newFilter&&"function"==typeof t.getMessages&&"function"==typeof t.uninstallFilter&&"function"==typeof t.startPolling&&"function"==typeof t.stopPolling},r=function(t){return"string"==typeof t?t:(t=t||{},t.topics&&console.warn('"topics" is deprecated, is "topic" instead'),{to:t.to,topic:t.topic,earliest:t.earliest,latest:t.latest,max:t.max,skip:t.skip,address:t.address})},o=function(t,n,o){if(!e(n))return void console.error("filter implemenation is invalid");t=r(t);var a=[],i=n.newFilter(t),u=function(t){t.forEach(function(t){t=o?o(t):t,a.forEach(function(n){n(t)})})};n.startPolling(i,u,n.uninstallFilter);var f=function(t){a.push(t)},s=function(){return n.getMessages(i)},c=function(){n.stopPolling(i),n.uninstallFilter(i),a=[]};return{changed:f,arrived:f,happened:f,messages:s,logs:s,uninstall:c}};n.exports=o},{}],8:[function(t,n){var e=t("./utils"),r=t("./const"),o=function(t,n,e){return new Array(n-t.length+1).join(e?e:"0")+t},a=function(t){var n=2*r.ETH_PADDING;return t instanceof BigNumber||"number"==typeof t?("number"==typeof t&&(t=new BigNumber(t)),BigNumber.config(r.ETH_BIGNUMBER_ROUNDING_MODE),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?a(new BigNumber(t)):(+t).toString(16),o(t,n)},i=function(t){return e.fromAscii(t,r.ETH_PADDING).substr(2)},u=function(t){return"000000000000000000000000000000000000000000000000000000000000000"+(t?"1":"0")},f=function(t){return a(new BigNumber(t).times(new BigNumber(2).pow(128)))},s=function(t){return"1"===new BigNumber(t.substr(0,1),16).toString(2).substr(0,1)},c=function(t){return t=t||"0",s(t)?new BigNumber(t,16).minus(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16)).minus(1):new BigNumber(t,16)},l=function(t){return t=t||"0",new BigNumber(t,16)},p=function(t){return c(t).dividedBy(new BigNumber(2).pow(128))},m=function(t){return l(t).dividedBy(new BigNumber(2).pow(128))},h=function(t){return"0x"+t},d=function(t){return"0000000000000000000000000000000000000000000000000000000000000001"===t?!0:!1},g=function(t){return e.toAscii(t)},v=function(t){return"0x"+t.slice(t.length-40,t.length)};n.exports={formatInputInt:a,formatInputString:i,formatInputBool:u,formatInputReal:f,formatOutputInt:c,formatOutputUInt:l,formatOutputReal:p,formatOutputUReal:m,formatOutputHash:h,formatOutputBool:d,formatOutputString:g,formatOutputAddress:v}},{"./const":2,"./utils":15}],9:[function(t,n){var e=function(t){this.handlers=[],this.host=t||"http://localhost:8080"};e.prototype.send=function(t){var n=new XMLHttpRequest;n.open("POST",this.host,!1),n.send(JSON.stringify(t));var e=n.responseText;return 200===n.status?JSON.parse(e):void 0},n.exports=e},{}],10:[function(t,n){var e=1,r=function(t,n){return t||console.error("jsonrpc method should be specified!"),{jsonrpc:"2.0",method:t,params:n||[],id:e++}},o=function(t){return!!t&&!t.error&&"2.0"===t.jsonrpc&&"number"==typeof t.id&&void 0!==t.result},a=function(t){return t.map(function(t){return r(t.method,t.params)})};n.exports={toPayload:r,isValidResponse:o,toBatchPayload:a}},{}],11:[function(t,n){var e=function(){};e.prototype.send=function(t){var n=navigator.qt.callMethod(JSON.stringify(t));return JSON.parse(n)},n.exports=e},{}],12:[function(t,n){var e=t("./jsonrpc"),r=t("./const"),o=function(){var t,n=[],o=function(n){var r=e.toPayload(n.method,n.params);if(!t)return console.error("provider is not set"),null;var o=t.send(r);return e.isValidResponse(o)?o.result:(console.log(o),null)},a=function(n){t=n},i=function(t,e,r,o){n.push({data:t,id:e,callback:r,uninstall:o})},u=function(t){for(var e=n.length;e--;){var r=n[e];r.id===t&&n.splice(e,1)}},f=function(){n.forEach(function(t){t.uninstall(t.id)}),n=[]},s=function(){n.forEach(function(t){var n=o(t.data);n instanceof Array&&0!==n.length&&t.callback(n)}),setTimeout(s,r.ETH_POLLING_TIMEOUT)};return s(),{send:o,setProvider:a,startPolling:i,stopPolling:u,reset:f}};n.exports=o},{"./const":2,"./jsonrpc":10}],13:[function(t,n){var e=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"}]};n.exports={methods:e}},{}],14:[function(t,n){var e=t("./formatters"),r=function(t){return function(n){return 0===n.indexOf(t)}},o=function(t){return function(n){return t===n}},a=function(){return[{type:r("uint"),format:e.formatInputInt},{type:r("int"),format:e.formatInputInt},{type:r("hash"),format:e.formatInputInt},{type:r("string"),format:e.formatInputString},{type:r("real"),format:e.formatInputReal},{type:r("ureal"),format:e.formatInputReal},{type:o("address"),format:e.formatInputInt},{type:o("bool"),format:e.formatInputBool}]},i=function(){return[{type:r("uint"),format:e.formatOutputUInt},{type:r("int"),format:e.formatOutputInt},{type:r("hash"),format:e.formatOutputHash},{type:r("string"),format:e.formatOutputString},{type:r("real"),format:e.formatOutputReal},{type:r("ureal"),format:e.formatOutputUReal},{type:o("address"),format:e.formatOutputAddress},{type:o("bool"),format:e.formatOutputBool}]};n.exports={prefixedType:r,namedType:o,inputTypes:a,outputTypes:i}},{"./formatters":8}],15:[function(t,n){var e=t("./const"),r=function(t,n){for(var e=!1,r=0;r<t.length&&!e;r++)e=n(t[r]);return e?r-1:-1},o=function(t){var n="",e=0,r=t.length;for("0x"===t.substring(0,2)&&(e=2);r>e;e+=2){var o=parseInt(t.substr(e,2),16);if(0===o)break;n+=String.fromCharCode(o)}return n},a=function(t){for(var n="",e=0;e<t.length;e++){var r=t.charCodeAt(e).toString(16);n+=r.length<2?"0"+r:r}return n},i=function(t,n){n=void 0===n?0:n;for(var e=a(t);e.length<2*n;)e+="00";return"0x"+e},u=function(t){var n=t.indexOf("(");return-1!==n?t.substr(0,n):t},f=function(t){var n=t.indexOf("(");return-1!==n?t.substr(n+1,t.length-1-(n+1)).replace(" ",""):""},s=function(t){return t.filter(function(t){return"function"===t.type})},c=function(t){return t.filter(function(t){return"event"===t.type})},l=function(t){for(var n="string"==typeof t?0===t.indexOf("0x")?parseInt(t.substr(2),16):parseInt(t):t,r=0,o=e.ETH_UNITS;n>3e3&&r<o.length-1;)n/=1e3,r++;for(var a=n.toString().length<n.toFixed(2).length?n.toString():n.toFixed(2),i=function(t,n,e){return n+","+e};;){var u=a;if(a=a.replace(/(\d)(\d\d\d[\.\,])/,i),u===a)break}return a+" "+o[r]};n.exports={findIndex:r,toAscii:o,fromAscii:i,extractDisplayName:u,extractTypeName:f,filterFunctions:s,filterEvents:c,toEth:l}},{"./const":2}],16:[function(t,n){var e=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"}]},r=function(){return[{name:"newFilter",call:"shh_newFilter"},{name:"uninstallFilter",call:"shh_uninstallFilter"},{name:"getMessages",call:"shh_getMessages"}]};n.exports={eth:e,shh:r}},{}],17:[function(t,n){var e=t("./eth"),r=t("./db"),o=t("./shh"),a=t("./watches"),i=t("./filter"),u=t("./utils"),f=t("./requestmanager"),s=function(){return[{name:"sha3",call:"web3_sha3"}]},c=function(t,n){n.forEach(function(n){t[n.name]=function(){var t=Array.prototype.slice.call(arguments),e="function"==typeof n.call?n.call(t):n.call;return g.manager.send({method:e,params:t})}})},l=function(t,n){n.forEach(function(n){var e={};e.get=function(){return g.manager.send({method:n.getter})},n.setter&&(e.set=function(t){return g.manager.send({method:n.setter,params:[t]})}),Object.defineProperty(t,n.name,e)})},p=function(t,n,e,r){g.manager.startPolling({method:t,params:[n]},n,e,r)},m=function(t){g.manager.stopPolling(t)},h={startPolling:p.bind(null,"eth_changed"),stopPolling:m},d={startPolling:p.bind(null,"shh_changed"),stopPolling:m},g={manager:f(),providers:{},toAscii:u.toAscii,fromAscii:u.fromAscii,toDecimal:function(t){return t=t.length>2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:u.toEth,eth:{contractFromAbi:function(t){return function(n){n=n||"0xc6d9d2cd449a754c494264e1809c50e34d64562b";var e=g.eth.contract(n,t);return e.address=n,e}},watch:function(t,n,e,r){return t._isEvent?t(n,e):i(t,h,r)}},db:{},shh:{watch:function(t){return i(t,d)}},setProvider:function(t){g.manager.setProvider(t)},reset:function(){g.manager.reset()}};c(g,s()),c(g.eth,e.methods()),l(g.eth,e.properties()),c(g.db,r.methods()),c(g.shh,o.methods()),c(h,a.eth()),c(d,a.shh()),n.exports=g},{"./db":4,"./eth":5,"./filter":7,"./requestmanager":12,"./shh":13,"./utils":15,"./watches":16}],web3:[function(t,n){var e=t("./lib/web3");e.providers.HttpSyncProvider=t("./lib/httpsync"),e.providers.QtSyncProvider=t("./lib/qtsync"),e.eth.contract=t("./lib/contract"),e.abi=t("./lib/abi"),n.exports=e},{"./lib/abi":1,"./lib/contract":3,"./lib/httpsync":9,"./lib/qtsync":11,"./lib/web3":17}]},{},["web3"]);`
|