UNPKG

ganache-core

Version:

[![npm Version](https://img.shields.io/npm/v/ganache-core.svg)](https://www.npmjs.com/package/ganache-core) [![npm Downloads](https://img.shields.io/npm/dm/ganache-core.svg)](https://www.npmjs.com/package/ganache-core) [![Build Status](https://travis-ci.o

1 lines 128 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Ganache",[],t):"object"==typeof exports?exports.Ganache=t():e.Ganache=t()}(global,(function(){return function(e){var t={};function __webpack_require__(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,__webpack_require__),r.l=!0,r.exports}return __webpack_require__.m=e,__webpack_require__.c=t,__webpack_require__.d=function(e,t,n){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.t=function(e,t){if(1&t&&(e=__webpack_require__(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)__webpack_require__.d(n,r,function(t){return e[t]}.bind(null,r));return n},__webpack_require__.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=36)}([function(e,t,n){const r=n(1);e.exports={buffer:function(e){let t;return"string"==typeof e?(t=0===e.indexOf("0x")?e.slice(2):e,t=t.length%2==1?"0"+t:t,t=Buffer.from(t,"hex")):t=Buffer.isBuffer(e)?e:Buffer.from(e),t},hex:function(e){if("string"==typeof e){if(0===e.indexOf("0x"))return e.trim();e=new r.BN(e)}if("boolean"==typeof e&&(e=e?1:0),"number"==typeof e)e=r.intToHex(e);else{if(null==e)return"0x";"object"==typeof e&&(e=e.toString("hex"))}return r.addHexPrefix(e)},_rpcQuantityHexString:function(e){return e=(e=this.hex(e)).replace(/^(?:0x)(?:0+(.+?))?$/,"0x$1")},rpcQuantityHexString:function(e){return"0x"===(e=this._rpcQuantityHexString(e))&&(e="0x0"),e},rpcQuantityBuffer:function(e){return"0x0"===(e=this._rpcQuantityHexString(e))&&(e="0x"),r.rlp.encode(e)},rpcDataHexString:function(e,t){if("number"==typeof t)e=this.hex(e).replace("0x",""),e=new Array(t-e.length).fill("0").join("")+e;else{if(0===e.length)return"0x";(e=this.hex(e).replace("0x","")).length%2!=0&&(e="0"+e)}return"0x"+e},nullableRpcDataHexString:function(e,t){if(null===e)return null;{const n=this.rpcDataHexString(e,t);return"0x"===n?null:n}},nullableRpcQuantityHexString:function(e,t){if(null===e)return null;{const n=this._rpcQuantityHexString(e,t);return"0x"===n?null:n}},hexWithZeroPadding:function(e){const t=(e=this.hex(e)).replace("0x","");return 1&t.length?"0x0"+t:e},number:function(e){if("number"==typeof e)return e;if("string"==typeof e&&0!==e.indexOf("0x"))return parseInt(e,10);var t=r.toBuffer(e);return r.bufferToInt(t)},rpcError:function(e,t,n){return JSON.stringify({jsonrpc:"2.0",id:e,error:{code:t,message:n}})}}},function(e,t){e.exports=require("ethereumjs-util")},function(e,t){e.exports=require("util")},function(e,t){e.exports=require("async")},function(e,t){e.exports=require("ethereumjs-common")},function(e,t){e.exports=require("web3-provider-engine/subproviders/subprovider.js")},function(e,t,n){var r=n(2).inherits,o=n(0),i=n(44);function RuntimeError(e,t){Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.results={},this.hashes=[],this.combine(e,t)}r(RuntimeError,Error),RuntimeError.prototype.combine=function(e,t){if(e instanceof RuntimeError)for(var n=e,r=Object.keys(n.results),a=0;a<r.length;a++){var s=r[a];this.results[s]=n.results[s],Array.prototype.push.apply(this.hashes,n.hashes)}else{var c=t.results;for(a=0;a<e.length;a++){var u=e[a],l=c[a];if(l.execResult.exceptionError){var h,p=o.hex(u.hash());this.hashes.push(p);var f=l.execResult.returnValue;if(f&&"08c379a0"===f.slice(0,4).toString("hex"))try{h=i.rawDecode(["string"],f.slice(4))[0]}catch(e){}const e=l.execResult.runState;this.results[p]={error:l.execResult.exceptionError.error||l.execResult.exceptionError,program_counter:e&&e.programCounter,return:o.hex(f),reason:h}}}}if(1===this.hashes.length){var d=this.results[this.hashes[0]],g="VM Exception while processing transaction: "+d.error;d.reason&&(g+=" "+d.reason),this.message=g}else{for(g="Multiple VM Exceptions while processing transactions: \n\n",a=0;a<this.hashes.length;a++)g+=(p=this.hashes[a])+": "+(d=this.results[p]).error,d.reason&&(g+=" "+d.reason),g+="\n";this.message=g}},RuntimeError.prototype.count=function(){return Object.keys(this.results).length},RuntimeError.fromResults=function(e,t){var n=new RuntimeError(e,t);return 0===n.count()?null:n},e.exports=RuntimeError},function(e,t){e.exports=require("level-sublevel")},function(e,t){e.exports=require("lodash")},function(e,t){e.exports=require("source-map-support/register")},function(e,t){e.exports=require("ethereumjs-account")},function(e,t,n){const r=n(12).Transaction,o=n(12).FakeTransaction,i=n(4).default,a=n(1),s=n(45),c=a.rlp,u=n(0),l=r.prototype.sign,fakeHash=function(){return null!=this._hash?this._hash:o.prototype.hash.apply(this,arguments)},h=Buffer.from([0]);function fixProps(e,t){e._originals=[];["nonce","gasPrice","gasLimit","value"].forEach(t=>function(e,t,n=32){const r=e._fields.indexOf(t),o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(e,t,{set:i=>{o.set.call(e,i),i=a.toBuffer(i),s(n>=i.length,`The field ${t} must not have more ${n} bytes`),e._originals[r]=i},get:()=>e._originals[r]})}(e,t,32)),e.isFake()&&(Object.defineProperty(e,"from",{enumerable:!0,configurable:!0,get:e.getSenderAddress.bind(e),set:t=>{e._from=t?a.toBuffer(t):null}}),t&&t.from&&(e.from=t.from),e.hash=fakeHash)}e.exports=class e extends r{constructor(t,n=e.types.none,r){t.chainId&&!r&&(r=i.forCustomChain("mainnet",{name:"ganache",networkId:1,chainId:t.chainId,comment:"Local test network",bootstrapNodes:[]},"muirGlacier")),super(void 0,{common:r}),this.ganacheTxCommon=r,this.type=n,fixProps(this,t),function(e,t){if(t){"string"==typeof t&&(t=u.buffer(t)),Buffer.isBuffer(t)&&(t=c.decode(t));const n=e;if(Array.isArray(t)){if(t.length>e._fields.length)throw new Error("wrong number of fields in data");t.forEach((e,t)=>{n[n._fields[t]]=a.toBuffer(e)})}else{if("object"!=(void 0===t?"undefined":typeof t))throw new Error("invalid data");{const r=Object.keys(t);e._fields.forEach((function(e){if(-1!==r.indexOf(e)){let r=t[e];"string"!=typeof r||r.startsWith("0x")||(r="0x"+r),n[e]=r}"gasLimit"===e?-1!==r.indexOf("gas")&&(n.gas=t.gas):"data"===e&&-1!==r.indexOf("input")&&(n.input=t.input)})),!e._chainId&&t&&null!=t.chainId&&(e.raw[n._fields.indexOf("v")]=e._chainId=t.chainId||0)}}}}(this,t)}static get types(){return{none:0,signed:1,fake:2}}static fromJSON(t,n,r,o,s){let c;if(t.to){const e=u.buffer(t.to);c=e.equals(Buffer.from([0]))?a.setLengthLeft(e,20):e}const l=t.data||t.input,h={nonce:a.toBuffer(u.hex(t.nonce)),from:a.toBuffer(u.hex(t.from)),value:a.toBuffer(u.hex(t.value)),gasLimit:a.toBuffer(u.hex(t.gas||t.gasLimit)),gasPrice:a.toBuffer(u.hex(t.gasPrice)),data:l?u.buffer(l):null,to:c,v:a.toBuffer(t.v),r:a.toBuffer(t.r),s:a.toBuffer(t.s)};if(!r&&h.v.length>0){const e=Math.floor((t.v-35)/2);r=i.forCustomChain("mainnet",{name:"ganache",networkId:o,chainId:e>=0?e:1,comment:"Local test network",bootstrapNodes:[]},s)}const p=new e(h,n,r);return p._hash=t.hash?u.buffer(t.hash):null,p}encode(){return{hash:u.nullableRpcDataHexString(this.hash()),nonce:u.nullableRpcQuantityHexString(this.nonce)||"0x",from:u.rpcDataHexString(this.from),to:u.nullableRpcDataHexString(this.to),value:u.nullableRpcQuantityHexString(this.value),gas:u.nullableRpcQuantityHexString(this.gasLimit),gasPrice:u.nullableRpcQuantityHexString(this.gasPrice),data:this.data?this.data.toString("hex"):null,v:u.nullableRpcQuantityHexString(this.v),r:u.nullableRpcQuantityHexString(this.r),s:u.nullableRpcQuantityHexString(this.s),_type:this.type,_options:{hardfork:this.ganacheTxCommon.hardfork(),chainId:this.ganacheTxCommon.chainId(),networkId:this.ganacheTxCommon.networkId()}}}isFake(){return(this.type&e.types.fake)===e.types.fake}isSigned(){return(this.type&e.types.signed)===e.types.signed}validateNonce(e){let t;return t=this.isSigned()&&0===this.nonce.length?h:this.nonce,t.equals(e)}sign(){l.apply(this,arguments),this.type|=e.types.signed}toJsonRpc(e){const t=this.hash();let n=null;for(let r=0,o=e.transactions,i=o.length;r<i;r++)if(o[r].hash().equals(t)){n=r;break}return{hash:u.nullableRpcDataHexString(t),nonce:u.rpcQuantityHexString(this.nonce),blockHash:u.nullableRpcDataHexString(e.hash()),blockNumber:u.nullableRpcQuantityHexString(e.header.number),transactionIndex:u.nullableRpcQuantityHexString(n),from:u.rpcDataHexString(this.from),to:u.nullableRpcDataHexString(this.to),value:u.rpcQuantityHexString(this.value),gas:u.rpcQuantityHexString(this.gasLimit),gasPrice:u.rpcQuantityHexString(this.gasPrice),input:u.rpcDataHexString(this.data),v:u.nullableRpcQuantityHexString(this.v),r:u.nullableRpcQuantityHexString(this.r),s:u.nullableRpcQuantityHexString(this.s)}}}},function(e,t){e.exports=require("ethereumjs-tx")},function(e,t){e.exports=require("ethereumjs-block")},function(e,t,n){var r=n(0);function Log(e){var t=this;Object.keys(e).forEach((function(n){t[n]=e[n]}))}Log.prototype.toJSON=function(){return{logIndex:r.rpcQuantityHexString(this.logIndex),transactionIndex:r.rpcQuantityHexString(this.transactionIndex),transactionHash:r.rpcDataHexString(this.transactionHash),blockHash:r.rpcDataHexString(this.block.hash()),blockNumber:r.rpcQuantityHexString(this.block.header.number),address:r.rpcDataHexString(this.address),data:r.rpcDataHexString(this.data),topics:this.topics,type:"mined",removed:this.removed||!1}},e.exports=Log},function(e,t,n){var r=n(0);function Receipt(e,t,n,r,o,i,a,s){this.tx=e,this.block=t,this.logs=n,this.gasUsed=r,this.cumulativeGasUsed=o,this.contractAddress=i,this.status=a,this.logsBloom=s,this.transactionIndex=0,this.txHash=e.hash();for(var c=0;c<t.transactions.length;c++){if(t.transactions[c].hash().equals(this.txHash)){this.transactionIndex=c;break}}}Receipt.prototype.toJSON=function(){return{transactionHash:r.rpcDataHexString(this.txHash),transactionIndex:r.rpcQuantityHexString(this.transactionIndex),blockHash:r.rpcDataHexString(this.block.hash()),blockNumber:r.rpcQuantityHexString(this.block.header.number),from:r.rpcDataHexString(this.tx.from),to:r.nullableRpcDataHexString(this.tx.to),gasUsed:r.rpcQuantityHexString(this.gasUsed),cumulativeGasUsed:r.rpcQuantityHexString(this.cumulativeGasUsed),contractAddress:null!=this.contractAddress?r.rpcDataHexString(this.contractAddress):null,logs:this.logs.map((function(e){return e.toJSON()})),status:r.rpcQuantityHexString(this.status),logsBloom:r.rpcDataHexString(this.logsBloom),v:r.rpcQuantityHexString(this.tx.v),r:r.rpcQuantityHexString(this.tx.r),s:r.rpcQuantityHexString(this.tx.s)}},e.exports=Receipt},function(e,t){class n extends Error{constructor(e,t,n){super("LevelUpArrayAdapter named '"+e+"' index out of range: index "+t+"; length: "+n),this.name=`${this.constructor.name}:${e}`,this.type=e}}e.exports={LevelUpOutOfRangeError:n,BlockOutOfRangeError:class extends n{constructor(e,t){super("blocks",e,t)}}}},function(e,t){e.exports=require("events")},function(e,t,n){"use strict";var r=n(77).version,o=n(19),i=n(78),a=n(32),s=n(33),c=n(93),u=n(94),l=n(21),Web3=function(){var e=this;o.packageInit(this,arguments),this.version=r,this.utils=l,this.eth=new i(this),this.shh=new c(this),this.bzz=new u(this);var t=this.setProvider;this.setProvider=function(n,r){return t.apply(e,arguments),e.eth.setRequestManager(e._requestManager),e.shh.setRequestManager(e._requestManager),e.bzz.setProvider(n),!0}};Web3.version=r,Web3.utils=l,Web3.modules={Eth:i,Net:a,Personal:s,Shh:c,Bzz:u},o.addProviders(Web3),e.exports=Web3},function(e,t){e.exports=require("web3-core")},function(e,t){e.exports=require("underscore")},function(e,t){e.exports=require("web3-utils")},function(e,t,n){n(9);const r=n(37),o=n(38),i=n(39),a=n(40),s=n(41),c=n(42),u=n(100),l=n(6),h=n(17),p=n(8);function Provider(e){const t=this;h.call(this),this.options=e=t._applyDefaultOptions(e||{});const n=new c(e,this);this.engine=new r({blockTracker:new u({blockchain:n.state.blockchain})});const l=new o;this.engine.manager=n,this.engine.addProvider(new i),this.engine.addProvider(new a),this.engine.addProvider(l),this.engine.addProvider(new s),this.engine.addProvider(n),this.engine.setMaxListeners(100),this.engine.start(),this.manager=n,this.sendAsync=this.send.bind(this),this.send=this.send.bind(this),this.close=this.close.bind(this),this._queueRequest=this._queueRequest.bind(this),this._processRequestQueue=this._processRequestQueue.bind(this),l.on("data",(function(e,n){t.emit("data",e,n)}))}const f={_chainId:1,_chainIdRpc:1337,vmErrorsOnRPCResponse:!0,verbose:!1,asyncRequestProcessing:!1,logger:{log:function(){}}};Provider.prototype=Object.create(h.prototype),Provider.prototype.constructor=Provider,Provider.prototype._applyDefaultOptions=function(e){return p.merge({},f,e)},Provider.prototype.send=function(e,t){if("function"!=typeof t)throw new Error("No callback provided to provider's send function. As of web3 1.0, provider.send is no longer synchronous and must be passed a callback as its final argument.");const n=this,externalize=function(e){return p.cloneDeep(e)};e=Array.isArray(e)?e.map(externalize):externalize(e);const intermediary=function(r,o){let i;if(o=p.cloneDeep(o),Array.isArray(o)){i=[];for(let t=0;t<o.length;t++)i.push(n.reportErrorInResponse(e[t],r,o[t]))}else i=n.reportErrorInResponse(e,r,o);n.options.verbose&&n.options.logger.log(" < "+JSON.stringify(i,null,2).split("\n").join("\n < ")),process.nextTick(()=>t(i.error?r:null,i))};n.options.verbose&&n.options.logger.log(" > "+JSON.stringify(e,null,2).split("\n").join("\n > ")),n.options.asyncRequestProcessing?n.engine.sendAsync(e,intermediary):n._queueRequest(e,intermediary)},Provider.prototype.close=function(e){this.manager.state.stopMining(),this.manager.state.blockchain.close(e),this.engine.stop()},Provider.prototype._queueRequest=function(e,t){this._requestQueue||(this._requestQueue=[]),this._requestQueue.push({payload:e,callback:t}),setImmediate(this._processRequestQueue)},Provider.prototype._processRequestQueue=function(){const e=this;if(e._requestInProgress)return;e._requestInProgress=!0;const t=e._requestQueue.shift();t?e.engine.sendAsync(t.payload,(n,r)=>{e._requestQueue.length>0&&setImmediate(e._processRequestQueue),t.callback(n,r),e._requestInProgress=!1}):(e._requestInProgress=!1,e._requestQueue.length>0&&setImmediate(e._processRequestQueue))},Provider.prototype.cleanUpErrorObject=function(e,t){if(!e||!t.error)return t;const n={error:{data:{}}};return e.message?(n.error.message=e.message,n.error.data.stack=e.stack,n.error.data.name=e.name,"code"in e&&(n.error.code=e.code)):t.error||(n.error={message:e.toString()}),p.merge(t,n)};const d=new Set(["eth_sendTransaction","eth_sendRawTransaction","personal_sendTransaction"]);Provider.prototype._isTransactionRequest=function(e){return d.has(e.method)},Provider.prototype.reportErrorInResponse=function(e,t,n){const r=this;return t?(r._isTransactionRequest(e)&&t instanceof l&&(n.result=t.hashes[0],r.options.vmErrorsOnRPCResponse?(n.error.data||(n.error.data={}),n.error.data[t.hashes[0]]=t.results[t.hashes[0]]):delete n.error),"eth_call"===e.method&&t instanceof l&&(r.options.vmErrorsOnRPCResponse?(n.error.data||(n.error.data={}),n.error.data[t.hashes[0]]=t.results[t.hashes[0]]):(n.result=t.results[t.hashes[0]].return||"0x",delete n.error)),r.cleanUpErrorObject(t,n)):n},e.exports=Provider},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=n(48).Buffer,i=n(1),a=n(24),s=n(49),c=n(50),u=n(51),l=n(52);function assert(e,t){if(!e)throw new Error(t||"Assertion failed")}function runCipherBuffer(e,t){return o.concat([e.update(t),e.final()])}var Wallet=function(e,t){if(e&&t)throw new Error("Cannot supply both a private and a public key to the constructor");if(e&&!i.isValidPrivate(e))throw new Error("Private key does not satisfy the curve requirements (ie. it is invalid)");if(t&&!i.isValidPublic(t))throw new Error("Invalid public key");this._privKey=e,this._pubKey=t};Object.defineProperty(Wallet.prototype,"privKey",{get:function(){return assert(this._privKey,"This is a public key only wallet"),this._privKey}}),Object.defineProperty(Wallet.prototype,"pubKey",{get:function(){return this._pubKey||(this._pubKey=i.privateToPublic(this.privKey)),this._pubKey}}),Wallet.generate=function(e){if(!e)return new Wallet(s(32));for(var t=new i.BN("088f924eeceeda7fe92e1f5b0fffffffffffffff",16);;){var n=s(32);if(new i.BN(i.privateToAddress(n)).lte(t))return new Wallet(n)}},Wallet.generateVanityAddress=function(e){for("object"!==(void 0===e?"undefined":r(e))&&(e=new RegExp(e));;){var t=s(32),n=i.privateToAddress(t);if(e.test(n.toString("hex")))return new Wallet(t)}},Wallet.prototype.getPrivateKey=function(){return this.privKey},Wallet.prototype.getPrivateKeyString=function(){return i.bufferToHex(this.getPrivateKey())},Wallet.prototype.getPublicKey=function(){return this.pubKey},Wallet.prototype.getPublicKeyString=function(){return i.bufferToHex(this.getPublicKey())},Wallet.prototype.getAddress=function(){return i.publicToAddress(this.pubKey)},Wallet.prototype.getAddressString=function(){return i.bufferToHex(this.getAddress())},Wallet.prototype.getChecksumAddressString=function(){return i.toChecksumAddress(this.getAddressString())},Wallet.prototype.toV3=function(e,t){assert(this._privKey,"This is a public key only wallet");var n,r=(t=t||{}).salt||s(32),l=t.iv||s(16),h=t.kdf||"scrypt",p={dklen:t.dklen||32,salt:r.toString("hex")};if("pbkdf2"===h)p.c=t.c||262144,p.prf="hmac-sha256",n=a.pbkdf2Sync(o.from(e),r,p.c,p.dklen,"sha256");else{if("scrypt"!==h)throw new Error("Unsupported kdf");p.n=t.n||262144,p.r=t.r||8,p.p=t.p||1,n=c(o.from(e),r,p.n,p.r,p.p,p.dklen)}var f=a.createCipheriv(t.cipher||"aes-128-ctr",n.slice(0,16),l);if(!f)throw new Error("Unsupported cipher");var d=runCipherBuffer(f,this.privKey),g=i.keccak256(o.concat([n.slice(16,32),o.from(d,"hex")]));return{version:3,id:u({random:t.uuid||s(16)}),address:this.getAddress().toString("hex"),crypto:{ciphertext:d.toString("hex"),cipherparams:{iv:l.toString("hex")},cipher:t.cipher||"aes-128-ctr",kdf:h,kdfparams:p,mac:g.toString("hex")}}},Wallet.prototype.getV3Filename=function(e){return["UTC--",(e?new Date(e):new Date).toJSON().replace(/:/g,"-"),"--",this.getAddress().toString("hex")].join("")},Wallet.prototype.toV3String=function(e,t){return JSON.stringify(this.toV3(e,t))},Wallet.fromPublicKey=function(e,t){return t&&(e=i.importPublic(e)),new Wallet(null,e)},Wallet.fromExtendedPublicKey=function(e){return assert("xpub"===e.slice(0,4),"Not an extended public key"),e=l.decode(e).slice(45),Wallet.fromPublicKey(e,!0)},Wallet.fromPrivateKey=function(e){return new Wallet(e)},Wallet.fromExtendedPrivateKey=function(e){assert("xprv"===e.slice(0,4),"Not an extended private key");var t=l.decode(e);return assert(0===t[45],"Invalid extended private key"),Wallet.fromPrivateKey(t.slice(46))},Wallet.fromV1=function(e,t){assert("string"==typeof t);var n="object"===(void 0===e?"undefined":r(e))?e:JSON.parse(e);if("1"!==n.Version)throw new Error("Not a V1 wallet");if("scrypt"!==n.Crypto.KeyHeader.Kdf)throw new Error("Unsupported key derivation scheme");var s=n.Crypto.KeyHeader.KdfParams,u=c(o.from(t),o.from(n.Crypto.Salt,"hex"),s.N,s.R,s.P,s.DkLen),l=o.from(n.Crypto.CipherText,"hex");if(i.keccak256(o.concat([u.slice(16,32),l])).toString("hex")!==n.Crypto.MAC)throw new Error("Key derivation failed - possibly wrong passphrase");var h=runCipherBuffer(a.createDecipheriv("aes-128-cbc",i.keccak256(u.slice(0,16)).slice(0,16),o.from(n.Crypto.IV,"hex")),l);return new Wallet(h)},Wallet.fromV3=function(e,t,n){assert("string"==typeof t);var s,u,l="object"===(void 0===e?"undefined":r(e))?e:JSON.parse(n?e.toLowerCase():e);if(3!==l.version)throw new Error("Not a V3 wallet");if("scrypt"===l.crypto.kdf)u=l.crypto.kdfparams,s=c(o.from(t),o.from(u.salt,"hex"),u.n,u.r,u.p,u.dklen);else{if("pbkdf2"!==l.crypto.kdf)throw new Error("Unsupported key derivation scheme");if("hmac-sha256"!==(u=l.crypto.kdfparams).prf)throw new Error("Unsupported parameters to PBKDF2");s=a.pbkdf2Sync(o.from(t),o.from(u.salt,"hex"),u.c,u.dklen,"sha256")}var h=o.from(l.crypto.ciphertext,"hex");if(i.keccak256(o.concat([s.slice(16,32),h])).toString("hex")!==l.crypto.mac)throw new Error("Key derivation failed - possibly wrong passphrase");var p=runCipherBuffer(a.createDecipheriv(l.crypto.cipher,s.slice(0,16),o.from(l.crypto.cipherparams.iv,"hex")),h);return new Wallet(p)},Wallet.fromEthSale=function(e,t){assert("string"==typeof t);var n="object"===(void 0===e?"undefined":r(e))?e:JSON.parse(e),s=o.from(n.encseed,"hex"),c=a.pbkdf2Sync(t,t,2e3,32,"sha256").slice(0,16),u=runCipherBuffer(a.createDecipheriv("aes-128-cbc",c,s.slice(0,16)),s.slice(16)),l=new Wallet(i.keccak256(u));if(l.getAddress().toString("hex")!==n.ethaddr)throw new Error("Decoded key mismatch - possibly wrong passphrase");return l},e.exports=Wallet},function(e,t){e.exports=require("crypto")},function(e,t,n){var r=n(0),o=n(10).default,i=n(13),a=n(14),s=n(15),c=n(55).default,u=n(4).default,l=n(6),h=n(26),p=n(1),f=n(3),d=n(56),g=n(57),m=n(17),b=n(70),k=n(8),y=n(2).promisify;const v=p.BN;function BlockchainDouble(e){if(m.apply(this),this.options=e=this._applyDefaultOptions(e||{}),this.logger=e.logger||console,this.data=new g(e),null!=e.trie&&null!=e.db_path)throw new Error("Can't initialize a TestRPC with a db and a custom trie.");this.pending_transactions=[],this.blockGasLimit=e.gasLimit,this.defaultTransactionGasLimit=e.defaultTransactionGasLimit,this.timeAdjustment=0}const x={gasLimit:"0x6691b7",defaultTransactionGasLimit:"0x15f90",time:null,debug:!1,hardfork:"muirGlacier",allowUnlimitedContractSize:!1};BlockchainDouble.prototype=Object.create(m.prototype),BlockchainDouble.prototype.constructor=BlockchainDouble,BlockchainDouble.prototype._applyDefaultOptions=function(e){return k.merge(e,x,Object.assign({},e))},BlockchainDouble.prototype.initialize=function(e,t){var n=this;this.data.initialize((function(r){if(r)return t(r);n.latestBlock((function(r,o){if(r)return t(r);var i=n.options,a=null;if(o&&(a=o.header.stateRoot),n.stateTrie=n.createStateTrie(n.data.trie_db,a),n.vm=i.vm||n.createVMFromStateTrie(n.stateTrie,!0),i.time&&n.setTime(i.time),o)return n.emit("block",o),t();n.createGenesisBlock((function(r,o){if(r)return t(r);e=e||[],n.vm.stateManager.checkpoint(()=>{f.eachSeries(e,(function(e,t){n.vm.stateManager.putAccount(p.toBuffer(e.address),e.account,t)}),(function(e){if(e)return t(e);n.vm.stateManager.commit(()=>{n.putBlock(o,[],[],t)})}))})}))}))}))},BlockchainDouble.prototype.createVMFromStateTrie=function(e,t){const n=this,o=u.forCustomChain("mainnet",{name:"ganache",networkId:n.options.network_id||n.forkVersion,chainId:n.options._chainId,comment:"Local test network",bootstrapNodes:[]},n.options.hardfork),i=new c({state:e,common:o,blockchain:{getBlock:function(e,t){try{e=r.number(e)}catch(e){}n.getBlock(e,t)}},activatePrecompiles:t||!1,allowUnlimitedContractSize:n.options.allowUnlimitedContractSize});return!0===n.options.debug&&i.on("step",(function(e){var t=e.opcode.name,o=e.opcode.in;if(o){var i=e.stack.slice(-o).map(e=>r.hex(e)).join(" ");n.logger.log(`${t} ${i}`)}else n.logger.log(t)})),i},BlockchainDouble.prototype.createStateTrie=function(e,t){return new h(e,t)},BlockchainDouble.prototype.createGenesisBlock=function(e){this.createBlock(e)},BlockchainDouble.prototype.latestBlock=function(e){this.data.blocks.last((function(t,n){if(t)return e(t);e(null,n)}))},BlockchainDouble.prototype.getEffectiveBlockNumber=function(e,t){return"string"!=typeof e&&(e=r.hex(e)),e.indexOf("0x")>=0?t(null,r.number(e)):"latest"===e||"pending"===e?this.getHeight(t):"earliest"===e?t(null,0):void 0},BlockchainDouble.prototype.getBlock=function(e,t){var n=this;if("string"!=typeof e&&(e=r.hex(e)),e.indexOf("0x")>=0){var o=e;if(!(o.length>40))return this.data.blocks.get(r.number(o),t);this.data.blockHashes.get(r.hex(o),(function(e,r){return e?t(e):n.data.blocks.get(r,t)}))}else{if("latest"===e||"pending"===e)return this.latestBlock(t);if("earliest"===e)return this.data.blocks.first(t);process.nextTick(t,new Error('Invalid `blockNumber`: "'+e+'"'))}},BlockchainDouble.prototype.putBlock=function(e,t,n,o){var i=this;e.header.stateRoot=this.stateTrie.root,this.data.blocks.length((function(a,s){if(a)return o(a);var c=[i.data.blocks.push.bind(i.data.blocks,e),i.data.blockLogs.push.bind(i.data.blockLogs,t),i.data.blockHashes.set.bind(i.data.blockHashes,r.hex(e.hash()),s)];e.transactions.forEach((function(e,t){var o=r.hex(e.hash());c.push(i.data.transactions.set.bind(i.data.transactions,o,e),i.data.transactionReceipts.set.bind(i.data.transactionReceipts,o,n[t]))})),f.parallel(c,(t,n)=>{t||i.emit("block",e),o(t,n)})}))},BlockchainDouble.prototype.popBlock=function(e){var t=this;this.data.blocks.last((function(n,o){if(n)return e(n);if(null==o)return e(null,null);var i=[],a=r.hex(o.hash());o.transactions.forEach((function(e){var n=r.hex(e.hash());i.push(t.data.transactions.del.bind(t.data.transactions,n),t.data.transactionReceipts.del.bind(t.data.transactionReceipts,n))})),i.push(t.data.blockLogs.pop.bind(t.data.blockLogs),t.data.blockHashes.del.bind(t.data.blockHashes,a),t.data.blocks.pop.bind(t.data.blocks)),f.series(i,(function(n){if(n)return e(n);t.data.blocks.last((function(n,r){if(n)return e(n);t.vm.stateManager.setStateRoot(r.header.stateRoot,(function(t){e(t,o)}))}))}))}))},BlockchainDouble.prototype.clearPendingTransactions=function(){this.pending_transactions=[]},BlockchainDouble.prototype.createBlock=function(e,t,n){var o=this;"function"==typeof e?(n=e,e=null,t=!1):"function"==typeof t&&(n=t,t=!1);var a=new i;!function(t){if(e)return t(null,e);o.latestBlock(t)}((function(e,i){if(e)return n(e);if(a.header.gasLimit=o.blockGasLimit,null!=i&&t)a.header.number=i.header.number,a.header.timestamp=i.header.timestamp,a.header.parentHash=i.header.parentHash;else{var s=null!=i?r.number(i.header.number):-1;a.header.number=r.hex(s+1),a.header.timestamp=r.hex(o.currentTime()),null!=i&&(a.header.parentHash=r.hex(i.hash()))}n(null,a)}))},BlockchainDouble.prototype.getQueuedNonce=function(e,t){var n=null,i=r.buffer(e);if(this.pending_transactions.forEach((function(e){if(e.from.equals(i)){var t=new v(e.nonce);(null===n||t.gt(n))&&(n=t)}})),null!=n)return t(null,n.iaddn(1).toArrayLike(Buffer));this.stateTrie.get(i,(function(e,n){if(e)return t(e);var r=new o(n);t(null,0===r.nonce.length?Buffer.from([0]):r.nonce)}))},BlockchainDouble.prototype.queueTransaction=function(e){this.pending_transactions.push(e)},BlockchainDouble.prototype.sortByPriceAndNonce=function(){var e={};this.pending_transactions.forEach(t=>{const n=t.from.toString("hex"),r=e[n];r?r.push(t):e[n]=[t]});var nonceSort=function(e,t){return parseInt(r.hex(e.nonce),16)-parseInt(r.hex(t.nonce),16)};Object.keys(e).forEach(t=>{e[t].sort(nonceSort)});var t=new d((function(e,t){return parseInt(r.hex(t.gasPrice),16)-parseInt(r.hex(e.gasPrice),16)}));Object.keys(e).forEach(n=>{t.push(e[n].shift())});const n=[];for(;t.size()>0;){const r=t.pop(),o=r.from.toString("hex");e[o].length>0&&t.push(e[o].shift()),n.push(r)}this.pending_transactions=n},BlockchainDouble.prototype.getReadyCall=function(e,t,n,r){const readyCall=(e,n,o)=>{if(n)return r(n);this.createBlock(o,t,(t,n)=>{if(t)return r(t);n.transactions.push(e),n.header.gasLimit=e.gasLimit;const i={tx:e,block:n,skipBalance:!0,skipNonce:!0};r(null,o.header.stateRoot,i)})};"latest"===n?this.latestBlock(readyCall.bind(null,e)):this.getBlock(n,readyCall.bind(null,e))},BlockchainDouble.prototype.readyCall=function(e,t,n,r){this.getReadyCall(e,t,n,(e,t,n)=>{if(e)return void r(e);const o=this.createStateTrie(this.data.trie_db,t,{persist:!1}),i=this.createVMFromStateTrie(o);r(null,i,n)})},BlockchainDouble.prototype.processCall=function(e,t,n){this.readyCall(e,!0,t,async(t,r,o)=>{if(t)return void n(t);const i=await r.runTx(o).catch(e=>({vmerr:e}));let a=i.vmerr;if(a&&a instanceof Error==!1&&(a=new Error("VM error: "+a)),a)return n(a,t);a=l.fromResults([e],{results:[i]}),n(a,i)})},BlockchainDouble.prototype.estimateGas=function(e,t,n){this.getReadyCall(e,!1,t,(e,t,r)=>{if(e)return void n(e);b(()=>{const e=this.createStateTrie(this.data.trie_db,t);return this.createVMFromStateTrie(e)},r,n)})},BlockchainDouble.prototype.processBlock=async function(e,t,n,o){"function"==typeof n&&(o=n,n=!0);const i=await e.runBlock({block:t,generate:!0,skipBlockValidation:!0}).catch(e=>({vmerr:e}));let c=i.vmerr;if(c&&c instanceof Error==!1&&(c=new Error("VM error: "+c)),c)return void o(c);c=l.fromResults(t.transactions,i);var u=[],f=[],d=0;i.results.forEach((function(e){d+=r.number(e.gasUsed)})),t.header.gasUsed=p.toBuffer(r.hex(d));const g=new h,m=new h,b=[],putInTrie=(e,t,n)=>y(e.put.bind(e))(t,n);for(var k=0;k<i.receipts.length;k++){var v=i.results[k],x=i.receipts[k],_=t.transactions[k],w=_.hash(),B=[];if(void 0===v.execResult.exceptionError)for(var S=0;S<x.logs.length;S++){for(var T=x.logs[S],A=r.hex(T[0]),C=[],D=0;D<T[1].length;D++)C.push(r.hex(T[1][D]));var F=r.hex(T[2]),E=new a({logIndex:r.hex(S),transactionIndex:r.hex(k),transactionHash:w,block:t,address:A,data:F,topics:C,type:"mined"});u.push(E),B.push(E)}const e=new s(_,t,B,v.gasUsed.toArrayLike(Buffer),x.gasUsed,v.createdAddress,x.status,r.hex(x.bitvector));f.push(e);const n=[x.status,x.gasUsed,x.bitvector,x.logs],o=p.rlp.encode(n),c=p.rlp.encode(k);b.push(putInTrie(g,c,_.serialize())),b.push(putInTrie(m,c,o))}function done(e){if(e)return o(e);o(c,t.transactions,i)}await Promise.all(b),t.header.transactionsTrie=p.toBuffer(g.root),t.header.receiptTrie=p.toBuffer(m.root),n?this.putBlock(t,u,f,done):done()},BlockchainDouble.prototype.processNextBlock=function(e,t){var n=this;"function"==typeof e&&(t=e,e=void 0),n.sortByPriceAndNonce();for(var o=[],i=0,a=r.number(n.blockGasLimit);n.pending_transactions.length>0;){var s=n.pending_transactions[0],c=r.number(s.gasLimit);if(!(i+c<=a))break;i+=c,n.pending_transactions.shift(),o.push(s)}if(0===o.length&&n.pending_transactions.length>0){return t("Unexpected error condition: next transaction exceeds block gas limit")}this.createBlock((function(i,a){if(i)return t(i);e&&(n.data.blocks.last((function(t,o){t||o&&r.number(o.header.timestamp)>e&&n.logger.log("Waring: Setting the block timestamp ("+e+") that is earlier than the parent block one.")})),a.header.timestamp=r.hex(e),n.setTime(new Date(1e3*e))),Array.prototype.push.apply(a.transactions,o),n.processBlock(n.vm,a,!0,t)}))},BlockchainDouble.prototype.processTransactionTrace=async function(e,t,n){const o=this,i=r.hex(e);let a,s="",c=null;const u={currentDepth:-1,stack:[]},l={gas:0,returnValue:"",structLogs:[]};function stepListener(e,n){const i=r.number(e.gasLeft),s=r.number(c.gasLimit)-i-l.gas;l.gas+=s;let h=null;if(!t.disableMemory&&(h=Buffer.from(e.memory).toString("hex"),h=h.match(/.{1,64}/g)||[],h.length>0)){const e=h[h.length-1];e.length<64&&(h[h.length-1]=e+new Array(64-e.length+1).join("0"))}let p=null;t.disableStack||(p=e.stack.map(e=>r.rpcDataHexString(e,64).replace("0x","")));let f={depth:e.depth,error:"",gas:i,gasCost:0,memory:h,op:e.opcode.name,pc:e.pc,stack:p,storage:null};l.structLogs.length&&(l.structLogs[l.structLogs.length-1].gasCost=s),t.disableStorage?(l.structLogs.push(f),n()):f=o.processStorageTrace(f,u,e,a,(function(e,t){if(e)return n(e);l.structLogs.push(t),n()}))}this.getTransactionReceipt(i,(function(e,t){if(e)return n(e);if(!t)return n(new Error("Unknown transaction "+i));const u=t.block;o.getBlock(u.header.parentHash,(function(e,t){if(e)return n(e);var h=o.createStateTrie(o.data.trie_db,t.header.stateRoot,{forkBlockNumber:r.number(t.header.number)});a=o.createVMFromStateTrie(h),o.createBlock(t,!1,(function(e,t){if(e)return n(e);t.header.timestamp=u.header.timestamp;for(var h=0;h<u.transactions.length;h++){var p=u.transactions[h];if(t.transactions.push(p),r.hex(p.hash())===i)break}function beforeTxListener(e){c=e,s=r.hex(e.hash()),s===i&&a.on("step",stepListener)}function afterTxListener(){s===i&&removeListeners()}function removeListeners(){a.removeListener("step",stepListener),a.removeListener("beforeTx",beforeTxListener),a.removeListener("afterTx",afterTxListener)}a.on("beforeTx",beforeTxListener),a.on("afterTx",afterTxListener),a.stateManager._cache.flush=e=>e(),o.processBlock(a,t,!1,(function(e){e&&0===e.message.indexOf("VM Exception")&&(e=null),removeListeners(),n(e,l)}))}))}))}))},BlockchainDouble.prototype.processStorageTrace=function(e,t,n,o,i){var a,s,c=n.opcode.name;switch(t.currentDepth>n.depth&&t.stack.pop(),t.currentDepth<n.depth&&t.stack.push({}),t.currentDepth=n.depth,c){case"SSTORE":{const o=n.stack,c=o.length;a=r.rpcDataHexString(o[c-1],64).replace("0x",""),s=r.rpcDataHexString(o[c-2],64).replace("0x",""),e.storage=Object.assign({},t.stack[t.currentDepth]),i(null,e),t.stack[t.currentDepth][a]=s}break;case"SLOAD":{const c=n.stack;a=r.rpcDataHexString(c[c.length-1],64).replace("0x",""),o.stateManager.getContractStorage(n.address,Buffer.from(a,"hex"),(function(n,o){if(n)return i(n);s=r.rpcDataHexString(o,64).replace("0x",""),t.stack[t.currentDepth][a]=s,e.storage=Object.assign({},t.stack[t.currentDepth]),i(null,e)}))}break;default:e.storage=Object.assign({},t.stack[t.currentDepth]),i(null,e)}},BlockchainDouble.prototype.getAccount=function(e,t,n){var r=this;this.getBlock(t,(function(t,i){if(t)return n(t);var a=r.stateTrie,s=a.root;r.stateTrie.root=i.header.stateRoot,a.get(p.toBuffer(e),(function(e,t){if(a.root=s,e)return n(e);var r=new o(t);n(null,r)}))}))},BlockchainDouble.prototype.getNonce=function(e,t,n){this.getAccount(e,t,(function(e,t){if(e)return n(e);n(null,t.nonce)}))},BlockchainDouble.prototype.getBalance=function(e,t,n){this.getAccount(e,t,(function(e,t){if(e)return n(e);n(null,t.balance)}))},BlockchainDouble.prototype.getStorage=function(e,t,n,r){var i=this;this.getBlock(n,(function(n,a){if(n)return r(n);var s=i.stateTrie,c=s.root;i.stateTrie.root=a.header.stateRoot,s.get(p.toBuffer(e),(function(e,n){if(null!=e)return s.root=c,r(e);var i=new o(n);s.root=i.stateRoot,s.get(p.setLengthLeft(p.toBuffer(t),32),(function(e,t){if(s.root=c,null!=e)return r(e);r(null,t)}))}))}))},BlockchainDouble.prototype.getCode=function(e,t,n){var r=this;this.getBlock(t,(function(t,i){if(t)return n(t);var a=r.stateTrie,s=a.root;r.stateTrie.root=i.header.stateRoot,a.get(p.toBuffer(e),(function(e,t){if(null!=e)return a.root=s,n(e);new o(t).getCode(a,(function(e,t){if(a.root=s,e)return n(e);n(null,t)}))}))}))},BlockchainDouble.prototype.getTransaction=function(e,t){e=r.hex(e),this.data.transactions.get(e,(function(e,n){if(e)return e.notFound?t(null,null):t(e);t(null,n)}))},BlockchainDouble.prototype.getTransactionReceipt=function(e,t){e=r.hex(e);const n=this.pending_transactions;for(var o=0;o<n.length;o++){if(e===r.hex(n[o].hash()))return t(null,{tx:n[o]})}this.data.transactionReceipts.get(e,(function(e,n){if(e)return e.notFound?t(null,null):t(e);t(e,n)}))},BlockchainDouble.prototype.getBlockLogs=function(e,t){var n=this;this.getEffectiveBlockNumber(e,(function(e,r){if(e)return t(e);n.data.blockLogs.get(r,t)}))},BlockchainDouble.prototype.getHeight=function(e){this.data.blocks.length((function(t,n){if(t)return e(t);e(null,n-1)}))},BlockchainDouble.prototype.currentTime=function(){return((new Date).getTime()/1e3|0)+this.timeAdjustment},BlockchainDouble.prototype.increaseTime=function(e){return e<0&&(e=0),this.timeAdjustment+=e,this.timeAdjustment},BlockchainDouble.prototype.setTime=function(e){var t=(new Date).getTime()/1e3|0,n=e.getTime()/1e3|0;this.timeAdjustment=n-t},BlockchainDouble.prototype.close=function(e){this.data.close(e)},e.exports=BlockchainDouble},function(e,t){e.exports=require("merkle-patricia-tree")},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("tmp")},function(e,t,n){var r=n(11),o=n(4).default,i=n(1);e.exports={encode:function(e,t){t(null,e.encode())},decode:function(e,t){const n={hash:e.hash,nonce:e.nonce,value:e.value,to:e.to,from:e.from,gasLimit:e.gas||e.gasLimit,gasPrice:e.gasPrice,data:e.data,v:e.v,r:e.r,s:e.s},a=i.bufferToInt(n.v);let s=Math.floor((a-35)/2);s<0&&(s=0);const c={name:"ganache",chainId:s,networkId:1,comment:"Local test network"};let u="muirGlacier";e._options&&(u=e._options.hardfork,c.chainId=e._options.chainId,c.networkId=e._options.networkId);const l=o.forCustomChain("mainnet",c,u),h=void 0===e._type?r.types.fake:e._type;t(null,r.fromJSON(n,h,l))}}},function(e,t){e.exports=require("web3-core-helpers")},function(e,t){e.exports=require("web3-core-method")},function(e,t){e.exports=require("web3-net")},function(e,t){e.exports=require("web3-eth-personal")},function(e,t,n){function TXRejectedError(e){Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.message=e}(0,n(2).inherits)(TXRejectedError,Error),e.exports=TXRejectedError},function(e,t,n){var r=n(0);e.exports={toJSON:function(e,t){return{number:r.rpcQuantityHexString(e.header.number),hash:r.hex(e.hash()),parentHash:r.hex(e.header.parentHash),mixHash:r.hex(e.header.mixHash),nonce:r.rpcDataHexString(r.hex(e.header.nonce),16),sha3Uncles:r.hex(e.header.uncleHash),logsBloom:r.hex(e.header.bloom),transactionsRoot:r.hex(e.header.transactionsTrie),stateRoot:r.hex(e.header.stateRoot),receiptsRoot:r.hex(e.header.receiptTrie),miner:r.hex(e.header.coinbase),difficulty:r.rpcQuantityHexString(e.header.difficulty),totalDifficulty:r.rpcQuantityHexString(e.header.difficulty),extraData:r.rpcDataHexString(e.header.extraData),size:r.hex(1e3),gasLimit:r.rpcQuantityHexString(e.header.gasLimit),gasUsed:r.rpcQuantityHexString(e.header.gasUsed),timestamp:r.rpcQuantityHexString(e.header.timestamp),transactions:e.transactions.map((function(n){return t?n.toJsonRpc(e):r.hex(n.hash())})),uncles:[]}}}},function(e,t,n){n(9);const r=n(22),o=n(101);e.exports={server:function(e){return o.create(e)},provider:function(e){return new r(e)},_webpacked:!0}},function(e,t){e.exports=require("web3-provider-engine")},function(e,t){e.exports=require("web3-provider-engine/subproviders/subscriptions")},function(e,t,n){var r=n(5);function RequestFunnel(){this.methods={eth_call:!0,eth_getStorageAt:!0,eth_sendTransaction:!0,eth_sendRawTransaction:!0,eth_newBlockFilter:!0,eth_getFilterChanges:!0,eth_getFilterLogs:!0},this.queue=[],this.isWorking=!1}(0,n(2).inherits)(RequestFunnel,r),e.exports=RequestFunnel,RequestFunnel.prototype.handleRequest=function(e,t,n){if(!0!==e.external||!0!==this.methods[e.method])return t();this.queue.push([e,t]),!1===this.isWorking&&this.processNext()},RequestFunnel.prototype.processNext=function(){var e=this;0!==this.queue.length?(this.isWorking=!0,(0,this.queue.shift()[1])((function(t,n,r){if(t)return r(t);r(),e.processNext()}))):this.isWorking=!1}},function(e,t,n){var r=n(5),o=n(2).inherits,i=n(3),a=n(0);function DelayedBlockFilter(){this.watching={}}o(DelayedBlockFilter,r),e.exports=DelayedBlockFilter,DelayedBlockFilter.prototype.handleRequest=function(e,t,n){return"eth_newBlockFilter"===e.method?this.handleNewBlockFilter(e,t,n):"eth_getFilterChanges"===e.method?this.handleGetFilterChanges(e,t,n):void t()},DelayedBlockFilter.prototype.handleNewBlockFilter=function(e,t,n){var r=this;t((function(e,t,n){if(e)return n();r.watching[t]=!0,n()}))},DelayedBlockFilter.prototype.handleGetFilterChanges=function(e,t,n){var r=this,o=e.params[0];if(!this.watching[o])return t();t((function(e,t,n){if(e)return n();var s,c,u;i.series([function(e){0!==t.length?(s=t[0],e()):r.emitPayload({method:"eth_blockNumber"},(function(t,n){if(t)return e(t);u=a.number(n.result),e()}))},function(e){if(u)return e();r.emitPayload({method:"eth_getBlockByHash",params:[s,!1]},(function(t,n){if(t)return e(t);u=a.number(n.result.number),e()}))},function(e){if(0===(u=a.number(u)))return c=void 0,e();u-=1,r.emitPayload({method:"eth_getBlockByNumber",params:[u,!1]},(function(t,n){if(t)return e(t);c=n.result.hash,e()}))}],(function(e){c&&(t[0]=c),delete r.watching[o],n()}))}))}},function(e,t,n){var r=n(5);function GethDefaults(){}(0,n(2).inherits)(GethDefaults,r),e.exports=GethDefaults,GethDefaults.prototype.handleRequest=function(e,t,n){if("eth_estimateGas"!==e.method&&"eth_call"!==e.method)return t();var r=e.params[0];null==r.from?this.emitPayload({method:"eth_coinbase"},(function(e,o){if(e)return n(e);var i=o.result;r.from=i,t()})):t()}},function(e,t,n){var r=n(1),o=n(2).inherits,i=n(43),a=n(0),s=n(34),c=n(35),u=n(99);const{BlockOutOfRangeError:l}=n(16);var h=n(5);const p="0x"+Number.MAX_SAFE_INTEGER.toString(16),f=["v","r","s"];function GethApiDouble(e,t){var n=this;this.state=e.state||new i(e,t),this.options=e,this.initialized=!1,this.initialization_error=null,this.post_initialization_callbacks=[],this.state.initialize((function(e){e&&(n.initialization_error=e),n.initialized=!0;var t=n.post_initialization_callbacks;n.post_initialization_callbacks=[],t.forEach((function(e){setImmediate((function(){e(n.initialization_error,n.state)}))}))}))}o(GethApiDouble,h),GethApiDouble.prototype.waitForInitialization=function(e){!1===this.initialized?this.post_initialization_callbacks.push(e):e(this.initialization_error,this.state)},GethApiDouble.prototype.handleRequest=function(e,t,n){if(null!=this.initialization_error)return n(this.initialization_error);if(!1!==this.initialized){var r=this[e.method];if(null==r)return n(new Error("Method "+e.method+" not supported."));var o=e.params||[],i=[].concat(o),a=!1;if(this.requiresDefaultBlockParameter(e.method)&&i.length<r.length-1&&(i.push("latest"),a=!0),i.push(n),i.length>r.length||void 0!==r.minLength&&i.length<r.minLength||void 0===r.minLength&&i.length<r.length){var s=`Incorrect number of arguments. Method '${e.method}' requires `;return r.minLength?s+=`between ${r.minLength-1} and ${r.length-1} arguments. `:s+=`exactly ${r.length-1} arguments. `,s+=a?"Including the implicit block argument, r":"R",s+=`equest specified ${i.length-1} arguments: ${JSON.stringify(i)}.`,n(new Error(s))}r.apply(this,i)}else this.waitForInitialization(this.getDelayedHandler(e,t,n))},GethApiDouble.prototype.getDelayedHandler=function(e,t,n){var r=this;return function(o,i){o&&n(o),r.handleRequest(e,t,n)}},GethApiDouble.prototype.requiresDefaultBlockParameter=function(e){return!0==={eth_getBalance:!0,eth_getCode:!0,eth_getTransactionCount:!0,eth_getStorageAt:!0,eth_call:!0,eth_estimateGas:!0}[e]},GethApiDouble.prototype.eth_accounts=function(e){e(null,Object.keys(this.state.accounts))},GethApiDouble.prototype.eth_blockNumber=function(e){this.state.blockNumber((function(t,n){if(t)return e(t);e(null,a.hex(n))}))},GethApiDouble.prototype.eth_chainId=function(e){e(null,a.hex(this.options._chainIdRpc))},GethApiDouble.prototype.eth_coinbase=function(e){e(null,this.state.coinbase)},GethApiDouble.prototype.eth_mining=function(e){e(null,this.state.is_mining)},GethApiDouble.prototype.eth_hashrate=function(e){e(null,"0x0")},GethApiDouble.prototype.eth_gasPrice=function(e){e(null,r.addHexPrefix(this.state.gasPrice()))},GethApiDouble.prototype.eth_getBalance=function(e,t,n){this.state.getBalance(e,t,n)},GethApiDouble.prototype.eth_getCode=function(e,t,n){this.state.getCode(e,t,n)},GethApiDouble.prototype.eth_getBlockByNumber=function(e,t,n){this.state.blockchain.getBlock(e,(function(e,r){if(e)return e instanceof l?n(null,null):n(e);n(null,c.toJSON(r,t))}))},GethApiDouble.prototype.eth_getBlockByHash=function(e,t,n){this.eth_getBlockByNumber.apply(this,arguments)},GethApiDouble.prototype.eth_getBlockTransactionCountByNumber=function(e,t){this.state.blockchain.getBlock(e,(function(e,n){if(e)return e instanceof l?t(null,null):t(e);t(null,a.rpcQuantityHexString(n.transactions.length))}))},GethApiDouble.prototype.eth_getBlockTransactionCountByHash=function(e,t){this.eth_getBlockTransactionCountByNumber.apply(this,arguments)},GethApiDouble.prototype.eth_getTransactionReceipt=function(e,t){this.state.getTransactionReceipt(e,(function(e,n){if(e)return t(e);var r=null;n&&n.block&&(r=n.toJSON(),f.forEach(e=>{delete r[e]})),t(null,r)}))},GethApiDouble.prototype.eth_getTransactionByHash=function(e,t){this.state.getTransactionReceipt(e,(function(e,n){if(e)return t(e);var r=null;n&&(n.block||(n.block={transactions:[],hash:()=>null,header:{number:null}}),r=n.tx.toJsonRpc(n.block)),t(null,r)}))},GethApiDouble.prototype.eth_getTransactionByBlockHashAndIndex=function(e,t,n){t=a.number(t),this.state.getBlock(e,(function(e,r){if(e)return e.notFound?n(null,null):n(e);if(t>=r.transactions.length)return n(new Error("Transaction at index "+a.hex(t)+" does not exist in block."));var o=r.transactions[t].toJsonRpc(r);n(null,o)}))},GethApiDouble.prototype.eth_getTransactionByBlockNumberAndIndex=function(e,t,n){this.eth_getTransactionByBlockHashAndIndex(e,t,n)},GethApiDouble.prototype.eth_getTransactionCount=function(e,t,n){this.state.getTransactionCount(e,t,(e,t)=>e instanceof l?n(null,null):n(e,t))},GethApiDouble.prototype.eth_sign=function(e,t,n){var r,o;try{r=this.state.sign(e,t)}catch(e){o=e}n(o,r)},GethApiDouble.prototype.eth_signTypedData=function(e,t,n){var r,o;try{r=this.state.signTypedData(e,t)}catch(e){o=e}n(o,r)},GethApiDouble.prototype.eth_sendTransaction=function(e,t){this.state.queueTransaction("eth_sendTransaction",e,null,t)},GethApiDouble.prototype.eth_sendRawTransaction=function(e,t){let n;if(e&&(n=a.buffer(e)),void 0===n)throw new s("rawTx must be a string, JSON-encoded Buffer, or Buffer.");this.state.queueRawTransaction(n,t)},GethApiDouble.prototype._setCallGasLimit=function(e){if(!e.gas&&!e.gasLimit){const t=this.options.callGasLimit;e.gas=null!=t?t:p}},GethApiDouble.prototype.eth_call=function(e,t,n){this._setCallGasLimit(e),this.state.queueTransaction("eth_call",e,t,n)},GethApiDouble.prototype.eth_estimateGas=function(e,t,n){this._setCallGasLimit(e),this.state.queueTransaction("eth_estimateGas",e,t,n)},GethApiDouble.prototype.eth_getStorageAt=function(e,t,n,r){this.state.queueStorage(e,t,n,r)},GethApiDouble.prototype.eth_newBlockFilter=function(e){var t=r.addHexPrefix(r.intToHex(this.state.latestFilterId));this.state.latestFilterId+=1,e(null,t)},GethApiDouble.prototype.eth_getFilterChanges=function(e,t){var n=this.state.latestBlock().hash().toString("hex");this.state.mine(),t(null,[n])},GethApiDouble.prototype.eth_getLogs=function(e,t){this.state.getLogs(e,t)},GethApiDouble.prototype.eth_uninstallFilter=function(e,t){t(null,!0)},GethApiDouble.prototype.eth_protocolVersion=function(e){e(null,"63")},GethApiDouble.prototype.bzz_hive=function(e){e(null,[])},GethApiDouble.prototype.bzz_info=function(e){e(null,[])},GethApiDouble.prototype.shh_version=function(e){e(null,"2")},GethApiDouble.prototype.eth_getCompilers=function(e){e(null,[])},GethApiDouble.prototype.eth_syncing=function(e){e(null,!1)},GethApiDouble.prototype.net_listening=function(e){e(null,!0)},GethApiDouble.prototype.net_peerCount=function(e){e(null,0)},GethApiDouble.prototype.web3_clientVersion=function(e){e(null,"EthereumJS TestRPC/v"+u.version+"/ethereum-js")},GethApiDouble.prototype.web3_sha3=function(e,t){t(null,a.hex(r.keccak256(e)))},GethApiDouble.prototype.net_version=function(e){e(null,this.state.net_version+"")},GethApiDouble.prototype.miner_start=function(e,t){t||"function"!=typeof e||(t=e,e=null),this.state.startMining((function(e){t(e,!0)}))},GethApiDouble.prototype.miner_start.minLength=1,GethApiDouble.prototype.miner_stop=function(e){this.state.stopMining((function(t){e(t,!0)}))},GethApiDouble.prototype.rpc_modules=function(e){e(null,{eth:"1.0",net:"1.0",rpc:"1.0",web3:"1.0",evm:"1.0",personal:"1.0"})},GethApiDouble.prototype.personal_listAccounts=function(e){e(null,Object.keys(this.state.personal_accounts))},GethApiDouble.prototype.personal_newAccount=function(e,t){var n=this.state.createAccount({generate:!0});this.state.accounts[n.address.toLowerCase()]=n,this.state.personal_accounts[n.address.toLowerCase()]=!0,this.state.account_passwords[n.address.toLowerCase()]=e,t(null,n.address)},GethApiDouble.prototype.personal_importRawKey=function(e,t,n){var r=this.state.createAccount({secretKey:e});this.state.accounts[r.address.toLowerCase()]=r,this.state.personal_accounts[r.address.toLowerCase()]=!0,this.state.account_passwords[r.address.toLowerCase()]=t,n(null,r.address)},GethApiDouble.prototype.personal_lockAccount=function(e,t){if(!0!==this.state.personal_accounts[e.toLowerCase()]){return t("Account not found")}delete this.state.unlocked_accounts[e.toLowerCase()],t(null,!0)},GethApiDouble.prototype.personal_unlockAccount=function(e,t,n,r){if(!0!==this.state.personal_accounts[e.toLowerCase()]){return r("Account not found")}var o=this.state.account_passwords[e.toLowerCase()];if(void 0!==o&&o!==t){return r("Invalid password")}this.state.unlocked_accounts[e.toLowerCase()]=!0,r(null,!0)},GethApiDouble.prototype.personal_sendTransaction=function(e,t,n){if(null!=e.from){var o=r.addHexPrefix(e.from).toLowerCase(),i=this;i.personal_unlockAccount(o,t,null,(function(t){if(t)return n(t);i.state.queueTransaction("eth_sendTransaction",e,null,(function(e,t){i.state.unlocked_accounts[o.toLowerCase()]=!1,n(e,t)}))}))}else{n("Sender not found")}},GethApiDouble.prototype.evm_snapshot=function(e){this.state.snapshot(e)},GethApiDouble.prototype.evm_revert=function(e,t){this.state.revert(e,t)},GethApiDouble.prototype.evm_increaseTime=function(e,t){t(null,this.state.blockchain.increaseTime(e))},GethApiDouble.prototype.evm_setTime=function(e,t){t(null,this.state.blockchain.setTime(new Date(e)))},GethApiDouble.prototype.evm_mine=function(e,t){"function"==typeof e&&(t=e,e=void 0),this.state.processBlock(e,(function(e){if(e)return