├── .editorconfig ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── dist ├── ethjs-contract.js ├── ethjs-contract.js.map └── ethjs-contract.min.js ├── docs ├── README.md ├── developer-guide.md └── user-guide.md ├── internals └── webpack │ └── webpack.config.js ├── package-lock.json ├── package.json └── src ├── contract.js ├── has-tx-object.js ├── index.js └── tests ├── test-contracts.js └── test.index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = false 6 | indent_style = space 7 | indent_size = 2 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes 2 | 3 | # Handle line endings automatically for files detected as text 4 | # and leave all files detected as binary untouched. 5 | * text=auto 6 | 7 | # 8 | # The above will handle all files NOT found below 9 | # 10 | 11 | # 12 | ## These files are text and should be normalized (Convert crlf => lf) 13 | # 14 | 15 | # source code 16 | *.php text 17 | *.css text 18 | *.sass text 19 | *.scss text 20 | *.less text 21 | *.styl text 22 | *.js text eol=lf 23 | *.coffee text 24 | *.json text 25 | *.htm text 26 | *.html text 27 | *.xml text 28 | *.svg text 29 | *.txt text 30 | *.ini text 31 | *.inc text 32 | *.pl text 33 | *.rb text 34 | *.py text 35 | *.scm text 36 | *.sql text 37 | *.sh text 38 | *.bat text 39 | 40 | # templates 41 | *.ejs text 42 | *.hbt text 43 | *.jade text 44 | *.haml text 45 | *.hbs text 46 | *.dot text 47 | *.tmpl text 48 | *.phtml text 49 | 50 | # server config 51 | .htaccess text 52 | 53 | # git config 54 | .gitattributes text 55 | .gitignore text 56 | .gitconfig text 57 | 58 | # code analysis config 59 | .jshintrc text 60 | .jscsrc text 61 | .jshintignore text 62 | .csslintrc text 63 | 64 | # misc config 65 | *.yaml text 66 | *.yml text 67 | .editorconfig text 68 | 69 | # build config 70 | *.npmignore text 71 | *.bowerrc text 72 | 73 | # Heroku 74 | Procfile text 75 | .slugignore text 76 | 77 | # Documentation 78 | *.md text 79 | LICENSE text 80 | AUTHORS text 81 | 82 | 83 | # 84 | ## These files are binary and should be left untouched 85 | # 86 | 87 | # (binary is a macro for -text -diff) 88 | *.png binary 89 | *.jpg binary 90 | *.jpeg binary 91 | *.gif binary 92 | *.ico binary 93 | *.mov binary 94 | *.mp4 binary 95 | *.mp3 binary 96 | *.flv binary 97 | *.fla binary 98 | *.swf binary 99 | *.gz binary 100 | *.zip binary 101 | *.7z binary 102 | *.ttf binary 103 | *.eot binary 104 | *.woff binary 105 | *.pyc binary 106 | *.pdf binary 107 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to ethjs-contract 2 | 3 | Love ethjs-contract and want to help? Thanks so much, there's something to do for everybody! 4 | 5 | Please take a moment to review this document in order to make the contribution process easy and effective for everyone involved. 6 | 7 | Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue or assessing patches and features. 8 | 9 | ## Using the issue tracker 10 | 11 | The [issue tracker](https://github.com/ethjs/ethjs-contract/issues) is 12 | the preferred channel for [bug reports](#bugs), [features requests](#features) 13 | and [submitting pull requests](#pull-requests). 14 | 15 | 16 | ## Bug reports 17 | 18 | A bug is a _demonstrable problem_ that is caused by the code in the repository. 19 | Good bug reports are extremely helpful - thank you! 20 | 21 | Guidelines for bug reports: 22 | 23 | 1. **Use the GitHub issue search** — check if the issue has already been reported. 24 | 25 | 2. **Check if the issue has been fixed** — try to reproduce it using the latest `master` or development branch in the repository. 26 | 27 | 3. **Isolate the problem** — 28 | 29 | A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. What is your environment? What steps will reproduce the issue? What browser(s) and OS 30 | experience the problem? What would you expect to be the outcome? All these details will help people to fix any potential bugs. 31 | 32 | Example: 33 | 34 | > Short and descriptive example bug report title 35 | > 36 | > A summary of the issue and the browser/OS environment in which it occurs. If 37 | > suitable, include the steps required to reproduce the bug. 38 | > 39 | > 1. This is the first step 40 | > 2. This is the second step 41 | > 3. Further steps, etc. 42 | > 43 | > `` - a link to the reduced test case 44 | > 45 | > Any other information you want to share that is relevant to the issue being 46 | > reported. This might include the lines of code that you have identified as 47 | > causing the bug, and potential solutions (and your opinions on their 48 | > merits). 49 | 50 | 51 | 52 | ## Feature requests 53 | 54 | Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to *you* to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible. 55 | 56 | 57 | 58 | ## Pull requests 59 | 60 | Good pull requests - patches, improvements, new features - are a fantastic 61 | help. They should remain focused in scope and avoid containing unrelated 62 | commits. 63 | 64 | **Please ask first** before embarking on any significant pull request (e.g. 65 | implementing features, refactoring code, porting to a different language), 66 | otherwise you risk spending a lot of time working on something that the 67 | project's developers might not want to merge into the project. 68 | 69 | Please adhere to the coding conventions used throughout a project (indentation, 70 | accurate comments, etc.) and any other requirements (such as test coverage). 71 | 72 | Adhering to the following process is the best way to get your work 73 | included in the project: 74 | 75 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) the project, clone your fork, and configure the remotes: 76 | 77 | ```bash 78 | # Clone your fork of the repo into the current directory 79 | git clone https://github.com//ethjs-contract.git 80 | # Navigate to the newly cloned directory 81 | cd ethjs-contract 82 | # Assign the original repo to a remote called "upstream" 83 | git remote add upstream https://github.com/ethjs/ethjs-contract.git 84 | ``` 85 | 86 | 2. If you cloned a while ago, get the latest changes from upstream: 87 | 88 | ```bash 89 | git checkout master 90 | git pull upstream master 91 | ``` 92 | 93 | 3. Create a new topic branch (off the main project development branch) to contain your feature, change, or fix: 94 | 95 | ```bash 96 | git checkout -b 97 | ``` 98 | 99 | 4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/about-git-rebase/) feature to tidy up your commits before making them public. 100 | 101 | 5. Locally merge (or rebase) the upstream development branch into your topic branch: 102 | 103 | ```bash 104 | git pull [--rebase] upstream master 105 | ``` 106 | 107 | 6. Push your topic branch up to your fork: 108 | 109 | ```bash 110 | git push origin 111 | ``` 112 | 113 | 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) 114 | with a clear title and description. 115 | 116 | **DESIGN NOTE**: ethjs-contract follows the UNIX programming philosophy. Please consider this before contributing, keep your commits/modules concise and to the point. 117 | 118 | Read more here: 119 | http://www.catb.org/esr/writings/taoup/html/ch01s06.html 120 | 121 | **IMPORTANT**: By submitting a patch, you agree to allow the project 122 | owners to license your work under the terms of the [MIT License](LICENSE.txt). 123 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # ethjs-contract 2 | 3 | Before opening a new issue, please take a moment to review our [**community guidelines**](https://github.com/ethjs/ethjs-contract/blob/master/.github/CONTRIBUTING.md) to make the contribution process easy and effective for everyone involved. 4 | 5 | **Before opening a new issue, you may find an answer in already closed issues**: 6 | https://github.com/ethjs/ethjs-contract/issues?q=is%3Aissue+is%3Aclosed 7 | 8 | ## Issue Type 9 | 10 | - [ ] Bug (https://github.com/ethjs/ethjs-contract/blob/master/.github/CONTRIBUTING.md#bug-reports) 11 | - [ ] Feature (https://github.com/ethjs/ethjs-contract/blob/master/.github/CONTRIBUTING.md#feature-requests) 12 | 13 | ## Description 14 | 15 | (Add images if possible) 16 | 17 | ## Steps to reproduce 18 | 19 | (Add link to a demo on https://jsfiddle.net or similar if possible) 20 | 21 | # Versions 22 | 23 | - Node/NPM: 24 | - Browser: 25 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## ethjs-contract 2 | 3 | Thank you for contributing! Please take a moment to review our [**contributing guidelines**](https://github.com/ethjs/ethjs-contract/blob/master/.github/CONTRIBUTING.md) 4 | to make the process easy and effective for everyone involved. 5 | 6 | **Please open an issue** before embarking on any significant pull request, especially those that 7 | add a new library or change existing tests, otherwise you risk spending a lot of time working 8 | on something that might not end up being merged into the project. 9 | 10 | Before opening a pull request, please ensure: 11 | 12 | - [ ] You have followed our [**contributing guidelines**](https://github.com/ethjs/ethjs-contract/blob/master/.github/CONTRIBUTING.md) 13 | - [ ] Pull request has tests (we are going for 100% coverage!) 14 | - [ ] Code is well-commented, linted and follows project conventions 15 | - [ ] Documentation is updated (if necessary) 16 | - [ ] Internal code generators and templates are updated (if necessary) 17 | - [ ] Description explains the issue/use-case resolved and auto-closes related issues 18 | 19 | Be kind to code reviewers, please try to keep pull requests as small and focused as possible :) 20 | 21 | **IMPORTANT**: By submitting a patch, you agree to allow the project 22 | owners to license your work under the terms of the [MIT License](https://github.com/ethjs/ethjs-contract/blob/master/LICENSE.md). 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Don't check auto-generated stuff into git 2 | node_modules 3 | coverage 4 | lib 5 | 6 | # Cruft 7 | .DS_Store 8 | npm-debug.log 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | language: node_js 3 | node_js: 4 | - "8" 5 | compiler: 6 | - gcc 7 | - clang 8 | install: 9 | env: 10 | - CXX=g++-4.8 11 | addons: 12 | apt: 13 | sources: 14 | - ubuntu-toolchain-r-test 15 | packages: 16 | - gcc-4.8 17 | - g++-4.8 18 | - clang 19 | after_success: npm run coveralls 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.1.6 -- BN formatting update 2 | 3 | 1. Bn formatting update 4 | 5 | # 0.1.5 -- remove ethjs-sha3 for js-sha3 6 | 7 | 1. Removed `ethjs-sha3` for `js-sha3`. 8 | 9 | # 0.1.4 -- fix object mutation 10 | 11 | 1. Fix object mutation with eth_call, eth_sendTransaction 12 | 13 | # 0.1.3 -- config fixes 14 | 15 | 1. Webpack config updates 16 | 2. Build config updates 17 | 18 | # 0.1.2 -- ethjs-abi update 19 | 20 | 1. Updated ethjs-abi module 21 | 2. More docs 22 | 23 | # 0.1.1 -- new event object 24 | 25 | 1. New Event object 26 | 2. Package upgrades and fixes 27 | 3. More docs 28 | 29 | # 0.1.0 -- promises, full coverage 30 | 31 | 1. Promises and callbacks on calls, new, event watchers 32 | 2. More coverage 33 | 3. Package upgrades 34 | 35 | # 0.0.1 -- ethjs-contract 36 | 37 | 1. Basic testing 38 | 2. Basic docs 39 | 3. License 40 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This Code of Conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting the project maintainer at nick.dodson@consensys.net. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | 44 | 45 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 46 | version 1.3.0, available at 47 | [http://contributor-covenant.org/version/1/3/0/][version] 48 | 49 | [homepage]: http://contributor-covenant.org 50 | [version]: http://contributor-covenant.org/version/1/3/0/ 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2016 Nick Dodson. nickdodson.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ethjs-contract 2 | 3 |
4 | 5 | 6 | Dependency Status 8 | 9 | 10 | 11 | 12 | devDependency Status 13 | 14 | 15 | 16 | 17 | Build Status 19 | 20 | 21 | 22 | 23 | NPM version 25 | 26 | 27 | 28 | 29 | Test Coverage 30 | 31 | 32 | 33 | 34 | js-airbnb-style 35 | 36 |
37 | 38 |
39 | 40 | A simple contract module for the Ethereum RPC layer. 41 | 42 | NOTE. Module not ready for use, still in heavy development. 43 | 44 | ## Install 45 | 46 | ``` 47 | npm install --save ethjs-contract 48 | ``` 49 | 50 | ## Usage 51 | 52 | ```js 53 | const HttpProvider = require('ethjs-provider-http'); 54 | const Eth = require('ethjs-query'); 55 | const EthContract = require('ethjs-contract'); 56 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 57 | const contract = new EthContract(eth); 58 | 59 | const SimpleStore = contract(abi, bytecode, defaultTxObject); 60 | const simpleStore = SimpleStore.at('0x000...'); 61 | const simpleStore = SimpleStore.new((error, result) => { 62 | // result null '0x928sdfk...' 63 | }); 64 | 65 | simpleStore.set(45000, (error, result) => { 66 | // result null '0x2dfj24...' 67 | }); 68 | 69 | simpleStore.get().catch((error) => { 70 | // error null 71 | }).then(result) => { 72 | // result 73 | }); 74 | 75 | const filter = simpleStore.SetComplete() 76 | .new({ toBlock: 'latest' }, (error, result) => { 77 | // result null filterId 78 | }); 79 | filter.watch((err, result) => { 80 | // result null FilterResult {...} 81 | }); 82 | filter.uninstall() 83 | .then(result) => { 84 | // result Boolean 85 | }); 86 | ``` 87 | 88 | ## About 89 | 90 | A simple contract object for the Ethereum RPC layer. 91 | 92 | ## Contributing 93 | 94 | Please help better the ecosystem by submitting issues and pull requests to default. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy. 95 | 96 | ## Guides 97 | 98 | You'll find more detailed information on using `ethjs-contract` and tailoring it to your needs in our guides: 99 | 100 | - [User guide](docs/user-guide.md) - Usage, configuration, FAQ and complementary tools. 101 | - [Developer guide](docs/developer-guide.md) - Contributing to `ethjs-contract` and writing your own code and coverage. 102 | 103 | ## Help out 104 | 105 | There is always a lot of work to do, and will have many rules to maintain. So please help out in any way that you can: 106 | 107 | - Create, enhance, and debug ethjs rules (see our guide to ["Working on rules"](./github/CONTRIBUTING.md)). 108 | - Improve documentation. 109 | - Chime in on any open issue or pull request. 110 | - Open new issues about your ideas for making `ethjs-contract` better, and pull requests to show us how your idea works. 111 | - Add new tests to *absolutely anything*. 112 | - Create or contribute to ecosystem tools, like modules for encoding or contracts. 113 | - Spread the word. 114 | 115 | Please consult our [Code of Conduct](CODE_OF_CONDUCT.md) docs before helping out. 116 | 117 | We communicate via [issues](https://github.com/ethjs/ethjs-contract/issues) and [pull requests](https://github.com/ethjs/ethjs-contract/pulls). 118 | 119 | ## Important documents 120 | 121 | - [Changelog](CHANGELOG.md) 122 | - [Code of Conduct](CODE_OF_CONDUCT.md) 123 | - [License](https://raw.githubusercontent.com/ethjs/ethjs-contract/master/LICENSE) 124 | 125 | ## Licence 126 | 127 | This project is licensed under the MIT license, Copyright (c) 2016 Nick Dodson. For more information see LICENSE.md. 128 | 129 | ``` 130 | The MIT License 131 | 132 | Copyright (c) 2016 Nick Dodson. nickdodson.com 133 | 134 | Permission is hereby granted, free of charge, to any person obtaining a copy 135 | of this software and associated documentation files (the "Software"), to deal 136 | in the Software without restriction, including without limitation the rights 137 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 138 | copies of the Software, and to permit persons to whom the Software is 139 | furnished to do so, subject to the following conditions: 140 | 141 | The above copyright notice and this permission notice shall be included in 142 | all copies or substantial portions of the Software. 143 | 144 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 145 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 146 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 147 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 148 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 149 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 150 | THE SOFTWARE. 151 | ``` 152 | -------------------------------------------------------------------------------- /dist/ethjs-contract.min.js: -------------------------------------------------------------------------------- 1 | !function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("EthContract",[],r):"object"==typeof exports?exports.EthContract=r():t.EthContract=r()}(this,function(){return function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}var e={};return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,r,e){Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:e})},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=51)}(function(t){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r))switch(typeof t[r]){case"function":break;case"object":t[r]=function(r){var e=r.slice(1),n=t[r[0]];return function(t,r,i){n.apply(this,[t,r,i].concat(e))}}(t[r]);break;default:t[r]=t[t[r]]}return t}([function(t,r){var e=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=e)},function(t,r,e){var n=e(42)("wks"),i=e(46),o=e(0).Symbol,u="function"==typeof o,s=t.exports=function(t){return n[t]||(n[t]=u&&o[t]||(u?o:i)("Symbol."+t))};s.store=n},function(t,r){var e=t.exports={version:"2.5.5"};"number"==typeof __e&&(__e=e)},function(t,r,e){var n=e(8);t.exports=function(t){if(!n(t))throw TypeError(t+" is not an object!");return t}},function(t,r,e){var n=e(0),i=e(2),o=e(12),u=e(5),s=e(14),a="prototype",h=function(t,r,e){var f,c,l,p=t&h.F,d=t&h.G,m=t&h.S,v=t&h.P,g=t&h.B,y=t&h.W,w=d?i:i[r]||(i[r]={}),M=w[a],b=d?n:m?n[r]:(n[r]||{})[a];d&&(e=r);for(f in e)c=!p&&b&&void 0!==b[f],c&&s(w,f)||(l=c?b[f]:e[f],w[f]=d&&"function"!=typeof b[f]?e[f]:g&&c?o(l,n):y&&b[f]==l?function(t){var r=function(r,e,n){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,e)}return new t(r,e,n)}return t.apply(this,arguments)};return r[a]=t[a],r}(l):v&&"function"==typeof l?o(Function.call,l):l,v&&((w.virtual||(w.virtual={}))[f]=l,t&h.R&&M&&!M[f]&&u(M,f,l)))};h.F=1,h.G=2,h.S=4,h.P=8,h.B=16,h.W=32,h.U=64,h.R=128,t.exports=h},function(t,r,e){var n=e(15),i=e(41);t.exports=e(7)?function(t,r,e){return n.f(t,r,i(1,e))}:function(t,r,e){return t[r]=e,t}},function(t,r,e){"use strict";(function(t,n){function i(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(r){return!1}}function o(){return t.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(r,e){if(o()t)throw new RangeError('"size" argument must not be negative')}function h(t,r,e,n){return a(r),r>0&&void 0!==e?"string"==typeof n?u(t,r).fill(e,n):u(t,r).fill(e):u(t,r)}function f(r,e){if(a(e),r=u(r,0>e?0:0|m(e)),!t.TYPED_ARRAY_SUPPORT)for(var n=0;e>n;++n)r[n]=0;return r}function c(r,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!t.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var i=0|g(e,n);r=u(r,i);var o=r.write(e,n);return o!==i&&(r=r.slice(0,o)),r}function l(t,r){var e=0>r.length?0:0|m(r.length);t=u(t,e);for(var n=0;e>n;n+=1)t[n]=255&r[n];return t}function p(r,e,n,i){if(0>n||n>e.byteLength)throw new RangeError("'offset' is out of bounds");if(n+(i||0)>e.byteLength)throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,n):new Uint8Array(e,n,i),t.TYPED_ARRAY_SUPPORT?(r=e,r.__proto__=t.prototype):r=l(r,e),r}function d(r,e){if(t.isBuffer(e)){var n=0|m(e.length);return r=u(r,n),0===r.length?r:(e.copy(r,0,0,n),r)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||$(e.length)?u(r,0):l(r,e);if("Buffer"===e.type&&X(e.data))return l(r,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function m(t){if(t>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|t}function v(r){return+r!=r&&(r=0),t.alloc(+r)}function g(r,e){if(t.isBuffer(r))return r.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(r)||r instanceof ArrayBuffer))return r.byteLength;"string"!=typeof r&&(r=""+r);var n=r.length;if(0===n)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return K(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(r).length;default:if(i)return K(r).length;e=(""+e).toLowerCase(),i=!0}}function y(t,r,e){var n=!1;if((void 0===r||0>r)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),0>=e)return"";if(e>>>=0,r>>>=0,r>=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,r,e);case"utf8":case"utf-8":return j(this,r,e);case"ascii":return P(this,r,e);case"latin1":case"binary":return O(this,r,e);case"base64":return k(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function w(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function M(r,e,n,i,o){if(0===r.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:-2147483648>n&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:r.length-1),0>n&&(n=r.length+n),r.length>n){if(0>n){if(!o)return-1;n=0}}else{if(o)return-1;n=r.length-1}if("string"==typeof e&&(e=t.from(e,i)),t.isBuffer(e))return 0===e.length?-1:b(r,e,n,i,o);if("number"==typeof e)return e=255&e,t.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(r,e,n):Uint8Array.prototype.lastIndexOf.call(r,e,n):b(r,[e],n,i,o);throw new TypeError("val must be string, number or Buffer")}function b(t,r,e,n,i){function o(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}var u=1,s=t.length,a=r.length;if(void 0!==n&&(n=(n+"").toLowerCase(),"ucs2"===n||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(2>t.length||2>r.length)return-1;u=2,s/=2,a/=2,e/=2}var h;if(i){var f=-1;for(h=e;s>h;h++)if(o(t,h)===o(r,f===-1?0:h-f)){if(f===-1&&(f=h),h-f+1===a)return f*u}else f!==-1&&(h-=h-f),f=-1}else for(e+a>s&&(e=s-a),h=e;h>=0;h--){for(var c=!0,l=0;a>l;l++)if(o(t,h+l)!==o(r,l)){c=!1;break}if(c)return h}return-1}function x(t,r,e,n){e=+e||0;var i=t.length-e;n?(n=+n,n>i&&(n=i)):n=i;var o=r.length;if(o%2!==0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var u=0;n>u;++u){var s=parseInt(r.substr(2*u,2),16);if(isNaN(s))return u;t[e+u]=s}return u}function _(t,r,e,n){return V(K(r,t.length-e),t,e,n)}function E(t,r,e,n){return V(G(r),t,e,n)}function A(t,r,e,n){return E(t,r,e,n)}function S(t,r,e,n){return V(J(r),t,e,n)}function T(t,r,e,n){return V(H(r,t.length-e),t,e,n)}function k(t,r,e){return W.fromByteArray(0===r&&e===t.length?t:t.slice(r,e))}function j(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;e>i;){var o=t[i],u=null,s=o>239?4:o>223?3:o>191?2:1;if(e>=i+s){var a,h,f,c;switch(s){case 1:128>o&&(u=o);break;case 2:a=t[i+1],128===(192&a)&&(c=(31&o)<<6|63&a,c>127&&(u=c));break;case 3:a=t[i+1],h=t[i+2],128===(192&a)&&128===(192&h)&&(c=(15&o)<<12|(63&a)<<6|63&h,c>2047&&(55296>c||c>57343)&&(u=c));break;case 4:a=t[i+1],h=t[i+2],f=t[i+3],128===(192&a)&&128===(192&h)&&128===(192&f)&&(c=(15&o)<<18|(63&a)<<12|(63&h)<<6|63&f,c>65535&&1114112>c&&(u=c))}}null===u?(u=65533,s=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),i+=s}return B(n)}function B(t){var r=t.length;if(tt>=r)return String.fromCharCode.apply(String,t);for(var e="",n=0;r>n;)e+=String.fromCharCode.apply(String,t.slice(n,n+=tt));return e}function P(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;e>i;++i)n+=String.fromCharCode(127&t[i]);return n}function O(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;e>i;++i)n+=String.fromCharCode(t[i]);return n}function R(t,r,e){var n=t.length;r&&r>=0||(r=0),(!e||0>e||e>n)&&(e=n);for(var i="",o=r;e>o;++o)i+=z(t[o]);return i}function L(t,r,e){for(var n=t.slice(r,e),i="",o=0;n.length>o;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function I(t,r,e){if(t%1!==0||0>t)throw new RangeError("offset is not uint");if(t+r>e)throw new RangeError("Trying to access beyond buffer length")}function C(r,e,n,i,o,u){if(!t.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||u>e)throw new RangeError('"value" argument is out of bounds');if(n+i>r.length)throw new RangeError("Index out of range")}function N(t,r,e,n){0>r&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);o>i;++i)t[e+i]=(r&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function U(t,r,e,n){0>r&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);o>i;++i)t[e+i]=r>>>8*(n?i:3-i)&255}function F(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(0>e)throw new RangeError("Index out of range")}function Y(t,r,e,n,i){return i||F(t,r,e,4,3.4028234663852886e38,-3.4028234663852886e38),Q.write(t,r,e,n,23,4),e+4}function q(t,r,e,n,i){return i||F(t,r,e,8,1.7976931348623157e308,-1.7976931348623157e308),Q.write(t,r,e,n,52,8),e+8}function D(t){if(t=Z(t).replace(rt,""),2>t.length)return"";for(;t.length%4!==0;)t+="=";return t}function Z(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function z(t){return 16>t?"0"+t.toString(16):t.toString(16)}function K(t,r){r=r||1/0;for(var e,n=t.length,i=null,o=[],u=0;n>u;++u){if(e=t.charCodeAt(u),e>55295&&57344>e){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(56320>e){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=(i-55296<<10|e-56320)+65536}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,128>e){if((r-=1)<0)break;o.push(e)}else if(2048>e){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(65536>e){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(e>=1114112)throw Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function G(t){for(var r=[],e=0;t.length>e;++e)r.push(255&t.charCodeAt(e));return r}function H(t,r){for(var e,n,i,o=[],u=0;t.length>u&&(r-=2)>=0;++u)e=t.charCodeAt(u),n=e>>8,i=e%256,o.push(i),o.push(n);return o}function J(t){return W.toByteArray(D(t))}function V(t,r,e,n){for(var i=0;n>i&&(i+eo;++o)if(r[o]!==e[o]){n=r[o],i=e[o];break}return i>n?-1:n>i?1:0},t.isEncoding=function(t){switch((t+"").toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},t.concat=function(r,e){if(!X(r))throw new TypeError('"list" argument must be an Array of Buffers');if(0===r.length)return t.alloc(0);var n;if(void 0===e)for(e=0,n=0;r.length>n;++n)e+=r[n].length;var i=t.allocUnsafe(e),o=0;for(n=0;r.length>n;++n){var u=r[n];if(!t.isBuffer(u))throw new TypeError('"list" argument must be an Array of Buffers');u.copy(i,o),o+=u.length}return i},t.byteLength=g,t.prototype._isBuffer=!0,t.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;t>r;r+=2)w(this,r,r+1);return this},t.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;t>r;r+=4)w(this,r,r+3),w(this,r+1,r+2);return this},t.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;t>r;r+=8)w(this,r,r+7),w(this,r+1,r+6),w(this,r+2,r+5),w(this,r+3,r+4);return this},t.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?j(this,0,t):y.apply(this,arguments)},t.prototype.equals=function(r){if(!t.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r||0===t.compare(this,r)},t.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},t.prototype.compare=function(r,e,n,i,o){if(!t.isBuffer(r))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=r?r.length:0),void 0===i&&(i=0),void 0===o&&(o=this.length),0>e||n>r.length||0>i||o>this.length)throw new RangeError("out of range index");if(i>=o&&e>=n)return 0;if(i>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,i>>>=0,o>>>=0,this===r)return 0;for(var u=o-i,s=n-e,a=Math.min(u,s),h=this.slice(i,o),f=r.slice(e,n),c=0;a>c;++c)if(h[c]!==f[c]){u=h[c],s=f[c];break}return s>u?-1:u>s?1:0},t.prototype.includes=function(t,r,e){return this.indexOf(t,r,e)!==-1},t.prototype.indexOf=function(t,r,e){return M(this,t,r,e,!0)},t.prototype.lastIndexOf=function(t,r,e){return M(this,t,r,e,!1)},t.prototype.write=function(t,r,e,n){if(void 0===r)n="utf8",e=this.length,r=0;else if(void 0===e&&"string"==typeof r)n=r,e=this.length,r=0;else{if(!isFinite(r))throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");r=0|r,isFinite(e)?(e=0|e,void 0===n&&(n="utf8")):(n=e,e=void 0)}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(0>e||0>r)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return x(this,t,r,e);case"utf8":case"utf-8":return _(this,t,r,e);case"ascii":return E(this,t,r,e);case"latin1":case"binary":return A(this,t,r,e);case"base64":return S(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},t.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var tt=4096;t.prototype.slice=function(r,e){var n=this.length;r=~~r,e=void 0===e?n:~~e,0>r?(r+=n,0>r&&(r=0)):r>n&&(r=n),0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),r>e&&(e=r);var i;if(t.TYPED_ARRAY_SUPPORT)i=this.subarray(r,e),i.__proto__=t.prototype;else{var o=e-r;i=new t(o,(void 0));for(var u=0;o>u;++u)i[u]=this[u+r]}return i},t.prototype.readUIntLE=function(t,r,e){t=0|t,r=0|r,e||I(t,r,this.length);for(var n=this[t],i=1,o=0;++o0&&(i*=256);)n+=this[t+--r]*i;return n},t.prototype.readUInt8=function(t,r){return r||I(t,1,this.length),this[t]},t.prototype.readUInt16LE=function(t,r){return r||I(t,2,this.length),this[t]|this[t+1]<<8},t.prototype.readUInt16BE=function(t,r){return r||I(t,2,this.length),this[t]<<8|this[t+1]},t.prototype.readUInt32LE=function(t,r){return r||I(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},t.prototype.readUInt32BE=function(t,r){return r||I(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},t.prototype.readIntLE=function(t,r,e){t=0|t,r=0|r,e||I(t,r,this.length);for(var n=this[t],i=1,o=0;++on||(n-=Math.pow(2,8*r)),n},t.prototype.readIntBE=function(t,r,e){t=0|t,r=0|r,e||I(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,i>o||(o-=Math.pow(2,8*r)),o},t.prototype.readInt8=function(t,r){return r||I(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},t.prototype.readInt16LE=function(t,r){r||I(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},t.prototype.readInt16BE=function(t,r){r||I(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},t.prototype.readInt32LE=function(t,r){return r||I(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},t.prototype.readInt32BE=function(t,r){return r||I(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},t.prototype.readFloatLE=function(t,r){return r||I(t,4,this.length),Q.read(this,t,!0,23,4)},t.prototype.readFloatBE=function(t,r){return r||I(t,4,this.length),Q.read(this,t,!1,23,4)},t.prototype.readDoubleLE=function(t,r){return r||I(t,8,this.length),Q.read(this,t,!0,52,8)},t.prototype.readDoubleBE=function(t,r){return r||I(t,8,this.length),Q.read(this,t,!1,52,8)},t.prototype.writeUIntLE=function(t,r,e,n){if(t=+t,r=0|r,e=0|e,!n){var i=Math.pow(2,8*e)-1;C(this,t,r,e,i,0)}var o=1,u=0;for(this[r]=255&t;++u=0&&(u*=256);)this[r+o]=t/u&255;return r+e},t.prototype.writeUInt8=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,1,255,0),t.TYPED_ARRAY_SUPPORT||(r=Math.floor(r)),this[e]=255&r,e+1},t.prototype.writeUInt16LE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,2,65535,0),t.TYPED_ARRAY_SUPPORT?(this[e]=255&r,this[e+1]=r>>>8):N(this,r,e,!0),e+2},t.prototype.writeUInt16BE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,2,65535,0),t.TYPED_ARRAY_SUPPORT?(this[e]=r>>>8,this[e+1]=255&r):N(this,r,e,!1),e+2},t.prototype.writeUInt32LE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,4,4294967295,0),t.TYPED_ARRAY_SUPPORT?(this[e+3]=r>>>24,this[e+2]=r>>>16,this[e+1]=r>>>8,this[e]=255&r):U(this,r,e,!0),e+4},t.prototype.writeUInt32BE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,4,4294967295,0),t.TYPED_ARRAY_SUPPORT?(this[e]=r>>>24,this[e+1]=r>>>16,this[e+2]=r>>>8,this[e+3]=255&r):U(this,r,e,!1),e+4},t.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r=0|r,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=0,u=1,s=0;for(this[r]=255&t;++ot&&0===s&&0!==this[r+o-1]&&(s=1),this[r+o]=(t/u>>0)-s&255;return r+e},t.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r=0|r,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=e-1,u=1,s=0;for(this[r+o]=255&t;--o>=0&&(u*=256);)0>t&&0===s&&0!==this[r+o+1]&&(s=1),this[r+o]=(t/u>>0)-s&255;return r+e},t.prototype.writeInt8=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,1,127,-128),t.TYPED_ARRAY_SUPPORT||(r=Math.floor(r)),0>r&&(r=255+r+1),this[e]=255&r,e+1},t.prototype.writeInt16LE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,2,32767,-32768),t.TYPED_ARRAY_SUPPORT?(this[e]=255&r,this[e+1]=r>>>8):N(this,r,e,!0),e+2},t.prototype.writeInt16BE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,2,32767,-32768),t.TYPED_ARRAY_SUPPORT?(this[e]=r>>>8,this[e+1]=255&r):N(this,r,e,!1),e+2},t.prototype.writeInt32LE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,4,2147483647,-2147483648),t.TYPED_ARRAY_SUPPORT?(this[e]=255&r,this[e+1]=r>>>8,this[e+2]=r>>>16,this[e+3]=r>>>24):U(this,r,e,!0),e+4},t.prototype.writeInt32BE=function(r,e,n){return r=+r,e=0|e,n||C(this,r,e,4,2147483647,-2147483648),0>r&&(r=4294967295+r+1),t.TYPED_ARRAY_SUPPORT?(this[e]=r>>>24,this[e+1]=r>>>16,this[e+2]=r>>>8,this[e+3]=255&r):U(this,r,e,!1),e+4},t.prototype.writeFloatLE=function(t,r,e){return Y(this,t,r,!0,e)},t.prototype.writeFloatBE=function(t,r,e){return Y(this,t,r,!1,e)},t.prototype.writeDoubleLE=function(t,r,e){return q(this,t,r,!0,e)},t.prototype.writeDoubleBE=function(t,r,e){return q(this,t,r,!1,e)},t.prototype.copy=function(r,e,n,i){if(n||(n=0),i||0===i||(i=this.length),r.length>e||(e=r.length),e||(e=0),i>0&&n>i&&(i=n),i===n)return 0;if(0===r.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>i)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),i-n>r.length-e&&(i=r.length-e+n);var o,u=i-n;if(this===r&&e>n&&i>e)for(o=u-1;o>=0;--o)r[o+e]=this[o+n];else if(1e3>u||!t.TYPED_ARRAY_SUPPORT)for(o=0;u>o;++o)r[o+e]=this[o+n];else Uint8Array.prototype.set.call(r,this.subarray(n,n+u),e);return u},t.prototype.fill=function(r,e,n,i){if("string"==typeof r){if("string"==typeof e?(i=e,e=0,n=this.length):"string"==typeof n&&(i=n,n=this.length),1===r.length){var o=r.charCodeAt(0);256>o&&(r=o)}if(void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!t.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else"number"==typeof r&&(r=255&r);if(0>e||e>this.length||n>this.length)throw new RangeError("Out of range index");if(e>=n)return this;e>>>=0,n=void 0===n?this.length:n>>>0,r||(r=0);var u;if("number"==typeof r)for(u=e;n>u;++u)this[u]=r;else{var s=t.isBuffer(r)?r:K(""+new t(r,i)),a=s.length;for(u=0;n-e>u;++u)this[u+e]=s[u%a]}return this};var rt=/[^+\/0-9A-Za-z-_]/g}).call(r,e(6).Buffer,e(49))},function(t,r,e){t.exports=!e(13)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,r){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,r){t.exports={}},function(t,r){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,r){var e={}.toString;t.exports=function(t){return e.call(t).slice(8,-1)}},function(t,r,e){var n=e(10);t.exports=function(t,r,e){if(n(t),void 0===r)return t;switch(e){case 1:return function(e){return t.call(r,e)};case 2:return function(e,n){return t.call(r,e,n)};case 3:return function(e,n,i){return t.call(r,e,n,i)}}return function(){return t.apply(r,arguments)}}},function(t,r){t.exports=function(t){try{return!!t()}catch(r){return!0}}},function(t,r){var e={}.hasOwnProperty;t.exports=function(t,r){return e.call(t,r)}},function(t,r,e){var n=e(3),i=e(66),o=e(87),u=Object.defineProperty;r.f=e(7)?Object.defineProperty:function(t,r,e){if(n(t),r=o(r,!0),n(e),i)try{return u(t,r,e)}catch(s){}if("get"in e||"set"in e)throw TypeError("Accessors not supported!");return"value"in e&&(t[r]=e.value),t}},function(t,r,e){(function(r,e){/** 2 | * [js-sha3]{@link https://github.com/emn178/js-sha3} 3 | * 4 | * @version 0.5.5 5 | * @author Chen, Yi-Cyuan [emn178@gmail.com] 6 | * @copyright Chen, Yi-Cyuan 2015-2016 7 | * @license MIT 8 | */ 9 | !function(n){"use strict";function i(t,r,e){this.blocks=[],this.s=[],this.padding=r,this.outputBits=e,this.reset=!0,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=e>>5,this.extraBytes=(31&e)>>3;for(var n=0;50>n;++n)this.s[n]=0}var o="object"==typeof r&&r.versions&&r.versions.node;o&&(n=e);for(var u=!n.JS_SHA3_TEST&&"object"==typeof t&&t.exports,s="0123456789abcdef".split(""),a=[31,7936,2031616,520093696],h=[1,256,65536,16777216],f=[6,1536,393216,100663296],c=[0,8,16,24],l=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],p=[224,256,384,512],d=[128,256],m=["hex","buffer","arrayBuffer","array"],v=function(t,r,e){return function(n){return new i(t,r,t).update(n)[e]()}},g=function(t,r,e){return function(n,o){return new i(t,r,o).update(n)[e]()}},y=function(t,r){var e=v(t,r,"hex");e.create=function(){return new i(t,r,t)},e.update=function(t){return e.create().update(t)};for(var n=0;m.length>n;++n){var o=m[n];e[o]=v(t,r,o)}return e},w=function(t,r){var e=g(t,r,"hex");e.create=function(e){return new i(t,r,e)},e.update=function(t,r){return e.create(r).update(t)};for(var n=0;m.length>n;++n){var o=m[n];e[o]=g(t,r,o)}return e},M=[{name:"keccak",padding:h,bits:p,createMethod:y},{name:"sha3",padding:f,bits:p,createMethod:y},{name:"shake",padding:a,bits:d,createMethod:w}],b={},x=0;M.length>x;++x)for(var _=M[x],E=_.bits,A=0;E.length>A;++A)b[_.name+"_"+E[A]]=_.createMethod(E[A],_.padding);i.prototype.update=function(t){var r="string"!=typeof t;r&&t.constructor==n.ArrayBuffer&&(t=new Uint8Array(t));for(var e,i,o=t.length,u=this.blocks,s=this.byteCount,a=this.blockCount,h=0,f=this.s;o>h;){if(this.reset)for(this.reset=!1,u[0]=this.block,e=1;a+1>e;++e)u[e]=0;if(r)for(e=this.start;o>h&&s>e;++h)u[e>>2]|=t[h]<h&&s>e;++h)i=t.charCodeAt(h),128>i?u[e>>2]|=i<i?(u[e>>2]|=(192|i>>6)<>2]|=(128|63&i)<i||i>=57344?(u[e>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<e)this.start=e;else{for(this.start=e-s,this.block=u[a],e=0;a>e;++e)f[e]^=u[e];S(f),this.reset=!0}}return this},i.prototype.finalize=function(){var t=this.blocks,r=this.lastByteIndex,e=this.blockCount,n=this.s;if(t[r>>2]|=this.padding[3&r],this.lastByteIndex==this.byteCount)for(t[0]=t[e],r=1;e+1>r;++r)t[r]=0;for(t[e-1]|=2147483648,r=0;e>r;++r)n[r]^=t[r];S(n)},i.prototype.toString=i.prototype.hex=function(){this.finalize();for(var t,r=this.blockCount,e=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,u=0,a="";n>u;){for(o=0;r>o&&n>u;++o,++u)t=e[o],a+=s[t>>4&15]+s[15&t]+s[t>>12&15]+s[t>>8&15]+s[t>>20&15]+s[t>>16&15]+s[t>>28&15]+s[t>>24&15];u%r==0&&(S(e),o=0)}return i&&(t=e[o],i>0&&(a+=s[t>>4&15]+s[15&t]),i>1&&(a+=s[t>>12&15]+s[t>>8&15]),i>2&&(a+=s[t>>20&15]+s[t>>16&15])),a},i.prototype.arrayBuffer=function(){this.finalize();var t,r=this.blockCount,e=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,u=0,s=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var a=new Uint32Array(t);n>u;){for(o=0;r>o&&n>u;++o,++u)a[u]=e[o];u%r==0&&S(e)}return i&&(a[o]=e[o],t=t.slice(0,s)),t},i.prototype.buffer=i.prototype.arrayBuffer,i.prototype.digest=i.prototype.array=function(){this.finalize();for(var t,r,e=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,u=0,s=0,a=[];i>s;){for(u=0;e>u&&i>s;++u,++s)t=s<<2,r=n[u],a[t]=255&r,a[t+1]=r>>8&255,a[t+2]=r>>16&255,a[t+3]=r>>24&255;s%e==0&&S(n)}return o&&(t=s<<2,r=n[u],o>0&&(a[t]=255&r),o>1&&(a[t+1]=r>>8&255),o>2&&(a[t+2]=r>>16&255)),a};var S=function(t){var r,e,n,i,o,u,s,a,h,f,c,p,d,m,v,g,y,w,M,b,x,_,E,A,S,T,k,j,B,P,O,R,L,I,C,N,U,F,Y,q,D,Z,z,K,G,H,J,V,$,W,Q,X,tt,rt,et,nt,it,ot,ut,st,at,ht,ft;for(n=0;48>n;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],u=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],a=t[4]^t[14]^t[24]^t[34]^t[44],h=t[5]^t[15]^t[25]^t[35]^t[45],f=t[6]^t[16]^t[26]^t[36]^t[46],c=t[7]^t[17]^t[27]^t[37]^t[47],p=t[8]^t[18]^t[28]^t[38]^t[48],d=t[9]^t[19]^t[29]^t[39]^t[49],r=p^(u<<1|s>>>31),e=d^(s<<1|u>>>31),t[0]^=r,t[1]^=e,t[10]^=r,t[11]^=e,t[20]^=r,t[21]^=e,t[30]^=r,t[31]^=e,t[40]^=r,t[41]^=e,r=i^(a<<1|h>>>31),e=o^(h<<1|a>>>31),t[2]^=r,t[3]^=e,t[12]^=r,t[13]^=e,t[22]^=r,t[23]^=e,t[32]^=r,t[33]^=e,t[42]^=r,t[43]^=e,r=u^(f<<1|c>>>31),e=s^(c<<1|f>>>31),t[4]^=r,t[5]^=e,t[14]^=r,t[15]^=e,t[24]^=r,t[25]^=e,t[34]^=r,t[35]^=e,t[44]^=r,t[45]^=e,r=a^(p<<1|d>>>31),e=h^(d<<1|p>>>31),t[6]^=r,t[7]^=e,t[16]^=r,t[17]^=e,t[26]^=r,t[27]^=e,t[36]^=r,t[37]^=e,t[46]^=r,t[47]^=e,r=f^(i<<1|o>>>31),e=c^(o<<1|i>>>31),t[8]^=r,t[9]^=e,t[18]^=r,t[19]^=e,t[28]^=r,t[29]^=e,t[38]^=r,t[39]^=e,t[48]^=r,t[49]^=e,m=t[0],v=t[1],H=t[11]<<4|t[10]>>>28,J=t[10]<<4|t[11]>>>28,j=t[20]<<3|t[21]>>>29,B=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,at=t[30]<<9|t[31]>>>23,Z=t[40]<<18|t[41]>>>14,z=t[41]<<18|t[40]>>>14,I=t[2]<<1|t[3]>>>31,C=t[3]<<1|t[2]>>>31,g=t[13]<<12|t[12]>>>20,y=t[12]<<12|t[13]>>>20,V=t[22]<<10|t[23]>>>22,$=t[23]<<10|t[22]>>>22,P=t[33]<<13|t[32]>>>19,O=t[32]<<13|t[33]>>>19,ht=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,rt=t[5]<<30|t[4]>>>2,et=t[4]<<30|t[5]>>>2,N=t[14]<<6|t[15]>>>26,U=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,M=t[24]<<11|t[25]>>>21,W=t[34]<<15|t[35]>>>17,Q=t[35]<<15|t[34]>>>17,R=t[45]<<29|t[44]>>>3,L=t[44]<<29|t[45]>>>3,A=t[6]<<28|t[7]>>>4,S=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,F=t[26]<<25|t[27]>>>7,Y=t[27]<<25|t[26]>>>7,b=t[36]<<21|t[37]>>>11,x=t[37]<<21|t[36]>>>11,X=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,K=t[8]<<27|t[9]>>>5,G=t[9]<<27|t[8]>>>5,T=t[18]<<20|t[19]>>>12,k=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,ut=t[28]<<7|t[29]>>>25,q=t[38]<<8|t[39]>>>24,D=t[39]<<8|t[38]>>>24,_=t[48]<<14|t[49]>>>18,E=t[49]<<14|t[48]>>>18,t[0]=m^~g&w,t[1]=v^~y&M,t[10]=A^~T&j,t[11]=S^~k&B,t[20]=I^~N&F,t[21]=C^~U&Y,t[30]=K^~H&V,t[31]=G^~J&$,t[40]=rt^~nt&ot,t[41]=et^~it&ut,t[2]=g^~w&b,t[3]=y^~M&x,t[12]=T^~j&P,t[13]=k^~B&O,t[22]=N^~F&q,t[23]=U^~Y&D,t[32]=H^~V&W,t[33]=J^~$&Q,t[42]=nt^~ot&st,t[43]=it^~ut&at,t[4]=w^~b&_,t[5]=M^~x&E,t[14]=j^~P&R,t[15]=B^~O&L,t[24]=F^~q&Z,t[25]=Y^~D&z,t[34]=V^~W&X,t[35]=$^~Q&tt,t[44]=ot^~st&ht,t[45]=ut^~at&ft,t[6]=b^~_&m,t[7]=x^~E&v,t[16]=P^~R&A,t[17]=O^~L&S,t[26]=q^~Z&I,t[27]=D^~z&C,t[36]=W^~X&K,t[37]=Q^~tt&G,t[46]=st^~ht&rt,t[47]=at^~ft&et,t[8]=_^~m&g,t[9]=E^~v&y,t[18]=R^~A&T,t[19]=L^~S&k,t[28]=Z^~I&N,t[29]=z^~C&U,t[38]=X^~K&H,t[39]=tt^~G&J,t[48]=ht^~rt&nt,t[49]=ft^~et&it,t[0]^=l[n],t[1]^=l[n+1]};if(u)t.exports=b;else if(n)for(var T in b)n[T]=b[T]}(this)}).call(r,e(102),e(49))},function(t,r){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,r,e){var n=e(8),i=e(0).document,o=n(i)&&n(i.createElement);t.exports=function(t){return o?i.createElement(t):{}}},function(t,r,e){"use strict";function n(t){var r,e;this.promise=new t(function(t,n){if(void 0!==r||void 0!==e)throw TypeError("Bad Promise constructor");r=t,e=n}),this.resolve=i(r),this.reject=i(e)}var i=e(10);t.exports.f=function(t){return new n(t)}},function(t,r,e){var n=e(79),i=e(34);t.exports=Object.keys||function(t){return n(t,i)}},function(t,r,e){var n=e(15).f,i=e(14),o=e(1)("toStringTag");t.exports=function(t,r,e){t&&!i(t=e?t:t.prototype,o)&&n(t,o,{configurable:!0,value:r})}},function(t,r,e){var n=e(42)("keys"),i=e(46);t.exports=function(t){return n[t]||(n[t]=i(t))}},function(t,r){var e=Math.ceil,n=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?n:e)(t)}},function(t,r,e){var n=e(36),i=e(17);t.exports=function(t){return n(i(t))}},function(t,r,e){var n=e(17);t.exports=function(t){return Object(n(t))}},function(t,r,e){(function(t,n){function i(t,r){this._id=t,this._clearFn=r}var o=e(108).nextTick,u=Function.prototype.apply,s=Array.prototype.slice,a={},h=0;r.setTimeout=function(){return new i(u.call(setTimeout,window,arguments),clearTimeout)},r.setInterval=function(){return new i(u.call(setInterval,window,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(t){t.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(window,this._id)},r.enroll=function(t,r){clearTimeout(t._idleTimeoutId),t._idleTimeout=r},r.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},r._unrefActive=r.active=function(t){clearTimeout(t._idleTimeoutId);var r=t._idleTimeout;0>r||(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},r))},r.setImmediate="function"==typeof t?t:function(t){var e=h++,n=arguments.length>=2&&s.call(arguments,1);return a[e]=!0,o(function(){a[e]&&(n?t.apply(null,n):t.call(null),r.clearImmediate(e))}),e},r.clearImmediate="function"==typeof n?n:function(t){delete a[t]}}).call(r,e(26).setImmediate,e(26).clearImmediate)},function(t,r,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t){if(!Array.isArray(t)||0===t.length)return!1;var r=t[t.length-1];if(!r)return!1;if("object"!=typeof r)return!1;if(0===(0,u["default"])(r).length)return!0;var e=(0,u["default"])(r),n=s.some(function(t){return e.includes(t)});return!!n}var o=e(53),u=n(o),s=["from","to","data","value","gasPrice","gas"];t.exports=i},function(t,r,e){t.exports={"default":e(59),__esModule:!0}},function(t,r,e){"use strict";(function(r){function n(){}function i(t,e){function n(t){return parseInt(32*Math.ceil(t/32))}if(t.length!==e.length)throw Error("[ethjs-abi] while encoding params, types/values mismatch, Your contract requires "+t.length+" types (arguments), and you passed in "+e.length);var i=[];t.forEach(function(t,r){var n=m(t);i.push({dynamic:n.dynamic,value:n.encode(e[r])})});var o=0,u=0;i.forEach(function(t){t.dynamic?(o+=32,u+=n(t.value.length)):o+=n(t.value.length)});var s=0,a=o,h=new r(o+u);return i.forEach(function(t,r){t.dynamic?(d.encode(a).copy(h,s),s+=32,t.value.copy(h,a),a+=n(t.value.length)):(t.value.copy(h,s),s+=n(t.value.length))}),"0x"+h.toString("hex")}function o(t,r,e){var i=3>=arguments.length||void 0===arguments[3]||arguments[3];3>arguments.length&&(e=r,r=t,t=[]),e=p.hexOrBuffer(e);var o=new n,u=0;return r.forEach(function(r,n){var s=m(r);if(s.dynamic){var a=d.decode(e,u),h=s.decode(e,a.value.toNumber());u+=a.consumed}else{var h=s.decode(e,u);u+=h.consumed}i&&(o[n]=h.value),t[n]&&(o[t[n]]=h.value)}),o}function u(t,e){var n=t.name+"("+p.getKeys(t.inputs,"type").join(",")+")",o="0x"+new r(p.keccak256(n),"hex").slice(0,4).toString("hex"),u=i(p.getKeys(t.inputs,"type"),e).substring(2);return""+o+u}function s(t,r){var e=p.getKeys(t.outputs,"name",!0),n=p.getKeys(t.outputs,"type");return o(e,n,p.hexOrBuffer(r))}function a(t,r){return u(t,r)}function h(t){var r=t.name+"("+p.getKeys(t.inputs,"type").join(",")+")";return"0x"+p.keccak256(r)}function f(t,e,n){var i=3>=arguments.length||void 0===arguments[3]||arguments[3],u=t.inputs.filter(function(t){return!t.indexed}),s=p.getKeys(u,"name",!0),a=p.getKeys(u,"type"),h=o(s,a,p.hexOrBuffer(e),i),f=t.anonymous?0:1;return t.inputs.filter(function(t){return t.indexed}).map(function(t,e){var i=new r(n[e+f].slice(2),"hex"),o=m(t.type);h[t.name]=o.decode(i,0).value}),h._eventName=t.name,h}function c(t,r){var e=2>=arguments.length||void 0===arguments[2]||arguments[2];if(t&&r.topics[0]===h(t))return f(t,r.data,r.topics,e)}function l(t){var r=1>=arguments.length||void 0===arguments[1]||arguments[1],e={};return t.filter(function(t){return"event"===t.type}).map(function(t){e[h(t)]=t}),function(t){return t.map(function(t){return c(e[t.topics[0]],t,r)}).filter(function(t){return t})}}var p=e(98),d=p.uint256Coder,m=p.getParamCoder;t.exports={encodeParams:i,decodeParams:o,encodeMethod:u,decodeMethod:s,encodeEvent:a,decodeEvent:f,decodeLogItem:c,logDecoder:l,eventSignature:h}}).call(r,e(6).Buffer)},function(t,r){"use strict";function e(t,r){function e(t){var e=this;e.filterId=null,e.options=Object.assign({delay:300,decoder:function(t){return t},defaultFilterObject:{}},t||{}),e.watchers={},e.interval=setInterval(function(){null!==e.filterId&&Object.keys(e.watchers).length>0&&r.getFilterChanges(e.filterId,function(t,r){var n=[],i=null;if(!t)try{r.forEach(function(t,i){n[i]=r[i],"object"==typeof r[i]&&(n[i].data=e.options.decoder(n[i].data))})}catch(o){i=Error("[ethjs-filter] while decoding filter change event data from RPC '"+JSON.stringify(n)+"': "+o)}Object.keys(e.watchers).forEach(function(o){var u=e.watchers[o];return u.stop===!0?void delete e.watchers[o]:void(i?u.callback(i,null):t?u.callback(t,null):Array.isArray(n)&&r.length>0&&u.callback(t,n))})})},e.options.delay)}return e.prototype.at=function(t){var r=this;r.filterId=t},e.prototype.watch=function(t){var r=t||function(){},e=this,n=Math.random().toString(36).substring(7);return e.watchers[n]={callback:r,stop:!1,stopWatching:function(){e.watchers[n].stop=!0}}},e.prototype.uninstall=function(t){var e=this,n=t||null;e.watchers=Object.assign({}),clearInterval(e.interval);var i=new Promise(function(t,n){r.uninstallFilter(e.filterId,function(r,e){r?n(r):t(e)})});return n&&i.then(function(t){return n(null,t)})["catch"](function(t){return n(t,null)}),n?null:i},e.prototype["new"]=function(){var e=null,n=this,i=[],o=[].slice.call(arguments);"function"==typeof o[o.length-1]&&(e=o.pop()),"Filter"===t&&i.push(Object.assign(n.options.defaultFilterObject,o[o.length-1]||{}));var u=new Promise(function(e,o){i.push(function(t,r){t?o(t):(n.filterId=r,e(r))}),r["new"+t].apply(r,i)});return e&&u.then(function(t){return e(null,t)})["catch"](function(t){return e(t,null)}),e?null:u},e}function n(t){var r=this;if(!(r instanceof n))throw Error("the EthFilter object must be instantiated with `new` flag.. (e.g. `const filters = new EthFilter(query);`)");if("object"!=typeof t)throw Error("the EthFilter object must be instantiated with an EthQuery instance (e.g. `const filters = new EthFilter(new EthQuery(provider));`). See github.com/ethjs/ethjs-query for more details..");r.Filter=e("Filter",t),r.BlockFilter=e("BlockFilter",t),r.PendingTransactionFilter=e("PendingTransactionFilter",t)}t.exports=n},function(t,r,e){"use strict";(function(r){function n(t){var r=t;if("string"!=typeof r)throw Error("[ethjs-util] while padding to even, value must be string, is currently "+typeof r+", while padToEven.");return r.length%2&&(r="0"+r),r}function i(t){var r=t.toString(16);return"0x"+n(r)}function o(t){var e=i(t);return r.from(e.slice(2),"hex")}function u(t){if("string"!=typeof t)throw Error("[ethjs-util] while getting binary size, method getBinarySize requires input 'str' to be type String, got '"+typeof t+"'.");return r.byteLength(t,"utf8")}function s(t,r,e){if(Array.isArray(t)!==!0)throw Error("[ethjs-util] method arrayContainsArray requires input 'superset' to be an array got type '"+typeof t+"'");if(Array.isArray(r)!==!0)throw Error("[ethjs-util] method arrayContainsArray requires input 'subset' to be an array got type '"+typeof r+"'");return r[!!e&&"some"||"every"](function(r){return t.indexOf(r)>=0})}function a(t){var e=new r(n(m(t).replace(/^0+|0+$/g,"")),"hex");return e.toString("utf8")}function h(t){var r="",e=0,n=t.length;for("0x"===t.substring(0,2)&&(e=2);n>e;e+=2){var i=parseInt(t.substr(e,2),16);r+=String.fromCharCode(i)}return r}function f(t){var e=new r(t,"utf8");return"0x"+n(e.toString("hex")).replace(/^0+|0+$/g,"")}function c(t){for(var r="",e=0;t.length>e;e++){var n=t.charCodeAt(e),i=n.toString(16);r+=2>i.length?"0"+i:i}return"0x"+r}function l(t,r,e){if(!Array.isArray(t))throw Error("[ethjs-util] method getKeys expecting type Array as 'params' input, got '"+typeof t+"'");if("string"!=typeof r)throw Error("[ethjs-util] method getKeys expecting type String for input 'key' got '"+typeof r+"'.");for(var n=[],i=0;t.length>i;i++){var o=t[i][r];if(e&&!o)o="";else if("string"!=typeof o)throw Error("invalid abi");n.push(o)}return n}function p(t,r){return!("string"!=typeof t||!t.match(/^0x[0-9A-Fa-f]*$/))&&(!r||t.length===2+2*r)}var d=e(47),m=e(48);t.exports={arrayContainsArray:s,intToBuffer:o,getBinarySize:u,isHexPrefixed:d,stripHexPrefix:m,padToEven:n,intToHex:i,fromAscii:c,fromUtf8:f,toAscii:h,toUtf8:a,getKeys:l,isHexString:p}}).call(r,e(6).Buffer)},function(t,r,e){(function(t){!function(t,r){"use strict";function n(t,r){if(!t)throw Error(r||"Assertion failed")}function i(t,r){t.super_=r;var e=function(){};e.prototype=r.prototype,t.prototype=new e,t.prototype.constructor=t}function o(t,r,e){return o.isBN(t)?t:(this.negative=0,this.words=null,this.length=0,this.red=null,void(null!==t&&("le"!==r&&"be"!==r||(e=r,r=10),this._init(t||0,r||10,e||"be"))))}function u(t,r,e){for(var n=0,i=Math.min(t.length,e),o=r;i>o;o++){var u=t.charCodeAt(o)-48;n<<=4,n|=49>u||u>54?17>u||u>22?15&u:u-17+10:u-49+10}return n}function s(t,r,e,n){for(var i=0,o=Math.min(t.length,e),u=r;o>u;u++){var s=t.charCodeAt(u)-48;i*=n,i+=49>s?17>s?s:s-17+10:s-49+10}return i}function a(t){for(var r=Array(t.bitLength()),e=0;r.length>e;e++){var n=e/26|0,i=e%26;r[e]=(t.words[n]&1<>>i}return r}function h(t,r,e){e.negative=r.negative^t.negative;var n=t.length+r.length|0;e.length=n,n=n-1|0;var i=0|t.words[0],o=0|r.words[0],u=i*o,s=67108863&u,a=u/67108864|0;e.words[0]=s;for(var h=1;n>h;h++){for(var f=a>>>26,c=67108863&a,l=Math.min(h,r.length-1),p=Math.max(0,h-t.length+1);l>=p;p++){var d=h-p|0;i=0|t.words[d],o=0|r.words[p],u=i*o+c,f+=u/67108864|0,c=67108863&u}e.words[h]=0|c,a=0|f}return 0!==a?e.words[h]=0|a:e.length--,e.strip()}function f(t,r,e){e.negative=r.negative^t.negative,e.length=t.length+r.length;for(var n=0,i=0,o=0;e.length-1>o;o++){var u=i;i=0;for(var s=67108863&n,a=Math.min(o,r.length-1),h=Math.max(0,o-t.length+1);a>=h;h++){var f=o-h,c=0|t.words[f],l=0|r.words[h],p=c*l,d=67108863&p;u=u+(p/67108864|0)|0,d=d+s|0,s=67108863&d,u=u+(d>>>26)|0,i+=u>>>26,u&=67108863}e.words[o]=s,n=u,u=i}return 0!==n?e.words[o]=n:e.length--,e.strip()}function c(t,r,e){var n=new l;return n.mulp(t,r,e)}function l(t,r){this.x=t,this.y=r}function p(t,r){this.name=t,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function d(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function m(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function v(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function g(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function y(t){if("string"==typeof t){var r=o._prime(t);this.m=r.p,this.prime=r}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function w(t){y.call(this,t),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}"object"==typeof t?t.exports=o:r.BN=o,o.BN=o,o.wordSize=26;var M;try{M=e(6).Buffer}catch(b){}o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,r){return t.cmp(r)>0?t:r},o.min=function(t,r){return t.cmp(r)<0?t:r},o.prototype._init=function(t,r,e){if("number"==typeof t)return this._initNumber(t,r,e);if("object"==typeof t)return this._initArray(t,r,e);"hex"===r&&(r=16),n(r===(0|r)&&r>=2&&36>=r),t=(""+t).replace(/\s+/g,"");var i=0;"-"===t[0]&&i++,16===r?this._parseHex(t,i):this._parseBase(t,r,i),"-"===t[0]&&(this.negative=1),this.strip(),"le"===e&&this._initArray(this.toArray(),r,e)},o.prototype._initNumber=function(t,r,e){0>t&&(this.negative=1,t=-t),67108864>t?(this.words=[67108863&t],this.length=1):4503599627370496>t?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(n(9007199254740992>t),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===e&&this._initArray(this.toArray(),r,e)},o.prototype._initArray=function(t,r,e){if(n("number"==typeof t.length),0>=t.length)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=Array(this.length);for(var i=0;this.length>i;i++)this.words[i]=0;var o,u,s=0;if("be"===e)for(i=t.length-1,o=0;i>=0;i-=3)u=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=u<>>26-s&67108863,s+=24,26>s||(s-=26,o++);else if("le"===e)for(i=0,o=0;t.length>i;i+=3)u=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=u<>>26-s&67108863,s+=24,26>s||(s-=26,o++);return this.strip()},o.prototype._parseHex=function(t,r){this.length=Math.ceil((t.length-r)/6),this.words=Array(this.length);for(var e=0;this.length>e;e++)this.words[e]=0;var n,i,o=0;for(e=t.length-6,n=0;e>=r;e-=6)i=u(t,e,e+6),this.words[n]|=i<>>26-o&4194303,o+=24,26>o||(o-=26,n++);e+6!==r&&(i=u(t,r,e+6),this.words[n]|=i<>>26-o&4194303),this.strip()},o.prototype._parseBase=function(t,r,e){this.words=[0],this.length=1;for(var n=0,i=1;67108863>=i;i*=r)n++;n--,i=i/r|0;for(var o=t.length-e,u=o%n,a=Math.min(o,o-u)+e,h=0,f=e;a>f;f+=n)h=s(t,f,f+n,r),this.imuln(i),67108864>this.words[0]+h?this.words[0]+=h:this._iaddn(h);if(0!==u){var c=1;for(h=s(t,f,t.length,r),f=0;u>f;f++)c*=r;this.imuln(c),67108864>this.words[0]+h?this.words[0]+=h:this._iaddn(h)}},o.prototype.copy=function(t){t.words=Array(this.length);for(var r=0;this.length>r;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;t>this.length;)this.words[this.length++]=0;return this},o.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},o.prototype.inspect=function(){return(this.red?""};var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],_=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],E=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(t,r){t=t||10,r=0|r||1;var e;if(16===t||"hex"===t){e="";for(var i=0,o=0,u=0;this.length>u;u++){var s=this.words[u],a=(16777215&(s<>>24-i&16777215,e=0!==o||u!==this.length-1?x[6-a.length]+a+e:a+e,i+=2,26>i||(i-=26,u--)}for(0!==o&&(e=o.toString(16)+e);e.length%r!==0;)e="0"+e;return 0!==this.negative&&(e="-"+e),e}if(t===(0|t)&&t>=2&&36>=t){var h=_[t],f=E[t];e="";var c=this.clone();for(c.negative=0;!c.isZero();){var l=c.modn(f).toString(t);c=c.idivn(f),e=c.isZero()?l+e:x[h-l.length]+l+e}for(this.isZero()&&(e="0"+e);e.length%r!==0;)e="0"+e;return 0!==this.negative&&(e="-"+e),e}n(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(t,r){return n(void 0!==M),this.toArrayLike(M,t,r)},o.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},o.prototype.toArrayLike=function(t,r,e){var i=this.byteLength(),o=e||Math.max(1,i);n(o>=i,"byte array longer than desired length"),n(o>0,"Requested array length <= 0"),this.strip();var u,s,a="le"===r,h=new t(o),f=this.clone();if(a){for(s=0;!f.isZero();s++)u=f.andln(255),f.iushrn(8),h[s]=u;for(;o>s;s++)h[s]=0}else{for(s=0;o-i>s;s++)h[s]=0;for(s=0;!f.isZero();s++)u=f.andln(255),f.iushrn(8),h[o-s-1]=u}return h},o.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var r=t,e=0;return 4096>r||(e+=13,r>>>=13),64>r||(e+=7,r>>>=7),8>r||(e+=4,r>>>=4),2>r||(e+=2,r>>>=2),e+r},o.prototype._zeroBits=function(t){if(0===t)return 26;var r=t,e=0;return 0===(8191&r)&&(e+=13,r>>>=13),0===(127&r)&&(e+=7,r>>>=7),0===(15&r)&&(e+=4,r>>>=4),0===(3&r)&&(e+=2,r>>>=2),0===(1&r)&&e++,e},o.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return 26*(this.length-1)+r},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;this.length>r;r++){var e=this._zeroBits(this.words[r]);if(t+=e,26!==e)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;t.length>this.length;)this.words[this.length++]=0;for(var r=0;t.length>r;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},o.prototype.ior=function(t){return n(0===(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var r;r=this.length>t.length?t:this;for(var e=0;r.length>e;e++)this.words[e]=this.words[e]&t.words[e];return this.length=r.length,this.strip()},o.prototype.iand=function(t){return n(0===(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var r,e;this.length>t.length?(r=this,e=t):(r=t,e=this);for(var n=0;e.length>n;n++)this.words[n]=r.words[n]^e.words[n];if(this!==r)for(;r.length>n;n++)this.words[n]=r.words[n];return this.length=r.length,this.strip()},o.prototype.ixor=function(t){return n(0===(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){n("number"==typeof t&&t>=0);var r=0|Math.ceil(t/26),e=t%26;this._expand(r),e>0&&r--;for(var i=0;r>i;i++)this.words[i]=67108863&~this.words[i];return e>0&&(this.words[i]=~this.words[i]&67108863>>26-e),this.strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,r){n("number"==typeof t&&t>=0);var e=t/26|0,i=t%26;return this._expand(e+1),this.words[e]=r?this.words[e]|1<t.length?(e=this,n=t):(e=t,n=this);for(var i=0,o=0;n.length>o;o++)r=(0|e.words[o])+(0|n.words[o])+i,this.words[o]=67108863&r,i=r>>>26;for(;0!==i&&e.length>o;o++)r=(0|e.words[o])+i,this.words[o]=67108863&r,i=r>>>26;if(this.length=e.length,0!==i)this.words[this.length]=i,this.length++;else if(e!==this)for(;e.length>o;o++)this.words[o]=e.words[o];return this},o.prototype.add=function(t){var r;return 0!==t.negative&&0===this.negative?(t.negative=0,r=this.sub(t),t.negative^=1,r):0===t.negative&&0!==this.negative?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e=this.cmp(t);if(0===e)return this.negative=0,this.length=1,this.words[0]=0,this;var n,i;e>0?(n=this,i=t):(n=t,i=this);for(var o=0,u=0;i.length>u;u++)r=(0|n.words[u])-(0|i.words[u])+o,o=r>>26,this.words[u]=67108863&r;for(;0!==o&&n.length>u;u++)r=(0|n.words[u])+o,o=r>>26,this.words[u]=67108863&r;if(0===o&&n.length>u&&n!==this)for(;n.length>u;u++)this.words[u]=n.words[u];return this.length=Math.max(this.length,u),n!==this&&(this.negative=1),this.strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var A=function(t,r,e){var n,i,o,u=t.words,s=r.words,a=e.words,h=0,f=0|u[0],c=8191&f,l=f>>>13,p=0|u[1],d=8191&p,m=p>>>13,v=0|u[2],g=8191&v,y=v>>>13,w=0|u[3],M=8191&w,b=w>>>13,x=0|u[4],_=8191&x,E=x>>>13,A=0|u[5],S=8191&A,T=A>>>13,k=0|u[6],j=8191&k,B=k>>>13,P=0|u[7],O=8191&P,R=P>>>13,L=0|u[8],I=8191&L,C=L>>>13,N=0|u[9],U=8191&N,F=N>>>13,Y=0|s[0],q=8191&Y,D=Y>>>13,Z=0|s[1],z=8191&Z,K=Z>>>13,G=0|s[2],H=8191&G,J=G>>>13,V=0|s[3],$=8191&V,W=V>>>13,Q=0|s[4],X=8191&Q,tt=Q>>>13,rt=0|s[5],et=8191&rt,nt=rt>>>13,it=0|s[6],ot=8191&it,ut=it>>>13,st=0|s[7],at=8191&st,ht=st>>>13,ft=0|s[8],ct=8191&ft,lt=ft>>>13,pt=0|s[9],dt=8191&pt,mt=pt>>>13;e.negative=t.negative^r.negative,e.length=19,n=Math.imul(c,q),i=Math.imul(c,D),i=i+Math.imul(l,q)|0,o=Math.imul(l,D);var vt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(d,q),i=Math.imul(d,D),i=i+Math.imul(m,q)|0,o=Math.imul(m,D),n=n+Math.imul(c,z)|0,i=i+Math.imul(c,K)|0,i=i+Math.imul(l,z)|0,o=o+Math.imul(l,K)|0;var gt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(g,q),i=Math.imul(g,D),i=i+Math.imul(y,q)|0,o=Math.imul(y,D),n=n+Math.imul(d,z)|0,i=i+Math.imul(d,K)|0,i=i+Math.imul(m,z)|0,o=o+Math.imul(m,K)|0,n=n+Math.imul(c,H)|0,i=i+Math.imul(c,J)|0,i=i+Math.imul(l,H)|0,o=o+Math.imul(l,J)|0;var yt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(M,q),i=Math.imul(M,D),i=i+Math.imul(b,q)|0,o=Math.imul(b,D),n=n+Math.imul(g,z)|0,i=i+Math.imul(g,K)|0,i=i+Math.imul(y,z)|0,o=o+Math.imul(y,K)|0,n=n+Math.imul(d,H)|0,i=i+Math.imul(d,J)|0,i=i+Math.imul(m,H)|0,o=o+Math.imul(m,J)|0,n=n+Math.imul(c,$)|0,i=i+Math.imul(c,W)|0,i=i+Math.imul(l,$)|0,o=o+Math.imul(l,W)|0;var wt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(_,q),i=Math.imul(_,D),i=i+Math.imul(E,q)|0,o=Math.imul(E,D),n=n+Math.imul(M,z)|0,i=i+Math.imul(M,K)|0,i=i+Math.imul(b,z)|0,o=o+Math.imul(b,K)|0,n=n+Math.imul(g,H)|0,i=i+Math.imul(g,J)|0,i=i+Math.imul(y,H)|0,o=o+Math.imul(y,J)|0,n=n+Math.imul(d,$)|0,i=i+Math.imul(d,W)|0,i=i+Math.imul(m,$)|0,o=o+Math.imul(m,W)|0,n=n+Math.imul(c,X)|0,i=i+Math.imul(c,tt)|0,i=i+Math.imul(l,X)|0,o=o+Math.imul(l,tt)|0;var Mt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(S,q),i=Math.imul(S,D),i=i+Math.imul(T,q)|0,o=Math.imul(T,D),n=n+Math.imul(_,z)|0,i=i+Math.imul(_,K)|0,i=i+Math.imul(E,z)|0,o=o+Math.imul(E,K)|0,n=n+Math.imul(M,H)|0,i=i+Math.imul(M,J)|0,i=i+Math.imul(b,H)|0,o=o+Math.imul(b,J)|0,n=n+Math.imul(g,$)|0,i=i+Math.imul(g,W)|0,i=i+Math.imul(y,$)|0,o=o+Math.imul(y,W)|0,n=n+Math.imul(d,X)|0,i=i+Math.imul(d,tt)|0,i=i+Math.imul(m,X)|0, 10 | o=o+Math.imul(m,tt)|0,n=n+Math.imul(c,et)|0,i=i+Math.imul(c,nt)|0,i=i+Math.imul(l,et)|0,o=o+Math.imul(l,nt)|0;var bt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(j,q),i=Math.imul(j,D),i=i+Math.imul(B,q)|0,o=Math.imul(B,D),n=n+Math.imul(S,z)|0,i=i+Math.imul(S,K)|0,i=i+Math.imul(T,z)|0,o=o+Math.imul(T,K)|0,n=n+Math.imul(_,H)|0,i=i+Math.imul(_,J)|0,i=i+Math.imul(E,H)|0,o=o+Math.imul(E,J)|0,n=n+Math.imul(M,$)|0,i=i+Math.imul(M,W)|0,i=i+Math.imul(b,$)|0,o=o+Math.imul(b,W)|0,n=n+Math.imul(g,X)|0,i=i+Math.imul(g,tt)|0,i=i+Math.imul(y,X)|0,o=o+Math.imul(y,tt)|0,n=n+Math.imul(d,et)|0,i=i+Math.imul(d,nt)|0,i=i+Math.imul(m,et)|0,o=o+Math.imul(m,nt)|0,n=n+Math.imul(c,ot)|0,i=i+Math.imul(c,ut)|0,i=i+Math.imul(l,ot)|0,o=o+Math.imul(l,ut)|0;var xt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(O,q),i=Math.imul(O,D),i=i+Math.imul(R,q)|0,o=Math.imul(R,D),n=n+Math.imul(j,z)|0,i=i+Math.imul(j,K)|0,i=i+Math.imul(B,z)|0,o=o+Math.imul(B,K)|0,n=n+Math.imul(S,H)|0,i=i+Math.imul(S,J)|0,i=i+Math.imul(T,H)|0,o=o+Math.imul(T,J)|0,n=n+Math.imul(_,$)|0,i=i+Math.imul(_,W)|0,i=i+Math.imul(E,$)|0,o=o+Math.imul(E,W)|0,n=n+Math.imul(M,X)|0,i=i+Math.imul(M,tt)|0,i=i+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(g,et)|0,i=i+Math.imul(g,nt)|0,i=i+Math.imul(y,et)|0,o=o+Math.imul(y,nt)|0,n=n+Math.imul(d,ot)|0,i=i+Math.imul(d,ut)|0,i=i+Math.imul(m,ot)|0,o=o+Math.imul(m,ut)|0,n=n+Math.imul(c,at)|0,i=i+Math.imul(c,ht)|0,i=i+Math.imul(l,at)|0,o=o+Math.imul(l,ht)|0;var _t=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(I,q),i=Math.imul(I,D),i=i+Math.imul(C,q)|0,o=Math.imul(C,D),n=n+Math.imul(O,z)|0,i=i+Math.imul(O,K)|0,i=i+Math.imul(R,z)|0,o=o+Math.imul(R,K)|0,n=n+Math.imul(j,H)|0,i=i+Math.imul(j,J)|0,i=i+Math.imul(B,H)|0,o=o+Math.imul(B,J)|0,n=n+Math.imul(S,$)|0,i=i+Math.imul(S,W)|0,i=i+Math.imul(T,$)|0,o=o+Math.imul(T,W)|0,n=n+Math.imul(_,X)|0,i=i+Math.imul(_,tt)|0,i=i+Math.imul(E,X)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(M,et)|0,i=i+Math.imul(M,nt)|0,i=i+Math.imul(b,et)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(g,ot)|0,i=i+Math.imul(g,ut)|0,i=i+Math.imul(y,ot)|0,o=o+Math.imul(y,ut)|0,n=n+Math.imul(d,at)|0,i=i+Math.imul(d,ht)|0,i=i+Math.imul(m,at)|0,o=o+Math.imul(m,ht)|0,n=n+Math.imul(c,ct)|0,i=i+Math.imul(c,lt)|0,i=i+Math.imul(l,ct)|0,o=o+Math.imul(l,lt)|0;var Et=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(U,q),i=Math.imul(U,D),i=i+Math.imul(F,q)|0,o=Math.imul(F,D),n=n+Math.imul(I,z)|0,i=i+Math.imul(I,K)|0,i=i+Math.imul(C,z)|0,o=o+Math.imul(C,K)|0,n=n+Math.imul(O,H)|0,i=i+Math.imul(O,J)|0,i=i+Math.imul(R,H)|0,o=o+Math.imul(R,J)|0,n=n+Math.imul(j,$)|0,i=i+Math.imul(j,W)|0,i=i+Math.imul(B,$)|0,o=o+Math.imul(B,W)|0,n=n+Math.imul(S,X)|0,i=i+Math.imul(S,tt)|0,i=i+Math.imul(T,X)|0,o=o+Math.imul(T,tt)|0,n=n+Math.imul(_,et)|0,i=i+Math.imul(_,nt)|0,i=i+Math.imul(E,et)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(M,ot)|0,i=i+Math.imul(M,ut)|0,i=i+Math.imul(b,ot)|0,o=o+Math.imul(b,ut)|0,n=n+Math.imul(g,at)|0,i=i+Math.imul(g,ht)|0,i=i+Math.imul(y,at)|0,o=o+Math.imul(y,ht)|0,n=n+Math.imul(d,ct)|0,i=i+Math.imul(d,lt)|0,i=i+Math.imul(m,ct)|0,o=o+Math.imul(m,lt)|0,n=n+Math.imul(c,dt)|0,i=i+Math.imul(c,mt)|0,i=i+Math.imul(l,dt)|0,o=o+Math.imul(l,mt)|0;var At=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(U,z),i=Math.imul(U,K),i=i+Math.imul(F,z)|0,o=Math.imul(F,K),n=n+Math.imul(I,H)|0,i=i+Math.imul(I,J)|0,i=i+Math.imul(C,H)|0,o=o+Math.imul(C,J)|0,n=n+Math.imul(O,$)|0,i=i+Math.imul(O,W)|0,i=i+Math.imul(R,$)|0,o=o+Math.imul(R,W)|0,n=n+Math.imul(j,X)|0,i=i+Math.imul(j,tt)|0,i=i+Math.imul(B,X)|0,o=o+Math.imul(B,tt)|0,n=n+Math.imul(S,et)|0,i=i+Math.imul(S,nt)|0,i=i+Math.imul(T,et)|0,o=o+Math.imul(T,nt)|0,n=n+Math.imul(_,ot)|0,i=i+Math.imul(_,ut)|0,i=i+Math.imul(E,ot)|0,o=o+Math.imul(E,ut)|0,n=n+Math.imul(M,at)|0,i=i+Math.imul(M,ht)|0,i=i+Math.imul(b,at)|0,o=o+Math.imul(b,ht)|0,n=n+Math.imul(g,ct)|0,i=i+Math.imul(g,lt)|0,i=i+Math.imul(y,ct)|0,o=o+Math.imul(y,lt)|0,n=n+Math.imul(d,dt)|0,i=i+Math.imul(d,mt)|0,i=i+Math.imul(m,dt)|0,o=o+Math.imul(m,mt)|0;var St=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(U,H),i=Math.imul(U,J),i=i+Math.imul(F,H)|0,o=Math.imul(F,J),n=n+Math.imul(I,$)|0,i=i+Math.imul(I,W)|0,i=i+Math.imul(C,$)|0,o=o+Math.imul(C,W)|0,n=n+Math.imul(O,X)|0,i=i+Math.imul(O,tt)|0,i=i+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,n=n+Math.imul(j,et)|0,i=i+Math.imul(j,nt)|0,i=i+Math.imul(B,et)|0,o=o+Math.imul(B,nt)|0,n=n+Math.imul(S,ot)|0,i=i+Math.imul(S,ut)|0,i=i+Math.imul(T,ot)|0,o=o+Math.imul(T,ut)|0,n=n+Math.imul(_,at)|0,i=i+Math.imul(_,ht)|0,i=i+Math.imul(E,at)|0,o=o+Math.imul(E,ht)|0,n=n+Math.imul(M,ct)|0,i=i+Math.imul(M,lt)|0,i=i+Math.imul(b,ct)|0,o=o+Math.imul(b,lt)|0,n=n+Math.imul(g,dt)|0,i=i+Math.imul(g,mt)|0,i=i+Math.imul(y,dt)|0,o=o+Math.imul(y,mt)|0;var Tt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(U,$),i=Math.imul(U,W),i=i+Math.imul(F,$)|0,o=Math.imul(F,W),n=n+Math.imul(I,X)|0,i=i+Math.imul(I,tt)|0,i=i+Math.imul(C,X)|0,o=o+Math.imul(C,tt)|0,n=n+Math.imul(O,et)|0,i=i+Math.imul(O,nt)|0,i=i+Math.imul(R,et)|0,o=o+Math.imul(R,nt)|0,n=n+Math.imul(j,ot)|0,i=i+Math.imul(j,ut)|0,i=i+Math.imul(B,ot)|0,o=o+Math.imul(B,ut)|0,n=n+Math.imul(S,at)|0,i=i+Math.imul(S,ht)|0,i=i+Math.imul(T,at)|0,o=o+Math.imul(T,ht)|0,n=n+Math.imul(_,ct)|0,i=i+Math.imul(_,lt)|0,i=i+Math.imul(E,ct)|0,o=o+Math.imul(E,lt)|0,n=n+Math.imul(M,dt)|0,i=i+Math.imul(M,mt)|0,i=i+Math.imul(b,dt)|0,o=o+Math.imul(b,mt)|0;var kt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(U,X),i=Math.imul(U,tt),i=i+Math.imul(F,X)|0,o=Math.imul(F,tt),n=n+Math.imul(I,et)|0,i=i+Math.imul(I,nt)|0,i=i+Math.imul(C,et)|0,o=o+Math.imul(C,nt)|0,n=n+Math.imul(O,ot)|0,i=i+Math.imul(O,ut)|0,i=i+Math.imul(R,ot)|0,o=o+Math.imul(R,ut)|0,n=n+Math.imul(j,at)|0,i=i+Math.imul(j,ht)|0,i=i+Math.imul(B,at)|0,o=o+Math.imul(B,ht)|0,n=n+Math.imul(S,ct)|0,i=i+Math.imul(S,lt)|0,i=i+Math.imul(T,ct)|0,o=o+Math.imul(T,lt)|0,n=n+Math.imul(_,dt)|0,i=i+Math.imul(_,mt)|0,i=i+Math.imul(E,dt)|0,o=o+Math.imul(E,mt)|0;var jt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(jt>>>26)|0,jt&=67108863,n=Math.imul(U,et),i=Math.imul(U,nt),i=i+Math.imul(F,et)|0,o=Math.imul(F,nt),n=n+Math.imul(I,ot)|0,i=i+Math.imul(I,ut)|0,i=i+Math.imul(C,ot)|0,o=o+Math.imul(C,ut)|0,n=n+Math.imul(O,at)|0,i=i+Math.imul(O,ht)|0,i=i+Math.imul(R,at)|0,o=o+Math.imul(R,ht)|0,n=n+Math.imul(j,ct)|0,i=i+Math.imul(j,lt)|0,i=i+Math.imul(B,ct)|0,o=o+Math.imul(B,lt)|0,n=n+Math.imul(S,dt)|0,i=i+Math.imul(S,mt)|0,i=i+Math.imul(T,dt)|0,o=o+Math.imul(T,mt)|0;var Bt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(U,ot),i=Math.imul(U,ut),i=i+Math.imul(F,ot)|0,o=Math.imul(F,ut),n=n+Math.imul(I,at)|0,i=i+Math.imul(I,ht)|0,i=i+Math.imul(C,at)|0,o=o+Math.imul(C,ht)|0,n=n+Math.imul(O,ct)|0,i=i+Math.imul(O,lt)|0,i=i+Math.imul(R,ct)|0,o=o+Math.imul(R,lt)|0,n=n+Math.imul(j,dt)|0,i=i+Math.imul(j,mt)|0,i=i+Math.imul(B,dt)|0,o=o+Math.imul(B,mt)|0;var Pt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(U,at),i=Math.imul(U,ht),i=i+Math.imul(F,at)|0,o=Math.imul(F,ht),n=n+Math.imul(I,ct)|0,i=i+Math.imul(I,lt)|0,i=i+Math.imul(C,ct)|0,o=o+Math.imul(C,lt)|0,n=n+Math.imul(O,dt)|0,i=i+Math.imul(O,mt)|0,i=i+Math.imul(R,dt)|0,o=o+Math.imul(R,mt)|0;var Ot=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,n=Math.imul(U,ct),i=Math.imul(U,lt),i=i+Math.imul(F,ct)|0,o=Math.imul(F,lt),n=n+Math.imul(I,dt)|0,i=i+Math.imul(I,mt)|0,i=i+Math.imul(C,dt)|0,o=o+Math.imul(C,mt)|0;var Rt=(h+n|0)+((8191&i)<<13)|0;h=(o+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(U,dt),i=Math.imul(U,mt),i=i+Math.imul(F,dt)|0,o=Math.imul(F,mt);var Lt=(h+n|0)+((8191&i)<<13)|0;return h=(o+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,a[0]=vt,a[1]=gt,a[2]=yt,a[3]=wt,a[4]=Mt,a[5]=bt,a[6]=xt,a[7]=_t,a[8]=Et,a[9]=At,a[10]=St,a[11]=Tt,a[12]=kt,a[13]=jt,a[14]=Bt,a[15]=Pt,a[16]=Ot,a[17]=Rt,a[18]=Lt,0!==h&&(a[19]=h,e.length++),e};Math.imul||(A=h),o.prototype.mulTo=function(t,r){var e,n=this.length+t.length;return e=10===this.length&&10===t.length?A(this,t,r):63>n?h(this,t,r):1024>n?f(this,t,r):c(this,t,r)},l.prototype.makeRBT=function(t){for(var r=Array(t),e=o.prototype._countBits(t)-1,n=0;t>n;n++)r[n]=this.revBin(n,e,t);return r},l.prototype.revBin=function(t,r,e){if(0===t||t===e-1)return t;for(var n=0,i=0;r>i;i++)n|=(1&t)<>=1;return n},l.prototype.permute=function(t,r,e,n,i,o){for(var u=0;o>u;u++)n[u]=r[t[u]],i[u]=e[t[u]]},l.prototype.transform=function(t,r,e,n,i,o){this.permute(o,t,r,e,n,i);for(var u=1;i>u;u<<=1)for(var s=u<<1,a=Math.cos(2*Math.PI/s),h=Math.sin(2*Math.PI/s),f=0;i>f;f+=s)for(var c=a,l=h,p=0;u>p;p++){var d=e[f+p],m=n[f+p],v=e[f+p+u],g=n[f+p+u],y=c*v-l*g;g=c*g+l*v,v=y,e[f+p]=d+v,n[f+p]=m+g,e[f+p+u]=d-v,n[f+p+u]=m-g,p!==s&&(y=a*c-h*l,l=a*l+h*c,c=y)}},l.prototype.guessLen13b=function(t,r){var e=1|Math.max(r,t),n=1&e,i=0;for(e=e/2|0;e;e>>>=1)i++;return 1<1)for(var n=0;e/2>n;n++){var i=t[n];t[n]=t[e-n-1],t[e-n-1]=i,i=r[n],r[n]=-r[e-n-1],r[e-n-1]=-i}},l.prototype.normalize13b=function(t,r){for(var e=0,n=0;r/2>n;n++){var i=8192*Math.round(t[2*n+1]/r)+Math.round(t[2*n]/r)+e;t[n]=67108863&i,e=67108864>i?0:i/67108864|0}return t},l.prototype.convert13b=function(t,r,e,i){for(var o=0,u=0;r>u;u++)o+=0|t[u],e[2*u]=8191&o,o>>>=13,e[2*u+1]=8191&o,o>>>=13;for(u=2*r;i>u;++u)e[u]=0;n(0===o),n(0===(o&-8192))},l.prototype.stub=function(t){for(var r=Array(t),e=0;t>e;e++)r[e]=0;return r},l.prototype.mulp=function(t,r,e){var n=2*this.guessLen13b(t.length,r.length),i=this.makeRBT(n),o=this.stub(n),u=Array(n),s=Array(n),a=Array(n),h=Array(n),f=Array(n),c=Array(n),l=e.words;l.length=n,this.convert13b(t.words,t.length,u,n),this.convert13b(r.words,r.length,h,n),this.transform(u,o,s,a,n,i),this.transform(h,o,f,c,n,i);for(var p=0;n>p;p++){var d=s[p]*f[p]-a[p]*c[p];a[p]=s[p]*c[p]+a[p]*f[p],s[p]=d}return this.conjugate(s,a,n),this.transform(s,a,l,o,n,i),this.conjugate(l,o,n),this.normalize13b(l,n),e.negative=t.negative^r.negative,e.length=t.length+r.length,e.strip()},o.prototype.mul=function(t){var r=new o(null);return r.words=Array(this.length+t.length),this.mulTo(t,r)},o.prototype.mulf=function(t){var r=new o(null);return r.words=Array(this.length+t.length),c(this,t,r)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){n("number"==typeof t),n(67108864>t);for(var r=0,e=0;this.length>e;e++){var i=(0|this.words[e])*t,o=(67108863&i)+(67108863&r);r>>=26,r+=i/67108864|0,r+=o>>>26,this.words[e]=67108863&o}return 0!==r&&(this.words[e]=r,this.length++),this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var r=a(t);if(0===r.length)return new o(1);for(var e=this,n=0;r.length>n&&0===r[n];n++,e=e.sqr());if(++nn;n++,i=i.sqr())0!==r[n]&&(e=e.mul(i));return e},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var r,e=t%26,i=(t-e)/26,o=67108863>>>26-e<<26-e;if(0!==e){var u=0;for(r=0;this.length>r;r++){var s=this.words[r]&o,a=(0|this.words[r])-s<>>26-e}u&&(this.words[r]=u,this.length++)}if(0!==i){for(r=this.length-1;r>=0;r--)this.words[r+i]=this.words[r];for(r=0;i>r;r++)this.words[r]=0;this.length+=i}return this.strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,r,e){n("number"==typeof t&&t>=0);var i;i=r?(r-r%26)/26:0;var o=t%26,u=Math.min((t-o)/26,this.length),s=67108863^67108863>>>o<h;h++)a.words[h]=this.words[h];a.length=u}if(0===u);else if(this.length>u)for(this.length-=u,h=0;this.length>h;h++)this.words[h]=this.words[h+u];else this.words[0]=0,this.length=1;var f=0;for(h=this.length-1;!(0>h||0===f&&i>h);h--){var c=0|this.words[h];this.words[h]=f<<26-o|c>>>o,f=c&s}return a&&0!==f&&(a.words[a.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(t,r,e){return n(0===this.negative),this.iushrn(t,r,e)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){n("number"==typeof t&&t>=0);var r=t%26,e=(t-r)/26,i=1<=this.length)return!1;var o=this.words[e];return!!(o&i)},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var r=t%26,e=(t-r)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),e>=this.length)return this;if(0!==r&&e++,this.length=Math.min(e,this.length),0!==r){var i=67108863^67108863>>>r<t),0>t?this.isubn(-t):0!==this.negative?1===this.length&&t>(0|this.words[0])?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;this.length>r&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},o.prototype.isubn=function(t){if(n("number"==typeof t),n(67108864>t),0>t)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&0>this.words[0])this.words[0]=-this.words[0],this.negative=1;else for(var r=0;this.length>r&&0>this.words[r];r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,r,e){var i,o=t.length+e;this._expand(o);var u,s=0;for(i=0;t.length>i;i++){u=(0|this.words[i+e])+s;var a=(0|t.words[i])*r;u-=67108863&a,s=(u>>26)-(a/67108864|0),this.words[i+e]=67108863&u}for(;this.length-e>i;i++)u=(0|this.words[i+e])+s,s=u>>26,this.words[i+e]=67108863&u;if(0===s)return this.strip();for(n(s===-1),s=0,i=0;this.length>i;i++)u=-(0|this.words[i])+s,s=u>>26,this.words[i]=67108863&u;return this.negative=1,this.strip()},o.prototype._wordDiv=function(t,r){var e=this.length-t.length,n=this.clone(),i=t,u=0|i.words[i.length-1],s=this._countBits(u);e=26-s,0!==e&&(i=i.ushln(e),n.iushln(e),u=0|i.words[i.length-1]);var a,h=n.length-i.length;if("mod"!==r){a=new o(null),a.length=h+1,a.words=Array(a.length);for(var f=0;a.length>f;f++)a.words[f]=0}var c=n.clone()._ishlnsubmul(i,1,h);0===c.negative&&(n=c,a&&(a.words[h]=1));for(var l=h-1;l>=0;l--){var p=67108864*(0|n.words[i.length+l])+(0|n.words[i.length+l-1]);for(p=Math.min(p/u|0,67108863),n._ishlnsubmul(i,p,l);0!==n.negative;)p--,n.negative=0,n._ishlnsubmul(i,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=p)}return a&&a.strip(),n.strip(),"div"!==r&&0!==e&&n.iushrn(e),{div:a||null,mod:n}},o.prototype.divmod=function(t,r,e){if(n(!t.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var i,u,s;return 0!==this.negative&&0===t.negative?(s=this.neg().divmod(t,r),"mod"!==r&&(i=s.div.neg()),"div"!==r&&(u=s.mod.neg(),e&&0!==u.negative&&u.iadd(t)),{div:i,mod:u}):0===this.negative&&0!==t.negative?(s=this.divmod(t.neg(),r),"mod"!==r&&(i=s.div.neg()),{div:i,mod:s.mod}):0!==(this.negative&t.negative)?(s=this.neg().divmod(t.neg(),r),"div"!==r&&(u=s.mod.neg(),e&&0!==u.negative&&u.isub(t)),{div:s.div,mod:u}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===r?{div:this.divn(t.words[0]),mod:null}:"mod"===r?{div:null,mod:new o(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modn(t.words[0]))}:this._wordDiv(t,r)},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var e=0!==r.div.negative?r.mod.isub(t):r.mod,n=t.ushrn(1),i=t.andln(1),o=e.cmp(n);return 0>o||1===i&&0===o?r.div:0!==r.div.negative?r.div.isubn(1):r.div.iaddn(1)},o.prototype.modn=function(t){n(67108863>=t);for(var r=(1<<26)%t,e=0,i=this.length-1;i>=0;i--)e=(r*e+(0|this.words[i]))%t;return e},o.prototype.idivn=function(t){n(67108863>=t);for(var r=0,e=this.length-1;e>=0;e--){var i=(0|this.words[e])+67108864*r;this.words[e]=i/t|0,r=i%t}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var r=this,e=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var i=new o(1),u=new o(0),s=new o(0),a=new o(1),h=0;r.isEven()&&e.isEven();)r.iushrn(1),e.iushrn(1),++h;for(var f=e.clone(),c=r.clone();!r.isZero();){for(var l=0,p=1;0===(r.words[0]&p)&&26>l;++l,p<<=1);if(l>0)for(r.iushrn(l);l-- >0;)(i.isOdd()||u.isOdd())&&(i.iadd(f),u.isub(c)),i.iushrn(1),u.iushrn(1);for(var d=0,m=1;0===(e.words[0]&m)&&26>d;++d,m<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||a.isOdd())&&(s.iadd(f),a.isub(c)),s.iushrn(1),a.iushrn(1);r.cmp(e)<0?(e.isub(r),s.isub(i),a.isub(u)):(r.isub(e),i.isub(s),u.isub(a))}return{a:s,b:a,gcd:e.iushln(h)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var r=this,e=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var i=new o(1),u=new o(0),s=e.clone();r.cmpn(1)>0&&e.cmpn(1)>0;){for(var a=0,h=1;0===(r.words[0]&h)&&26>a;++a,h<<=1);if(a>0)for(r.iushrn(a);a-- >0;)i.isOdd()&&i.iadd(s),i.iushrn(1);for(var f=0,c=1;0===(e.words[0]&c)&&26>f;++f,c<<=1);if(f>0)for(e.iushrn(f);f-- >0;)u.isOdd()&&u.iadd(s),u.iushrn(1);r.cmp(e)<0?(e.isub(r),u.isub(i)):(r.isub(e),i.isub(u))}var l;return l=0===r.cmpn(1)?i:u,l.cmpn(0)<0&&l.iadd(t),l},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),e=t.clone();r.negative=0,e.negative=0;for(var n=0;r.isEven()&&e.isEven();n++)r.iushrn(1),e.iushrn(1);for(;;){for(;r.isEven();)r.iushrn(1);for(;e.isEven();)e.iushrn(1);var i=r.cmp(e);if(0>i){var o=r;r=e,e=o}else if(0===i||0===e.cmpn(1))break;r.isub(e)}return e.iushln(n)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0===(1&this.words[0])},o.prototype.isOdd=function(){return 1===(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){n("number"==typeof t);var r=t%26,e=(t-r)/26,i=1<=this.length)return this._expand(e+1),this.words[e]|=i,this;for(var o=i,u=e;0!==o&&this.length>u;u++){var s=0|this.words[u];s+=o,o=s>>>26,s&=67108863,this.words[u]=s}return 0!==o&&(this.words[u]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var r=0>t;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;this.strip();var e;if(this.length>1)e=1;else{r&&(t=-t),n(67108863>=t,"Number is too big");var i=0|this.words[0];e=i===t?0:t>i?-1:1}return 0!==this.negative?0|-e:e},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var r=this.ucmp(t);return 0!==this.negative?0|-r:r},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(t.length>this.length)return-1;for(var r=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],i=0|t.words[e];if(n!==i){i>n?r=-1:n>i&&(r=1);break}}return r},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return this.cmpn(t)===-1},o.prototype.lt=function(t){return this.cmp(t)===-1},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new y(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var S={k256:null,p224:null,p192:null,p25519:null};p.prototype._tmp=function(){var t=new o(null);return t.words=Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var r,e=t;do this.split(e,this.tmp),e=this.imulK(e),e=e.iadd(this.tmp),r=e.bitLength();while(r>this.n);var n=this.n>r?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):e.strip(),e},p.prototype.split=function(t,r){t.iushrn(this.n,0,r)},p.prototype.imulK=function(t){return t.imul(this.k)},i(d,p),d.prototype.split=function(t,r){for(var e=4194303,n=Math.min(t.length,9),i=0;n>i;i++)r.words[i]=t.words[i];if(r.length=n,9>=t.length)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(r.words[r.length++]=o&e,i=10;t.length>i;i++){var u=0|t.words[i];t.words[i-10]=(u&e)<<4|o>>>22,o=u}o>>>=22,t.words[i-10]=o,t.length-=0===o&&t.length>10?10:9},d.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,e=0;t.length>e;e++){var n=0|t.words[e];r+=977*n,t.words[e]=67108863&r,r=64*n+(r/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},i(m,p),i(v,p),i(g,p),g.prototype.imulK=function(t){for(var r=0,e=0;t.length>e;e++){var n=19*(0|t.words[e])+r,i=67108863&n;n>>>=26,t.words[e]=i,r=n}return 0!==r&&(t.words[t.length++]=r),t},o._prime=function T(t){if(S[t])return S[t];var T;if("k256"===t)T=new d;else if("p224"===t)T=new m;else if("p192"===t)T=new v;else{if("p25519"!==t)throw Error("Unknown prime "+t);T=new g}return S[t]=T,T},y.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},y.prototype._verify2=function(t,r){n(0===(t.negative|r.negative),"red works only with positives"),n(t.red&&t.red===r.red,"red works only with red numbers")},y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},y.prototype.add=function(t,r){this._verify2(t,r);var e=t.add(r);return e.cmp(this.m)<0||e.isub(this.m),e._forceRed(this)},y.prototype.iadd=function(t,r){this._verify2(t,r);var e=t.iadd(r);return e.cmp(this.m)<0||e.isub(this.m),e},y.prototype.sub=function(t,r){this._verify2(t,r);var e=t.sub(r);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},y.prototype.isub=function(t,r){this._verify2(t,r);var e=t.isub(r);return e.cmpn(0)<0&&e.iadd(this.m),e},y.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},y.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},y.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},y.prototype.isqr=function(t){return this.imul(t,t.clone())},y.prototype.sqr=function(t){return this.mul(t,t)},y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(n(r%2===1),3===r){var e=this.m.add(new o(1)).iushrn(2);return this.pow(t,e)}for(var i=this.m.subn(1),u=0;!i.isZero()&&0===i.andln(1);)u++,i.iushrn(1);n(!i.isZero());var s=new o(1).toRed(this),a=s.redNeg(),h=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new o(2*f*f).toRed(this);0!==this.pow(f,h).cmp(a);)f.redIAdd(a);for(var c=this.pow(f,i),l=this.pow(t,i.addn(1).iushrn(1)),p=this.pow(t,i),d=u;0!==p.cmp(s);){for(var m=p,v=0;0!==m.cmp(s);v++)m=m.redSqr();n(d>v);var g=this.pow(c,new o(1).iushln(d-v-1));l=l.redMul(g),c=g.redSqr(),p=p.redMul(c),d=v}return l},y.prototype.invm=function(t){var r=t._invmp(this.m);return 0!==r.negative?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},y.prototype.pow=function(t,r){if(r.isZero())return new o(1);if(0===r.cmpn(1))return t.clone();var e=4,n=Array(1<i;i++)n[i]=this.mul(n[i-1],t);var u=n[0],s=0,a=0,h=r.bitLength()%26;for(0===h&&(h=26),i=r.length-1;i>=0;i--){for(var f=r.words[i],c=h-1;c>=0;c--){var l=f>>c&1;u!==n[0]&&(u=this.sqr(u)),0!==l||0!==s?(s<<=1,s|=l,a++,(a===e||0===i&&0===c)&&(u=this.mul(u,n[s]),a=0,s=0)):a=0}h=26}return u},y.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},y.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},o.mont=function(t){return new w(t)},i(w,y),w.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},w.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},w.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(r),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=e.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)<0?i.cmpn(0)<0&&(o=i.iadd(this.m)):o=i.isub(this.m),o._forceRed(this)},w.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new o(0)._forceRed(this);var e=t.mul(r),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=e.isub(n).iushrn(this.shift),u=i;return i.cmp(this.m)<0?i.cmpn(0)<0&&(u=i.iadd(this.m)):u=i.isub(this.m),u._forceRed(this)},w.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}}(void 0===t||t,this)}).call(r,e(109)(t))},function(t,r,e){var n=e(11),i=e(1)("toStringTag"),o="Arguments"==n(function(){return arguments}()),u=function(t,r){try{return t[r]}catch(e){}};t.exports=function(t){var r,e,s;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(e=u(r=Object(t),i))?e:o?n(r):"Object"==(s=n(r))&&"function"==typeof r.callee?"Arguments":s}},function(t,r){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,r,e){var n=e(0).document;t.exports=n&&n.documentElement},function(t,r,e){var n=e(11);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==n(t)?t.split(""):Object(t)}},function(t,r,e){"use strict";var n=e(38),i=e(4),o=e(83),u=e(5),s=e(9),a=e(70),h=e(21),f=e(78),c=e(1)("iterator"),l=!([].keys&&"next"in[].keys()),p="@@iterator",d="keys",m="values",v=function(){return this};t.exports=function(t,r,e,g,y,w,M){a(e,r,g);var b,x,_,E=function(t){if(!l&&t in k)return k[t];switch(t){case d:return function(){return new e(this,t)};case m:return function(){return new e(this,t)}}return function(){return new e(this,t)}},A=r+" Iterator",S=y==m,T=!1,k=t.prototype,j=k[c]||k[p]||y&&k[y],B=j||E(y),P=y?S?E("entries"):B:void 0,O="Array"==r?k.entries||j:j;if(O&&(_=f(O.call(new t)),_!==Object.prototype&&_.next&&(h(_,A,!0),n||"function"==typeof _[c]||u(_,c,v))),S&&j&&j.name!==m&&(T=!0,B=function(){return j.call(this)}),n&&!M||!l&&!T&&k[c]||u(k,c,B),s[r]=B,s[A]=v,y)if(b={values:S?B:E(m),keys:w?B:E(d),entries:P},M)for(x in b)x in k||o(k,x,b[x]);else i(i.P+i.F*(l||T),r,b);return b}},function(t,r){t.exports=!0},function(t,r){t.exports=function(t){try{return{e:!1,v:t()}}catch(r){return{e:!0,v:r}}}},function(t,r,e){var n=e(3),i=e(8),o=e(19);t.exports=function(t,r){if(n(t),i(r)&&r.constructor===t)return r;var e=o.f(t),u=e.resolve;return u(r),e.promise}},function(t,r){t.exports=function(t,r){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:r}}},function(t,r,e){var n=e(0),i="__core-js_shared__",o=n[i]||(n[i]={});t.exports=function(t){return o[t]||(o[t]={})}},function(t,r,e){var n=e(3),i=e(10),o=e(1)("species");t.exports=function(t,r){var e,u=n(t).constructor;return void 0===u||void 0==(e=n(u)[o])?r:i(e)}},function(t,r,e){var n,i,o,u=e(12),s=e(67),a=e(35),h=e(18),f=e(0),c=f.process,l=f.setImmediate,p=f.clearImmediate,d=f.MessageChannel,m=f.Dispatch,v=0,g={},y="onreadystatechange",w=function(){var t=+this;if(g.hasOwnProperty(t)){var r=g[t];delete g[t],r()}},M=function(t){w.call(t.data)};l&&p||(l=function(t){for(var r=[],e=1;arguments.length>e;)r.push(arguments[e++]);return g[++v]=function(){s("function"==typeof t?t:Function(t),r)},n(v),v},p=function(t){delete g[t]},"process"==e(11)(c)?n=function(t){c.nextTick(u(w,t,1))}:m&&m.now?n=function(t){m.now(u(w,t,1))}:d?(i=new d,o=i.port2,i.port1.onmessage=M,n=u(o.postMessage,o,1)):f.addEventListener&&"function"==typeof postMessage&&!f.importScripts?(n=function(t){f.postMessage(t+"","*")},f.addEventListener("message",M,!1)):n=y in h("script")?function(t){a.appendChild(h("script"))[y]=function(){a.removeChild(this),w.call(t)}}:function(t){setTimeout(u(w,t,1),0)}),t.exports={set:l,clear:p}},function(t,r,e){var n=e(23),i=Math.min;t.exports=function(t){return t>0?i(n(t),9007199254740991):0}},function(t,r){var e=0,n=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++e+n).toString(36))}},function(t,r){t.exports=function(t){if("string"!=typeof t)throw Error("[is-hex-prefixed] value must be type 'string', is currently type "+typeof t+", while checking isHexPrefixed.");return"0x"===t.slice(0,2)}},function(t,r,e){var n=e(47);t.exports=function(t){return"string"!=typeof t?t:n(t)?t.slice(2):t}},function(t,r){var e;e=function(){return this}();try{e=e||Function("return this")()||(0,eval)("this")}catch(n){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(){function t(t){return function(){var r=[].slice.call(arguments),e=v(t.inputs,"type",!1),n="0x"+g(t.name+"("+e.join(",")+")"),o=[n],u=(0,p["default"])({},r[0])||{},s=(0,p["default"])({},r[0]||{},{to:i.address,topics:o}),a=(0,p["default"])({},u,{decoder:function(r){return d.decodeEvent(t,r,o)},defaultFilterObject:s});return new i.filters.Filter(a)}}function r(t){return function(){var r=void 0,n=[].slice.call(arguments);"function"==typeof n[n.length-1]&&(r=n.pop());var i=e({methodObject:t,methodArgs:n});return r?w(i)(r):i}}var e=function(){ 11 | var t=(0,c["default"])(s["default"].mark(function r(t){var e,n,o,u,a,f,c=t.methodObject,l=t.methodArgs;return s["default"].wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e="call",n={},y(l)&&(n=l.pop()),o=(0,p["default"])({},i.defaultTxObject,n,{to:i.address}),o.data=d.encodeMethod(c,l),c.constant===!1&&(e="sendTransaction"),t.next=8,i.query[e](o);case 8:if(u=t.sent,"call"!==e){t.next=19;break}return t.prev=10,a=d.decodeMethod(c,u),t.abrupt("return",a);case 15:throw t.prev=15,t.t0=t["catch"](10),f=Error("[ethjs-contract] while formatting incoming raw call data "+(0,h["default"])(u)+" "+t.t0);case 19:return t.abrupt("return",u);case 20:case"end":return t.stop()}},r,this,[[10,15]])}));return function(r){return t.apply(this,arguments)}}(),n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=this;i.abi=n.contractABI||[],i.query=n.query,i.address=n.address||"0x",i.bytecode=n.contractBytecode||"0x",i.defaultTxObject=n.contractDefaultTxObject||{},i.filters=new m(i.query),o(i.abi).forEach(function(e){"function"===e.type?i[e.name]=r(e):"event"===e.type&&(i[e.name]=t(e))})}function o(t){return t.filter(function(t){return("function"===t.type||"event"===t.type)&&t.name.length>0})}var u=e(56),s=n(u),a=e(52),h=n(a),f=e(55),c=n(f),l=e(28),p=n(l),d=e(29),m=e(30),v=e(31).getKeys,g=e(16).keccak_256,y=e(27),w=e(104);t.exports=i},function(t,r,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t){return function(r,e,n){if(!Array.isArray(r))throw Error("[ethjs-contract] Contract ABI must be type Array, got type "+typeof r);if(void 0!==e&&"string"!=typeof e)throw Error("[ethjs-contract] Contract bytecode must be type String, got type "+typeof e);if(void 0!==n&&"object"!=typeof n)throw Error("[ethjs-contract] Contract default tx object must be type Object, got type "+typeof r);var i={};return i.at=function(i){return new f({address:i,query:t,contractBytecode:e,contractDefaultTxObject:n,contractABI:r})},i["new"]=function(){var i={},u=null,f=[].slice.call(arguments);"function"==typeof f[f.length-1]&&(u=f.pop()),c(f)&&(i=f.pop());var l=o(r),p=(0,s["default"])({},n,i);if(e&&(p.data=e),l){var d=a.encodeParams(h(l.inputs,"type"),f).substring(2);p.data=""+p.data+d}return u?t.sendTransaction(p,u):t.sendTransaction(p)},i}}function o(t){return t.filter(function(t){return"constructor"===t.type})[0]}var u=e(28),s=n(u),a=e(29),h=(e(16).keccak_256,e(30),e(31).getKeys),f=e(50),c=e(27);t.exports=i},function(t,r,e){t.exports={"default":e(58),__esModule:!0}},function(t,r,e){t.exports={"default":e(60),__esModule:!0}},function(t,r,e){t.exports={"default":e(61),__esModule:!0}},function(t,r,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}r.__esModule=!0;var i=e(54),o=n(i);r["default"]=function(t){return function(){var r=t.apply(this,arguments);return new o["default"](function(t,e){function n(i,u){try{var s=r[i](u),a=s.value}catch(h){return void e(h)}return s.done?void t(a):o["default"].resolve(a).then(function(t){n("next",t)},function(t){n("throw",t)})}return n("next")})}}},function(t,r,e){t.exports=e(105)},function(t,r){"use strict";function e(t){var r=t.length;if(r%4>0)throw Error("Invalid string. Length must be a multiple of 4");return"="===t[r-2]?2:"="===t[r-1]?1:0}function n(t){return 3*t.length/4-e(t)}function i(t){var r,n,i,o,u,s=t.length;o=e(t),u=new f(3*s/4-o),n=o>0?s-4:s;var a=0;for(r=0;n>r;r+=4)i=h[t.charCodeAt(r)]<<18|h[t.charCodeAt(r+1)]<<12|h[t.charCodeAt(r+2)]<<6|h[t.charCodeAt(r+3)],u[a++]=i>>16&255,u[a++]=i>>8&255,u[a++]=255&i;return 2===o?(i=h[t.charCodeAt(r)]<<2|h[t.charCodeAt(r+1)]>>4,u[a++]=255&i):1===o&&(i=h[t.charCodeAt(r)]<<10|h[t.charCodeAt(r+1)]<<4|h[t.charCodeAt(r+2)]>>2,u[a++]=i>>8&255,u[a++]=255&i),u}function o(t){return a[t>>18&63]+a[t>>12&63]+a[t>>6&63]+a[63&t]}function u(t,r,e){for(var n,i=[],u=r;e>u;u+=3)n=(t[u]<<16&16711680)+(t[u+1]<<8&65280)+(255&t[u+2]),i.push(o(n));return i.join("")}function s(t){for(var r,e=t.length,n=e%3,i="",o=[],s=16383,h=0,f=e-n;f>h;h+=s)o.push(u(t,h,h+s>f?f:h+s));return 1===n?(r=t[e-1],i+=a[r>>2],i+=a[r<<4&63],i+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],i+=a[r>>10],i+=a[r>>4&63],i+=a[r<<2&63],i+="="),o.push(i),o.join("")}r.byteLength=n,r.toByteArray=i,r.fromByteArray=s;for(var a=[],h=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,p=c.length;p>l;++l)a[l]=c[l],h[c.charCodeAt(l)]=l;h["-".charCodeAt(0)]=62,h["_".charCodeAt(0)]=63},function(t,r,e){var n=e(2),i=n.JSON||(n.JSON={stringify:JSON.stringify});t.exports=function(t){return i.stringify.apply(i,arguments)}},function(t,r,e){e(90),t.exports=e(2).Object.assign},function(t,r,e){e(91),t.exports=e(2).Object.keys},function(t,r,e){e(92),e(94),e(97),e(93),e(95),e(96),t.exports=e(2).Promise},function(t,r){t.exports=function(){}},function(t,r){t.exports=function(t,r,e,n){if(!(t instanceof r)||void 0!==n&&n in t)throw TypeError(e+": incorrect invocation!");return t}},function(t,r,e){var n=e(24),i=e(45),o=e(86);t.exports=function(t){return function(r,e,u){var s,a=n(r),h=i(a.length),f=o(u,h);if(t&&e!=e){for(;h>f;)if(s=a[f++],s!=s)return!0}else for(;h>f;f++)if((t||f in a)&&a[f]===e)return t||f||0;return!t&&-1}}},function(t,r,e){var n=e(12),i=e(69),o=e(68),u=e(3),s=e(45),a=e(88),h={},f={},r=t.exports=function(t,r,e,c,l){var p,d,m,v,g=l?function(){return t}:a(t),y=n(e,c,r?2:1),w=0;if("function"!=typeof g)throw TypeError(t+" is not iterable!");if(o(g)){for(p=s(t.length);p>w;w++)if(v=r?y(u(d=t[w])[0],d[1]):y(t[w]),v===h||v===f)return v}else for(m=g.call(t);!(d=m.next()).done;)if(v=i(m,y,d.value,r),v===h||v===f)return v};r.BREAK=h,r.RETURN=f},function(t,r,e){t.exports=!e(7)&&!e(13)(function(){return 7!=Object.defineProperty(e(18)("div"),"a",{get:function(){return 7}}).a})},function(t,r){t.exports=function(t,r,e){var n=void 0===e;switch(r.length){case 0:return n?t():t.call(e);case 1:return n?t(r[0]):t.call(e,r[0]);case 2:return n?t(r[0],r[1]):t.call(e,r[0],r[1]);case 3:return n?t(r[0],r[1],r[2]):t.call(e,r[0],r[1],r[2]);case 4:return n?t(r[0],r[1],r[2],r[3]):t.call(e,r[0],r[1],r[2],r[3])}return t.apply(e,r)}},function(t,r,e){var n=e(9),i=e(1)("iterator"),o=Array.prototype;t.exports=function(t){return void 0!==t&&(n.Array===t||o[i]===t)}},function(t,r,e){var n=e(3);t.exports=function(t,r,e,i){try{return i?r(n(e)[0],e[1]):r(e)}catch(o){var u=t["return"];throw void 0!==u&&n(u.call(t)),o}}},function(t,r,e){"use strict";var n=e(75),i=e(41),o=e(21),u={};e(5)(u,e(1)("iterator"),function(){return this}),t.exports=function(t,r,e){t.prototype=n(u,{next:i(1,e)}),o(t,r+" Iterator")}},function(t,r,e){var n=e(1)("iterator"),i=!1;try{var o=[7][n]();o["return"]=function(){i=!0},Array.from(o,function(){throw 2})}catch(u){}t.exports=function(t,r){if(!r&&!i)return!1;var e=!1;try{var o=[7],u=o[n]();u.next=function(){return{done:e=!0}},o[n]=function(){return u},t(o)}catch(s){}return e}},function(t,r){t.exports=function(t,r){return{value:r,done:!!t}}},function(t,r,e){var n=e(0),i=e(44).set,o=n.MutationObserver||n.WebKitMutationObserver,u=n.process,s=n.Promise,a="process"==e(11)(u);t.exports=function(){var t,r,e,h=function(){var n,i;for(a&&(n=u.domain)&&n.exit();t;){i=t.fn,t=t.next;try{i()}catch(o){throw t?e():r=void 0,o}}r=void 0,n&&n.enter()};if(a)e=function(){u.nextTick(h)};else if(!o||n.navigator&&n.navigator.standalone)if(s&&s.resolve){var f=s.resolve();e=function(){f.then(h)}}else e=function(){i.call(n,h)};else{var c=!0,l=document.createTextNode("");new o(h).observe(l,{characterData:!0}),e=function(){l.data=c=!c}}return function(n){var i={fn:n,next:void 0};r&&(r.next=i),t||(t=i,e()),r=i}}},function(t,r,e){"use strict";var n=e(20),i=e(77),o=e(80),u=e(25),s=e(36),a=Object.assign;t.exports=!a||e(13)(function(){var t={},r={},e=Symbol(),n="abcdefghijklmnopqrst";return t[e]=7,n.split("").forEach(function(t){r[t]=t}),7!=a({},t)[e]||Object.keys(a({},r)).join("")!=n})?function(t,r){for(var e=u(t),a=arguments.length,h=1,f=i.f,c=o.f;a>h;)for(var l,p=s(arguments[h++]),d=f?n(p).concat(f(p)):n(p),m=d.length,v=0;m>v;)c.call(p,l=d[v++])&&(e[l]=p[l]);return e}:a},function(t,r,e){var n=e(3),i=e(76),o=e(34),u=e(22)("IE_PROTO"),s=function(){},a="prototype",h=function(){var t,r=e(18)("iframe"),n=o.length,i="<",u=">";for(r.style.display="none",e(35).appendChild(r),r.src="javascript:",t=r.contentWindow.document,t.open(),t.write(i+"script"+u+"document.F=Object"+i+"/script"+u),t.close(),h=t.F;n--;)delete h[a][o[n]];return h()};t.exports=Object.create||function(t,r){var e;return null!==t?(s[a]=n(t),e=new s,s[a]=null,e[u]=t):e=h(),void 0===r?e:i(e,r)}},function(t,r,e){var n=e(15),i=e(3),o=e(20);t.exports=e(7)?Object.defineProperties:function(t,r){i(t);for(var e,u=o(r),s=u.length,a=0;s>a;)n.f(t,e=u[a++],r[e]);return t}},function(t,r){r.f=Object.getOwnPropertySymbols},function(t,r,e){var n=e(14),i=e(25),o=e(22)("IE_PROTO"),u=Object.prototype;t.exports=Object.getPrototypeOf||function(t){return t=i(t),n(t,o)?t[o]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?u:null}},function(t,r,e){var n=e(14),i=e(24),o=e(64)(!1),u=e(22)("IE_PROTO");t.exports=function(t,r){var e,s=i(t),a=0,h=[];for(e in s)e!=u&&n(s,e)&&h.push(e);for(;r.length>a;)n(s,e=r[a++])&&(~o(h,e)||h.push(e));return h}},function(t,r){r.f={}.propertyIsEnumerable},function(t,r,e){var n=e(4),i=e(2),o=e(13);t.exports=function(t,r){var e=(i.Object||{})[t]||Object[t],u={};u[t]=r(e),n(n.S+n.F*o(function(){e(1)}),"Object",u)}},function(t,r,e){var n=e(5);t.exports=function(t,r,e){for(var i in r)e&&t[i]?t[i]=r[i]:n(t,i,r[i]);return t}},function(t,r,e){t.exports=e(5)},function(t,r,e){"use strict";var n=e(0),i=e(2),o=e(15),u=e(7),s=e(1)("species");t.exports=function(t){var r="function"==typeof i[t]?i[t]:n[t];u&&r&&!r[s]&&o.f(r,s,{configurable:!0,get:function(){return this}})}},function(t,r,e){var n=e(23),i=e(17);t.exports=function(t){return function(r,e){var o,u,s=i(r)+"",a=n(e),h=s.length;return 0>a||a>=h?t?"":void 0:(o=s.charCodeAt(a),55296>o||o>56319||a+1===h||(u=s.charCodeAt(a+1))<56320||u>57343?t?s.charAt(a):o:t?s.slice(a,a+2):(o-55296<<10)+(u-56320)+65536)}}},function(t,r,e){var n=e(23),i=Math.max,o=Math.min;t.exports=function(t,r){return t=n(t),0>t?i(t+r,0):o(t,r)}},function(t,r,e){var n=e(8);t.exports=function(t,r){if(!n(t))return t;var e,i;if(r&&"function"==typeof(e=t.toString)&&!n(i=e.call(t)))return i;if("function"==typeof(e=t.valueOf)&&!n(i=e.call(t)))return i;if(!r&&"function"==typeof(e=t.toString)&&!n(i=e.call(t)))return i;throw TypeError("Can't convert object to primitive value")}},function(t,r,e){var n=e(33),i=e(1)("iterator"),o=e(9);t.exports=e(2).getIteratorMethod=function(t){if(void 0!=t)return t[i]||t["@@iterator"]||o[n(t)]}},function(t,r,e){"use strict";var n=e(62),i=e(72),o=e(9),u=e(24);t.exports=e(37)(Array,"Array",function(t,r){this._t=u(t),this._i=0,this._k=r},function(){var t=this._t,r=this._k,e=this._i++;return t&&t.length>e?"keys"==r?i(0,e):"values"==r?i(0,t[e]):i(0,[e,t[e]]):(this._t=void 0,i(1))},"values"),o.Arguments=o.Array,n("keys"),n("values"),n("entries")},function(t,r,e){var n=e(4);n(n.S+n.F,"Object",{assign:e(74)})},function(t,r,e){var n=e(25),i=e(20);e(81)("keys",function(){return function(t){return i(n(t))}})},function(t,r){},function(t,r,e){"use strict";var n,i,o,u,s=e(38),a=e(0),h=e(12),f=e(33),c=e(4),l=e(8),p=e(10),d=e(63),m=e(65),v=e(43),g=e(44).set,y=e(73)(),w=e(19),M=e(39),b=e(40),x="Promise",_=a.TypeError,E=a.process,A=a[x],S="process"==f(E),T=function(){},k=i=w.f,j=!!function(){try{var t=A.resolve(1),r=(t.constructor={})[e(1)("species")]=function(t){t(T,T)};return(S||"function"==typeof PromiseRejectionEvent)&&t.then(T)instanceof r}catch(n){}}(),B=function(t){var r;return!(!l(t)||"function"!=typeof(r=t.then))&&r},P=function(t,r){if(!t._n){t._n=!0;var e=t._c;y(function(){for(var n=t._v,i=1==t._s,o=0,u=function(r){var e,o,u,s=i?r.ok:r.fail,a=r.resolve,h=r.reject,f=r.domain;try{s?(i||(2==t._h&&L(t),t._h=1),s===!0?e=n:(f&&f.enter(),e=s(n),f&&(f.exit(),u=!0)),e===r.promise?h(_("Promise-chain cycle")):(o=B(e))?o.call(e,a,h):a(e)):h(n)}catch(c){f&&!u&&f.exit(),h(c)}};e.length>o;)u(e[o++]);t._c=[],t._n=!1,r&&!t._h&&O(t)})}},O=function(t){g.call(a,function(){var r,e,n,i=t._v,o=R(t);if(o&&(r=M(function(){S?E.emit("unhandledRejection",i,t):(e=a.onunhandledrejection)?e({promise:t,reason:i}):(n=a.console)&&n.error&&n.error("Unhandled promise rejection",i)}),t._h=S||R(t)?2:1),t._a=void 0,o&&r.e)throw r.v})},R=function(t){return 1!==t._h&&0===(t._a||t._c).length},L=function(t){g.call(a,function(){var r;S?E.emit("rejectionHandled",t):(r=a.onrejectionhandled)&&r({promise:t,reason:t._v})})},I=function(t){var r=this;r._d||(r._d=!0,r=r._w||r,r._v=t,r._s=2,r._a||(r._a=r._c.slice()),P(r,!0))},C=function(t){var r,e=this;if(!e._d){e._d=!0,e=e._w||e;try{if(e===t)throw _("Promise can't be resolved itself");(r=B(t))?y(function(){var n={_w:e,_d:!1};try{r.call(t,h(C,n,1),h(I,n,1))}catch(i){I.call(n,i)}}):(e._v=t,e._s=1,P(e,!1))}catch(n){I.call({_w:e,_d:!1},n)}}};j||(A=function(t){d(this,A,x,"_h"),p(t),n.call(this);try{t(h(C,this,1),h(I,this,1))}catch(r){I.call(this,r)}},n=function(t){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1},n.prototype=e(82)(A.prototype,{then:function(t,r){var e=k(v(this,A));return e.ok="function"!=typeof t||t,e.fail="function"==typeof r&&r,e.domain=S?E.domain:void 0,this._c.push(e),this._a&&this._a.push(e),this._s&&P(this,!1),e.promise},"catch":function(t){return this.then(void 0,t)}}),o=function(){var t=new n;this.promise=t,this.resolve=h(C,t,1),this.reject=h(I,t,1)},w.f=k=function(t){return t===A||t===u?new o(t):i(t)}),c(c.G+c.W+c.F*!j,{Promise:A}),e(21)(A,x),e(84)(x),u=e(2)[x],c(c.S+c.F*!j,x,{reject:function(t){var r=k(this),e=r.reject;return e(t),r.promise}}),c(c.S+c.F*(s||!j),x,{resolve:function(t){return b(s&&this===u?A:this,t)}}),c(c.S+c.F*!(j&&e(71)(function(t){A.all(t)["catch"](T)})),x,{all:function(t){var r=this,e=k(r),n=e.resolve,i=e.reject,o=M(function(){var e=[],o=0,u=1;m(t,!1,function(t){var s=o++,a=!1;e.push(void 0),u++,r.resolve(t).then(function(t){a||(a=!0,e[s]=t,--u||n(e))},i)}),--u||n(e)});return o.e&&i(o.v),e.promise},race:function(t){var r=this,e=k(r),n=e.reject,i=M(function(){m(t,!1,function(t){r.resolve(t).then(e.resolve,n)})});return i.e&&n(i.v),e.promise}})},function(t,r,e){"use strict";var n=e(85)(!0);e(37)(String,"String",function(t){this._t=t+"",this._i=0},function(){var t,r=this._t,e=this._i;return r.length>e?(t=n(r,e),this._i+=t.length,{value:t,done:!1}):{value:void 0,done:!0}})},function(t,r,e){"use strict";var n=e(4),i=e(2),o=e(0),u=e(43),s=e(40);n(n.P+n.R,"Promise",{"finally":function(t){var r=u(this,i.Promise||o.Promise),e="function"==typeof t;return this.then(e?function(e){return s(r,t()).then(function(){return e})}:t,e?function(e){return s(r,t()).then(function(){throw e})}:t)}})},function(t,r,e){"use strict";var n=e(4),i=e(19),o=e(39);n(n.S,"Promise",{"try":function(t){var r=i.f(this),e=o(t);return(e.e?r.reject:r.resolve)(e.v),r.promise}})},function(t,r,e){e(89);for(var n=e(0),i=e(5),o=e(9),u=e(1)("toStringTag"),s="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),a=0;s.length>a;a++){var h=s[a],f=n[h],c=f&&f.prototype;c&&!c[u]&&i(c,u,h),o[h]=o.Array}},function(t,r,e){"use strict";(function(r){function n(t){for(var r=t,e=r[0];r.length>0&&""+e=="0";)r=r.slice(1),e=r[0];return r}function i(t){var e=t,i=e.toString(16);return i.length%2&&(i="0"+i),n(new r(i,"hex"))}function o(t,r){return!("string"!=typeof t||!t.match(/^0x[0-9A-Fa-f]*$/))&&(!r||t.length===2+2*r)}function u(t,e){var n=t;if(!r.isBuffer(n)){if(!o(n)){var i=Error(e?"[ethjs-abi] invalid "+e:"[ethjs-abi] invalid hex or buffer, must be a prefixed alphanumeric even length hex string");throw i.reason="[ethjs-abi] invalid hex string, hex must be prefixed and alphanumeric (e.g. 0x023..)",i.value=n,i}n=n.substring(2),n.length%2&&(n="0"+n),n=new r(n,"hex")}return n}function s(t){return"number"==typeof t?"0x"+i(new m(t)).toString("hex"):t.mod||t.modulo?"0x"+i(t).toString("hex"):"0x"+u(t).toString("hex")}function a(t,r,e){var n=[];if(!Array.isArray(t))throw Error("[ethjs-abi] while getting keys, invalid params value "+JSON.stringify(t));for(var i=0;t.length>i;i++){var o=t[i][r];if(e&&!o)o="";else if("string"!=typeof o)throw Error("[ethjs-abi] while getKeys found invalid ABI data structure, type value not string");n.push(o)}return n}function h(t,e){return{encode:function(n){var i=n;return"object"==typeof i&&i.toString&&(i.toTwos||i.dividedToIntegerBy)&&(i=i.toString(10).split(".")[0]),"string"!=typeof i&&"number"!=typeof i||(i=(i+"").split(".")[0]),i=v(i),i=i.toTwos(8*t).maskn(8*t),e&&(i=i.fromTwos(8*t).toTwos(256)),i.toArrayLike(r,"be",32)},decode:function(r,n){var i=32-t,o=new m(r.slice(n+i,n+32));return o=e?o.fromTwos(8*t):o.maskn(8*t),{consumed:32,value:new m(o.toString(10))}}}}function f(t){return{encode:function(t){var e=t;if(e=u(e),32===e.length)return e;var n=new r(32);return n.fill(0),e.copy(n),n},decode:function(r,e){if(0!==r.length&&e+32>r.length)throw Error("[ethjs-abi] while decoding fixed bytes, invalid bytes data length: "+t);return{consumed:32,value:"0x"+r.slice(e,e+t).toString("hex")}}}}function c(t){var e=parseInt(32*Math.ceil(t.length/32)),n=new r(e-t.length);return n.fill(0),r.concat([y.encode(t.length),t,n])}function l(t,r){if(0!==t.length&&r+32>t.length)throw Error("[ethjs-abi] while decoding dynamic bytes data, invalid bytes length: "+t.length+" should be less than "+(r+32));var e=y.decode(t,r).value;if(e=e.toNumber(),0!==t.length&&r+32+e>t.length)throw Error("[ethjs-abi] while decoding dynamic bytes data, invalid bytes length: "+t.length+" should be less than "+(r+32+e));return{consumed:parseInt(32+32*Math.ceil(e/32),10),value:t.slice(r+32,r+32+e)}}function p(t,e){return{encode:function(n){var i=new r(0),o=e;if(!Array.isArray(n))throw Error("[ethjs-abi] while encoding array, invalid array data, not type Object (Array)");if(o===-1&&(o=n.length,i=y.encode(o)),o!==n.length)throw Error("[ethjs-abi] while encoding array, size mismatch array length "+o+" does not equal "+n.length);return n.forEach(function(e){i=r.concat([i,t.encode(e)])}),i},decode:function(r,n){var i,o=e,u=n,s=0;o===-1&&(i=y.decode(r,u),o=i.value.toNumber(),s+=i.consumed,u+=i.consumed);for(var a=[],h=0;o>h;h++){var f=t.decode(r,u);s+=f.consumed,u+=f.consumed,a.push(f.value)}return{consumed:s,value:a}},dynamic:e===-1}}function d(t){for(var r=t,e=null,n="[ethjs-abi] while getting param coder (getParamCoder) type value "+JSON.stringify(r)+" is either invalid or unsupported by ethjs-abi.";r;){var i=r.match(_);if(!i)throw Error(n);r=r.substring(i[0].length);var o=i[2]||i[4]||i[5];switch(o){case"int":case"uint":if(e)throw Error(n);var u=parseInt(i[3]||256);if(0===u||u>256||u%8!==0)throw Error("[ethjs-abi] while getting param coder for type "+r+", invalid "+o+" width: "+r);e=h(u/8,"int"===o);break;case"bool":if(e)throw Error(n);e=w;break;case"string":if(e)throw Error(n);e=x;break;case"bytes":if(e)throw Error(n);if(i[3]){var s=parseInt(i[3]);if(0===s||s>32)throw Error("[ethjs-abi] while getting param coder for prefix bytes, invalid type "+r+", size "+s+" should be 0 or greater than 32");e=f(s)}else e=b;break;case"address":if(e)throw Error(n);e=M;break;case"[]":if(!e||e.dynamic)throw Error(n);e=p(e,-1);break;default:if(!e||e.dynamic)throw Error(n);var a=parseInt(i[6]);e=p(e,a)}}if(!e)throw Error(n);return e}var m=e(32),v=e(103),g=e(16).keccak_256,y=h(32,!1),w={encode:function(t){return y.encode(t?1:0)},decode:function(t,r){var e=y.decode(t,r);return{consumed:e.consumed,value:!e.value.isZero()}}},M={encode:function(t){var e=t,n=new r(32);if(!o(e,20))throw Error("[ethjs-abi] while encoding address, invalid address value, not alphanumeric 20 byte hex string");return e=u(e),n.fill(0),e.copy(n,12),n},decode:function(t,r){if(0===t.length)return{consumed:32,value:"0x"};if(0!==t.length&&r+32>t.length)throw Error("[ethjs-abi] while decoding address data, invalid address data, invalid byte length "+t.length);return{consumed:32,value:"0x"+t.slice(r+12,r+32).toString("hex")}}},b={encode:function(t){return c(u(t))},decode:function(t,r){var e=l(t,r);return e.value="0x"+e.value.toString("hex"),e},dynamic:!0},x={encode:function(t){return c(new r(t,"utf8"))},decode:function(t,r){var e=l(t,r);return e.value=e.value.toString("utf8"),e},dynamic:!0},_=RegExp(/^((u?int|bytes)([0-9]*)|(address|bool|string)|(\[([0-9]*)\]))/);t.exports={BN:m,bnToBuffer:i,isHexString:o,hexOrBuffer:u,hexlify:s,stripZeros:n,keccak256:g,getKeys:a,numberToBN:v,coderNumber:h,uint256Coder:y,coderBoolean:w,coderFixedBytes:f,coderAddress:M,coderDynamicBytes:b,coderString:x,coderArray:p,paramTypePart:_,getParamCoder:d}}).call(r,e(6).Buffer)},function(t,r){r.read=function(t,r,e,n,i){var o,u,s=8*i-n-1,a=(1<>1,f=-7,c=e?i-1:0,l=e?-1:1,p=t[r+c];for(c+=l,o=p&(1<<-f)-1,p>>=-f,f+=s;f>0;o=256*o+t[r+c],c+=l,f-=8);for(u=o&(1<<-f)-1,o>>=-f,f+=n;f>0;u=256*u+t[r+c],c+=l,f-=8);if(0===o)o=1-h;else{if(o===a)return u?NaN:(p?-1:1)*(1/0);u+=Math.pow(2,n),o-=h}return(p?-1:1)*u*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var u,s,a,h=8*o-i-1,f=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,m=0>r||0===r&&0>1/r?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(s=isNaN(r)?1:0,u=f):(u=Math.floor(Math.log(r)/Math.LN2),r*(a=Math.pow(2,-u))<1&&(u--,a*=2),r+=1>u+c?l*Math.pow(2,1-c):l/a,2>r*a||(u++,a/=2),f>u+c?1>u+c?(s=r*Math.pow(2,c-1)*Math.pow(2,i),u=0):(s=(r*a-1)*Math.pow(2,i),u+=c):(s=0,u=f));i>=8;t[e+p]=255&s,p+=d,s/=256,i-=8);for(u=u<0;t[e+p]=255&u,p+=d,u/=256,h-=8);t[e+p-d]|=128*m}},function(t,r){"use strict";var e=Object.prototype.toString;t.exports=function(t){return"[object Function]"===e.call(t)}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r){function e(){throw Error("setTimeout has not been defined")}function n(){throw Error("clearTimeout has not been defined")}function i(t){if(f===setTimeout)return setTimeout(t,0);if((f===e||!f)&&setTimeout)return f=setTimeout,setTimeout(t,0);try{return f(t,0)}catch(r){try{return f.call(null,t,0)}catch(r){return f.call(this,t,0)}}}function o(t){if(c===clearTimeout)return clearTimeout(t);if((c===n||!c)&&clearTimeout)return c=clearTimeout,clearTimeout(t);try{return c(t)}catch(r){try{return c.call(null,t)}catch(r){return c.call(this,t)}}}function u(){m&&p&&(m=!1,p.length?d=p.concat(d):v=-1,d.length&&s())}function s(){if(!m){var t=i(u);m=!0;for(var r=d.length;r;){for(p=d,d=[];++v1)for(var e=1;arguments.length>e;e++)r[e-1]=arguments[e];d.push(new a(t,r)),1!==d.length||m||i(s)},a.prototype.run=function(){this.fun.apply(null,this.array)},l.title="browser",l.browser=!0,l.env={},l.argv=[],l.version="",l.versions={},l.on=h,l.addListener=h,l.once=h,l.off=h,l.removeListener=h,l.removeAllListeners=h,l.emit=h,l.prependListener=h,l.prependOnceListener=h,l.listeners=function(t){return[]},l.binding=function(t){throw Error("process.binding is not supported")},l.cwd=function(){return"/"},l.chdir=function(t){throw Error("process.chdir is not supported")},l.umask=function(){return 0}},function(t,r,e){var n=e(32),i=e(48);t.exports=function(t){if("string"==typeof t||"number"==typeof t){var r=new n(1),e=(t+"").toLowerCase().trim(),o="0x"===e.substr(0,2)||"-0x"===e.substr(0,3),u=i(e);if("-"===u.substr(0,1)&&(u=i(u.slice(1)),r=new n((-1),10)),u=""===u?"0":u,!u.match(/^-?[0-9]+$/)&&u.match(/^[0-9A-Fa-f]+$/)||u.match(/^[a-fA-F]+$/)||o===!0&&u.match(/^[0-9A-Fa-f]+$/))return new n(u,16).mul(r);if((u.match(/^-?[0-9]+$/)||""===u)&&o===!1)return new n(u,10).mul(r)}else if("object"==typeof t&&t.toString&&!t.pop&&!t.push&&t.toString(10).match(/^-?[0-9]+$/)&&(t.mul||t.dividedToIntegerBy))return new n(t.toString(10),10);throw Error("[number-to-bn] while converting number "+JSON.stringify(t)+" to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.")}},function(t,r,e){"use strict";var n=e(100),i=e(107);t.exports=function(t){if(!n(t.then))throw new TypeError("Expected a promise");return function(r){t.then(function(t){i(r,null,t)},function(t){i(r,t)})}}},function(t,r,e){var n=function(){return this}()||Function("return this")(),i=n.regeneratorRuntime&&Object.getOwnPropertyNames(n).indexOf("regeneratorRuntime")>=0,o=i&&n.regeneratorRuntime;if(n.regeneratorRuntime=void 0,t.exports=e(106),i)n.regeneratorRuntime=o;else try{delete n.regeneratorRuntime}catch(u){n.regeneratorRuntime=void 0}},function(t,r){!function(r){"use strict";function e(t,r,e,n){var o=r&&r.prototype instanceof i?r:i,u=Object.create(o.prototype),s=new p(n||[]);return u._invoke=h(t,e,s),u}function n(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(n){return{type:"throw",arg:n}}}function i(){}function o(){}function u(){}function s(t){["next","throw","return"].forEach(function(r){t[r]=function(t){return this._invoke(r,t)}})}function a(t){function r(e,i,o,u){var s=n(t[e],t,i);if("throw"!==s.type){var a=s.arg,h=a.value;return h&&"object"==typeof h&&y.call(h,"__await")?Promise.resolve(h.__await).then(function(t){r("next",t,o,u)},function(t){r("throw",t,o,u)}):Promise.resolve(h).then(function(t){a.value=t,o(a)},u)}u(s.arg)}function e(t,e){function n(){return new Promise(function(n,i){r(t,e,n,i)})}return i=i?i.then(n,n):n()}var i;this._invoke=e}function h(t,r,e){var i=A;return function(o,u){if(i===T)throw Error("Generator is already running");if(i===k){if("throw"===o)throw u;return m()}for(e.method=o,e.arg=u;;){var s=e.delegate;if(s){var a=f(s,e);if(a){if(a===j)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(i===A)throw i=k,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);i=T;var h=n(t,r,e);if("normal"===h.type){if(i=e.done?k:S,h.arg===j)continue;return{value:h.arg,done:e.done}}"throw"===h.type&&(i=k,e.method="throw",e.arg=h.arg)}}}function f(t,r){var e=t.iterator[r.method];if(e===v){if(r.delegate=null,"throw"===r.method){if(t.iterator["return"]&&(r.method="return",r.arg=v,f(t,r),"throw"===r.method))return j;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return j}var i=n(e,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,j;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=v),r.delegate=null,j):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,j)}function c(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function l(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function p(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(c,this),this.reset(!0)}function d(t){if(t){var r=t[M];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,n=function i(){for(;++e=0;--n){var i=this.tryEntries[n],o=i.completion;if("root"===i.tryLoc)return r("end");if(this.prev>=i.tryLoc){var u=y.call(i,"catchLoc"),s=y.call(i,"finallyLoc");if(u&&s){if(i.catchLoc>this.prev)return r(i.catchLoc,!0);if(i.finallyLoc>this.prev)return r(i.finallyLoc)}else if(u){if(i.catchLoc>this.prev)return r(i.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return r(i.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(this.prev>=n.tryLoc&&y.call(n,"finallyLoc")&&n.finallyLoc>this.prev){var i=n;break}}!i||"break"!==t&&"continue"!==t||i.tryLoc>r||r>i.finallyLoc||(i=null);var o=i?i.completion:{};return o.type=t,o.arg=r,i?(this.method="next",this.next=i.finallyLoc,j):this.complete(o)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),j},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),l(e),j}},"catch":function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var i=n.arg;l(e)}return i}}throw Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:d(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=v),j}}}(function(){return this}()||Function("return this")())},function(t,r,e){"use strict";(function(r){t.exports="function"==typeof r?r:function(){var t=[].slice.apply(arguments);t.splice(1,0,0),setTimeout.apply(null,t)}}).call(r,e(26).setImmediate)},102,function(t,r){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,configurable:!1,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,configurable:!1,get:function(){return t.i}}),t.webpackPolyfill=1), 12 | t}}]))}); -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | 3 | ## Table of Contents 4 | 5 | - [General](general) 6 | - [**Developer Guide**](developer-guide.md) 7 | - [**User Guide**](user-guide.md) 8 | 9 | ## Overview 10 | 11 | ### Structure 12 | 13 | The [`src/`](../../../tree/master/src) directory contains your entire application code, including JavaScript, and tests. 14 | 15 | The rest of the folders and files only exist to make your life easier, and 16 | should not need to be touched. 17 | 18 | For more in-depth structure, see the developer-guide.md. 19 | 20 | *(If they do have to be changed, please [submit an issue](https://github.com/ethjs/ethjs-contract/issues)!)* 21 | 22 | ### Testing 23 | 24 | For a thorough explanation of the testing procedure, see the 25 | [testing documentation](./developer-guide/README.md)! 26 | 27 | #### Unit testing 28 | 29 | Unit tests live in `src/tests/` directories right next to the components being tested 30 | and are run with `npm test`. 31 | -------------------------------------------------------------------------------- /docs/developer-guide.md: -------------------------------------------------------------------------------- 1 | # Developer Guide 2 | 3 | All information regarding contributing to and progressing `ethjs-contract` module can be found in this document. 4 | 5 | ## Install 6 | 7 | ``` 8 | npm install --save ethjs-contract 9 | ``` 10 | 11 | ## Install from Source 12 | 13 | ``` 14 | git clone http://github.com/ethjs/ethjs-contract 15 | npm install 16 | ``` 17 | 18 | ## Test 19 | 20 | ``` 21 | npm test 22 | ``` 23 | 24 | ## Build 25 | 26 | ``` 27 | npm run build 28 | ``` 29 | 30 | ## Linting 31 | 32 | ``` 33 | npm run lint 34 | ``` 35 | 36 | ## Travis-ci and Coveralls Testing 37 | 38 | Note, this will generate a `coveralls` report locally. 39 | 40 | ``` 41 | npm run test-travis 42 | ``` 43 | 44 | You can find the coveralls report and view the percentages and stats, by going to the [index.html](coverage/lcov-report/index.html) file generated after running the `test-travis` script. Open this in Chrome to see the generated report. Travis will run mocha as usual, but collect information about the testing coverage. This report will be sent by TravisCI during the automated build process. 45 | 46 | ## Build Staging 47 | 48 | The build staging for this module is as follows: 49 | 50 | 1. Cleanup 51 | 2. Linting 52 | 3. Testing 53 | 4. Babel processing (output to lib) 54 | 5. Webpack (output to dist) 55 | 6. Webpack production (output to dist) 56 | 7. Retest lib folder for babel processing solidity 57 | 8. Report build stats 58 | 59 | ## Folder Structure 60 | 61 | All module source code is found in the `src` directory. All module helper scripts can be found in the `scripts` folder. These will not need to be touched, and are purely configuration for this repository. 62 | 63 | ``` 64 | ./ethjs-contract 65 | ./.github 66 | ./dist 67 | ./lib 68 | ./tests 69 | ./internals 70 | ./webpack 71 | ./coverage 72 | ./docs 73 | ./src 74 | ./tests 75 | ``` 76 | 77 | Note, the `./lib` dir is generated from the babel build staging. `./coverage` is generated from the `npm run test-travis` script. All internals and helper scripts (i.e. `webpack`) are in `./internals`. All distribution builds are in `./dist` (usually a minified and unminified production build of the package). 78 | 79 | ## NPM Practice 80 | 81 | Across all `ethjs-` repos, we enforce version hardening (i.e. "0.0.3" not "^0.0.3"). We want to reduce potential hazardous install changes from dependancies as much as possible to ensure package preformace, testing, security and design. Please make sure all your commits and PR's are version hardend if you are installing or removing new packages. 82 | 83 | After build staging it is the `lib` folder which actually gets published to NPM. This allows for easy inclusion into other modules which may not use babel transpiling or which may not support es2015+. 84 | 85 | ## NPM/Node Version Requirements 86 | 87 | `ethjs` requires you have: 88 | - `nodejs` -v 6.5.0+ 89 | - `npm` -v 3.0+ 90 | 91 | This is a requirement to run, test, lint and build this module. 92 | 93 | ## Webpack 94 | 95 | `ethjs` uses webpack across all its browser focused repos. Webpack is used to package down project files into distribution builds for the browser. You can see the builds it produces by going to the [dist](dist) folder. 96 | 97 | Read more about webpack here: 98 | https://github.com/webpack/docs 99 | 100 | ## Changelog 101 | 102 | All relevant changes are notated in the `CHANGELOG.md` file, moniter this file for changes to this repository. 103 | 104 | ## Travis-ci and Coveralls Practice 105 | 106 | Across all `ethjs-` repos, we enforce mandatory travis-ci and coveralls testing. We never `commit to master`. As a general policy, Coveralls.io results must always be above 95% for any `ethjs-` PR or commit. We want to ensure complete coverage across the board. 107 | 108 | ## Contributing 109 | 110 | Please help better the ecosystem by submitting issues and pull requests. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard. Please read more about contributing to `ethjs-contract` in the `.github/CONTRIBUTING.md`. 111 | 112 | ## Licence 113 | 114 | This project is licensed under the MIT license, Copyright (c) 2016 Nick Dodson. For more information see LICENSE. 115 | -------------------------------------------------------------------------------- /docs/user-guide.md: -------------------------------------------------------------------------------- 1 | # User Guide 2 | 3 | All information for developers using `ethjs-contract` should consult this document. 4 | 5 | ## Install 6 | 7 | ``` 8 | npm install --save ethjs-contract 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | const HttpProvider = require('ethjs-provider-http'); 15 | const Eth = require('ethjs-query'); 16 | const EthContract = require('ethjs-contract'); 17 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 18 | const contract = new EthContract(eth); 19 | 20 | const SimpleStore = contract(abi, bytecode, defaultTxObject); 21 | const simpleStore = SimpleStore.at('0x000...'); 22 | const simpleStore = SimpleStore.new((error, result) => { 23 | // result null '0x928sdfk...' 24 | }); 25 | 26 | simpleStore.set(45000, (error, result) => { 27 | // result null '0x2dfj24...' 28 | }); 29 | 30 | simpleStore.get().catch((error) => { 31 | // error null 32 | }).then(result) => { 33 | // result 34 | }); 35 | 36 | const filter = simpleStore.SetComplete((error, result) => { 37 | // result null filterId 38 | }); 39 | filter.watch().then((result) => { 40 | // result null FilterResult {...} 41 | }); 42 | filter.stopWatching((error, result) => { 43 | // result null Boolean filterUninstalled 44 | }); 45 | ``` 46 | 47 | ## API Design 48 | 49 | ### constructor 50 | 51 | [index.js:ethjs-contract](../../../blob/master/src/index.js "Source code on GitHub") 52 | 53 | Intakes an `ethjs-query` instance, outputs a single `contract` instance. 54 | 55 | **Parameters** 56 | 57 | - `eth` **Object** a single `ethjs-query` `Eth` instance for RPC formatting, and querying. 58 | 59 | Result `contract` **Object**. 60 | 61 | ```js 62 | const HttpProvider = require('ethjs-provider-http'); 63 | const Eth = require('ethjs-query'); 64 | const EthContract = require('ethjs-contract'); 65 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 66 | const contract = new EthContract(eth); 67 | ``` 68 | 69 | ### contract 70 | 71 | [index.js:ethjs-contract](../../../blob/master/src/index.js "Source code on GitHub") 72 | 73 | Intakes the contract Ethereum standard ABI schema, optionally the contract bytecode and default transaction object. Outputs a `ContractFactory` instance for the contract. 74 | 75 | **Parameters** 76 | 77 | - `abi` **Array** a single Ethereum standard contract ABI array 78 | - `bytecode` **String** [optional] the contract bytecode as a single alphanumeric hex string 79 | - `defaultTxObject` **Object** [optional] a single default transaction object 80 | 81 | Result `ContractFactory` **Object**. 82 | 83 | ```js 84 | const HttpProvider = require('ethjs-provider-http'); 85 | const Eth = require('ethjs-query'); 86 | const EthContract = require('ethjs-contract'); 87 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 88 | const contract = new EthContract(eth); 89 | 90 | // the abi 91 | const SimpleStoreABI = JSON 92 | .parse('[{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]'); 93 | 94 | // bytecode 95 | const SimpleStoreBytecode = '606060405234610000575b5b5b61010e8061001a6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b1146100435780636d4ce63c14610076575b610000565b346100005761005e6004808035906020019091905050610099565b60405180821515815260200191505060405180910390f35b3461000057610083610103565b6040518082815260200191505060405180910390f35b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b9056'; 96 | 97 | eth.accounts().then((accounts) => { 98 | const SimpleStore = contract(SimpleStoreABI, SimpleStoreBytecode, { 99 | from: accounts[0], 100 | gas: 300000, 101 | }); 102 | 103 | // create a new contract 104 | const simpleStore = SimpleStore.new((error, result) => { 105 | // result null '0x928sdfk...' (i.e. the transaction hash) 106 | }); 107 | 108 | // setup an instance of that contract 109 | const simpleStore = SimpleStore.at('0x000...'); 110 | }); 111 | ``` 112 | 113 | ### ContractFactory.new 114 | 115 | [index.js:ethjs-contract](../../../blob/master/src/index.js "Source code on GitHub") 116 | 117 | The contract factory has two methods, 'at' and 'new' which can be used to create the contract instane. the `at` method is used to create a `Contract` instance for a contract that has already been deployed to the Ethereum blockchain (testnet, livenet, local or otherwise). The `new` method is used to deploy the contract to the current chain. 118 | 119 | **Parameters** 120 | 121 | - [`params`] **Various** the contract constructor input paramaters, if any have been specified, these can be of various types, lengths and requirements depending on the contract constructor. 122 | - `txObject` **Object** [optional] a web3 standard transaciton JSON object 123 | - `callback` **Function** [optional] a standard async callback which is fired when the contract has either been created or the transaction has failed. 124 | 125 | Result a single Promise **Object** instance. 126 | 127 | 128 | ```js 129 | const HttpProvider = require('ethjs-provider-http'); 130 | const Eth = require('ethjs-query'); 131 | const EthContract = require('ethjs-contract'); 132 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 133 | const contract = new EthContract(eth); 134 | 135 | // the abi 136 | const SimpleStoreABI = JSON 137 | .parse('[{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]'); 138 | 139 | // bytecode 140 | const SimpleStoreBytecode = '606060405234610000575b5b5b61010e8061001a6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b1146100435780636d4ce63c14610076575b610000565b346100005761005e6004808035906020019091905050610099565b60405180821515815260200191505060405180910390f35b3461000057610083610103565b6040518082815260200191505060405180910390f35b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b9056'; 141 | 142 | eth.accounts().then((accounts) => { 143 | const SimpleStore = contract(SimpleStoreABI, SimpleStoreBytecode, { 144 | from: accounts[0], 145 | gas: 300000, 146 | }); 147 | 148 | // create a new contract 149 | SimpleStore.new((error, result) => { 150 | // result null '0x928sdfk...' (i.e. the transaction hash) 151 | }); 152 | }); 153 | ``` 154 | 155 | ### ContractFactory.at 156 | 157 | [index.js:ethjs-contract](../../../blob/master/src/index.js "Source code on GitHub") 158 | 159 | The contract factory has two methods, 'at' and 'new' which can be used to create the `Contract` instane. 160 | 161 | **Parameters** 162 | 163 | - `address` **String** a single 20 byte alphanumeric hex string contract address 164 | 165 | Result a single `Contract` **Object** instance. 166 | 167 | ```js 168 | const HttpProvider = require('ethjs-provider-http'); 169 | const Eth = require('ethjs-query'); 170 | const EthContract = require('ethjs-contract'); 171 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 172 | const contract = new EthContract(eth); 173 | 174 | // the abi 175 | const SimpleStoreABI = JSON 176 | .parse('[{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]'); 177 | 178 | // bytecode 179 | const SimpleStoreBytecode = '606060405234610000575b5b5b61010e8061001a6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b1146100435780636d4ce63c14610076575b610000565b346100005761005e6004808035906020019091905050610099565b60405180821515815260200191505060405180910390f35b3461000057610083610103565b6040518082815260200191505060405180910390f35b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b9056'; 180 | 181 | eth.accounts().then((accounts) => { 182 | const SimpleStore = contract(SimpleStoreABI, SimpleStoreBytecode, { 183 | from: accounts[0], 184 | gas: 300000, 185 | }); 186 | 187 | // setup an instance of that contract 188 | const simpleStore = SimpleStore.at('0x000...'); 189 | 190 | // use a method that comes with the contract 191 | simpleStore.set(45).then((txHash) => { 192 | console.log(txHash); 193 | }); 194 | }); 195 | ``` 196 | 197 | ### Contract 198 | 199 | [index.js:ethjs-contract](../../../blob/master/src/index.js "Source code on GitHub") 200 | 201 | The contract instance is meant to simulate a deployed Ethereum contract interface as a javascript object. All specified call methods are attached to this object (as specified by the contract ABI schema array). 202 | 203 | In the example below, the SimpleStore contract has methods `set`, `get`, `constructor` and `SetComplete`. 204 | 205 | The `get` method is flagged as `constant`, which means it will not make changes to the blockchain. It is purely for getting information from the chain. 206 | 207 | However, the `set` method is not constant, which means it can be transacted with and change the blockchain. 208 | 209 | The `constructor` method is only used when deploying the contract, i.e. when `.new` is used. 210 | 211 | In this contract, the `SetComplete` event is fired when the `set` method has set a new value successfully. 212 | 213 | You will notice the `simpleStore` instance makes all these methods available to it. 214 | 215 | ```js 216 | const HttpProvider = require('ethjs-provider-http'); 217 | const Eth = require('ethjs-query'); 218 | const EthContract = require('ethjs-contract'); 219 | const eth = new Eth(new HttpProvider('http://localhost:8545')); 220 | const contract = new EthContract(eth); 221 | 222 | // the abi 223 | const SimpleStoreABI = JSON 224 | .parse('[{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]'); 225 | 226 | // bytecode 227 | const SimpleStoreBytecode = '606060405234610000575b5b5b61010e8061001a6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b1146100435780636d4ce63c14610076575b610000565b346100005761005e6004808035906020019091905050610099565b60405180821515815260200191505060405180910390f35b3461000057610083610103565b6040518082815260200191505060405180910390f35b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b9056'; 228 | 229 | eth.accounts().then((accounts) => { 230 | const SimpleStore = contract(SimpleStoreABI, SimpleStoreBytecode, { 231 | from: accounts[0], 232 | gas: 300000, 233 | }); 234 | 235 | // setup an instance of that contract 236 | const simpleStore = SimpleStore.at('0x000...'); 237 | 238 | simpleStore.set(45000, (error, result) => { 239 | // result null '0x2dfj24...' 240 | }); 241 | 242 | simpleStore.get().catch((error) => { 243 | // error null 244 | }).then(result) => { 245 | // result 246 | }); 247 | 248 | const filter = simpleStore.SetComplete().new((error, result) => { 249 | // result null filterId 250 | }); 251 | filter.watch().then((result) => { 252 | // result null FilterResult {...} (will only fire once) 253 | }); 254 | filter.uninstall((error, result) => { 255 | // result null Boolean filterUninstalled 256 | }); 257 | }); 258 | ``` 259 | 260 | ## Promises And callbacks 261 | 262 | All `Contract` object prototype methods support both promises and callbacks. `EventFilter` objects also have complete promise support. 263 | 264 | ## Why BN.js? 265 | 266 | `ethjs` has made a policy of using `BN.js` across all of its repositories. Here are some of the reasons why: 267 | 268 | 1. lighter than alternatives (BigNumber.js) 269 | 2. faster than most alternatives, see [benchmarks](https://github.com/indutny/bn.js/issues/89) 270 | 3. used by the Ethereum foundation across all [`ethereumjs`](https://github.com/ethereumjs) repositories 271 | 4. is already used by a critical JS dependency of many ethereum packages, see package [`elliptic`](https://github.com/indutny/elliptic) 272 | 5. purposefully **does not support decimals or floats numbers** (for greater precision), remember, the Ethereum blockchain cannot and will not support float values or decimal numbers. 273 | 274 | ## Browser Builds 275 | 276 | `ethjs` provides production distributions for all of its modules that are ready for use in the browser right away. Simply include either `dist/ethjs-contract.js` or `dist/ethjs-contract.min.js` directly into an HTML file to start using this module. Note, an `EthContract` object is made available globally. 277 | 278 | ```html 279 | 280 | 283 | ``` 284 | 285 | Note, even though `ethjs` should have transformed and polyfilled most of the requirements to run this module across most modern browsers. You may want to look at an additional polyfill for extra support. 286 | 287 | Use a polyfill service such as `Polyfill.io` to ensure complete cross-browser support: 288 | https://polyfill.io/ 289 | 290 | ## Latest Webpack Figures 291 | 292 | ``` 293 | Hash: 7a3fde336c393e27e46b 294 | Version: webpack 2.1.0-beta.15 295 | Time: 891ms 296 | Asset Size Chunks Chunk Names 297 | ethjs-contract.js 204 kB 0 [emitted] main 298 | ethjs-contract.js.map 249 kB 0 [emitted] main 299 | + 17 hidden modules 300 | 301 | Version: webpack 2.1.0-beta.15 302 | Time: 3276ms 303 | Asset Size Chunks Chunk Names 304 | ethjs-contract.min.js 89.4 kB 0 [emitted] main 305 | + 17 hidden modules 306 | ``` 307 | 308 | ## Other Awesome Modules, Tools and Frameworks 309 | 310 | ### Foundation 311 | - [web3.js](https://github.com/ethereum/web3.js) -- the original Ethereum JS swiss army knife **Ethereum Foundation** 312 | - [ethereumjs](https://github.com/ethereumjs) -- critical ethereum javascript infrastructure **Ethereum Foundation** 313 | - [browser-solidity](https://ethereum.github.io/browser-solidity) -- an in browser Solidity IDE **Ethereum Foundation** 314 | 315 | ### Nodes 316 | - [geth](https://github.com/ethereum/go-ethereum) Go-Ethereum 317 | - [parity](https://github.com/ethcore/parity) Rust-Ethereum build in Rust 318 | - [testrpc](https://github.com/ethereumjs/testrpc) Testing Node (ethereumjs-vm) 319 | 320 | ### Testing 321 | - [wafr](https://github.com/silentcicero/wafr) -- a super simple Solidity testing framework 322 | - [truffle](https://github.com/ConsenSys/truffle) -- a solidity/js dApp framework 323 | - [embark](https://github.com/iurimatias/embark-framework) -- a solidity/js dApp framework 324 | - [dapple](https://github.com/nexusdev/dapple) -- a solidity dApp framework 325 | - [chaitherium](https://github.com/SafeMarket/chaithereum) -- a JS web3 unit testing framework 326 | - [contest](https://github.com/DigixGlobal/contest) -- a JS testing framework for contracts 327 | 328 | ### Wallets 329 | - [ethers-wallet](https://github.com/ethers-io/ethers-wallet) -- an amazingly small Ethereum wallet 330 | - [metamask](https://metamask.io/) -- turns your browser into an Ethereum enabled browser =D 331 | 332 | ## Our Relationship with Ethereum & EthereumJS 333 | 334 | We would like to mention that we are not in any way affiliated with the Ethereum Foundation or `ethereumjs`. However, we love the work they do and work with them often to make Ethereum great! Our aim is to support the Ethereum ecosystem with a policy of diversity, modularity, simplicity, transparency, clarity, optimization and extensibility. 335 | 336 | Many of our modules use code from `web3.js` and the `ethereumjs-` repositories. We thank the authors where we can in the relevant repositories. We use their code carefully, and make sure all test coverage is ported over and where possible, expanded on. 337 | -------------------------------------------------------------------------------- /internals/webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); // eslint-disable-line 2 | 3 | var env = process.env.NODE_ENV; // eslint-disable-line 4 | var filename = 'ethjs-contract'; // eslint-disable-line 5 | var library = 'EthContract'; // eslint-disable-line 6 | var config = { // eslint-disable-line 7 | module: { 8 | loaders: [ 9 | { 10 | test: /\.js$/, 11 | loaders: ['babel-loader'], 12 | exclude: /node_modules/, 13 | }, 14 | { 15 | test: /\.json$/, 16 | loader: 'json', 17 | }, 18 | ], 19 | }, 20 | devtool: 'cheap-module-source-map', 21 | output: { 22 | path: 'dist', 23 | filename: filename + '.js', // eslint-disable-line 24 | library: library, // eslint-disable-line 25 | libraryTarget: 'umd', 26 | umdNamedDefine: true, 27 | }, 28 | plugins: [ 29 | new webpack.BannerPlugin({ banner: ' /* eslint-disable */ ', raw: true, entryOnly: true }), 30 | new webpack.optimize.OccurrenceOrderPlugin(), 31 | new webpack.DefinePlugin({ 32 | 'process.env.NODE_ENV': JSON.stringify(env), 33 | }), 34 | ], 35 | }; 36 | 37 | if (env === 'production') { 38 | config.output.filename = filename + '.min.js'; // eslint-disable-line 39 | config.plugins 40 | .push(new webpack.optimize.UglifyJsPlugin({ 41 | compressor: { 42 | pure_getters: true, 43 | unsafe: true, 44 | unsafe_comps: true, 45 | warnings: false, 46 | screw_ie8: false, 47 | }, 48 | mangle: { 49 | screw_ie8: false, 50 | }, 51 | output: { 52 | screw_ie8: false, 53 | }, 54 | })); 55 | config.plugins.push(new webpack.optimize.DedupePlugin()); 56 | } 57 | 58 | module.exports = config; 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": { 3 | "name": "Nick Dodson", 4 | "email": "nick.dodson@consensys.net" 5 | }, 6 | "babel": { 7 | "plugins": [ 8 | [ 9 | "transform-es2015-template-literals", 10 | { 11 | "loose": true 12 | } 13 | ], 14 | "transform-es2015-literals", 15 | "transform-es2015-function-name", 16 | "transform-es2015-arrow-functions", 17 | "transform-es2015-block-scoped-functions", 18 | [ 19 | "transform-es2015-classes", 20 | { 21 | "loose": true 22 | } 23 | ], 24 | "transform-es2015-object-super", 25 | "transform-es2015-shorthand-properties", 26 | [ 27 | "transform-es2015-computed-properties", 28 | { 29 | "loose": true 30 | } 31 | ], 32 | [ 33 | "transform-es2015-for-of", 34 | { 35 | "loose": true 36 | } 37 | ], 38 | "transform-es2015-sticky-regex", 39 | "transform-es2015-unicode-regex", 40 | "check-es2015-constants", 41 | [ 42 | "transform-es2015-spread", 43 | { 44 | "loose": true 45 | } 46 | ], 47 | "transform-es2015-parameters", 48 | [ 49 | "transform-es2015-destructuring", 50 | { 51 | "loose": true 52 | } 53 | ], 54 | "transform-es2015-block-scoping", 55 | "transform-object-rest-spread", 56 | "transform-es3-member-expression-literals", 57 | "transform-es3-property-literals", 58 | "transform-es3-property-literals", 59 | "transform-async-to-generator", 60 | "transform-regenerator", 61 | "transform-runtime" 62 | ], 63 | "env": { 64 | "commonjs": { 65 | "plugins": [ 66 | [ 67 | "transform-es2015-modules-commonjs", 68 | { 69 | "loose": true 70 | } 71 | ] 72 | ] 73 | } 74 | } 75 | }, 76 | "bugs": { 77 | "url": "https://github.com/ethjs/ethjs-contract/issues" 78 | }, 79 | "bundleDependencies": false, 80 | "dependencies": { 81 | "ethjs-abi": "0.2.0", 82 | "ethjs-filter": "0.1.7", 83 | "ethjs-util": "0.1.3", 84 | "js-sha3": "0.5.5" 85 | }, 86 | "deprecated": false, 87 | "description": "A simple contract object for the Ethereum RPC.", 88 | "devDependencies": { 89 | "async": "^2.6.0", 90 | "babel-cli": "6.18.0", 91 | "babel-core": "6.18.2", 92 | "babel-eslint": "7.1.0", 93 | "babel-loader": "6.2.8", 94 | "babel-plugin-check-es2015-constants": "6.8.0", 95 | "babel-plugin-transform-async-to-generator": "^6.24.1", 96 | "babel-plugin-transform-es2015-arrow-functions": "6.8.0", 97 | "babel-plugin-transform-es2015-block-scoped-functions": "6.8.0", 98 | "babel-plugin-transform-es2015-block-scoping": "6.18.0", 99 | "babel-plugin-transform-es2015-classes": "6.18.0", 100 | "babel-plugin-transform-es2015-computed-properties": "6.8.0", 101 | "babel-plugin-transform-es2015-destructuring": "6.19.0", 102 | "babel-plugin-transform-es2015-for-of": "6.18.0", 103 | "babel-plugin-transform-es2015-function-name": "6.9.0", 104 | "babel-plugin-transform-es2015-literals": "6.8.0", 105 | "babel-plugin-transform-es2015-modules-commonjs": "6.18.0", 106 | "babel-plugin-transform-es2015-object-super": "6.8.0", 107 | "babel-plugin-transform-es2015-parameters": "6.18.0", 108 | "babel-plugin-transform-es2015-shorthand-properties": "6.18.0", 109 | "babel-plugin-transform-es2015-spread": "6.8.0", 110 | "babel-plugin-transform-es2015-sticky-regex": "6.8.0", 111 | "babel-plugin-transform-es2015-template-literals": "6.8.0", 112 | "babel-plugin-transform-es2015-unicode-regex": "6.11.0", 113 | "babel-plugin-transform-es3-member-expression-literals": "6.5.0", 114 | "babel-plugin-transform-es3-property-literals": "^6.5.0", 115 | "babel-plugin-transform-object-rest-spread": "6.19.0", 116 | "babel-plugin-transform-regenerator": "^6.26.0", 117 | "babel-plugin-transform-runtime": "^6.23.0", 118 | "babel-register": "6.18.0", 119 | "chai": "3.5.0", 120 | "check-es3-syntax-cli": "0.1.3", 121 | "coveralls": "2.11.9", 122 | "cross-env": "1.0.7", 123 | "eslint": "^3.19.0", 124 | "eslint-config-airbnb": "9.0.1", 125 | "eslint-import-resolver-webpack": "0.2.4", 126 | "eslint-plugin-import": "1.8.0", 127 | "eslint-plugin-jsx-a11y": "1.2.0", 128 | "eslint-plugin-react": "5.1.1", 129 | "ethereumjs-testrpc": "3.0.2", 130 | "ethjs-provider-http": "0.1.3", 131 | "ethjs-query": "^0.3.6", 132 | "eventsource-polyfill": "0.9.6", 133 | "ganache-core": "^2.1.0", 134 | "hard-rejection": "^1.0.0", 135 | "istanbul": "0.4.5", 136 | "json-loader": "0.5.4", 137 | "lint-staged": "1.0.1", 138 | "mocha": "3.1.2", 139 | "pre-commit": "1.1.3", 140 | "promise-to-callback": "^1.0.0", 141 | "rimraf": "2.3.4", 142 | "webpack": "2.1.0-beta.15" 143 | }, 144 | "engines": { 145 | "node": ">=6.5.0", 146 | "npm": ">=3" 147 | }, 148 | "eslintConfig": { 149 | "parser": "babel-eslint", 150 | "extends": "airbnb", 151 | "env": { 152 | "node": true, 153 | "mocha": true, 154 | "es6": true 155 | }, 156 | "parserOptions": { 157 | "ecmaVersion": 6, 158 | "sourceType": "module" 159 | }, 160 | "rules": { 161 | "import/no-unresolved": 2, 162 | "comma-dangle": [ 163 | 2, 164 | "always-multiline" 165 | ], 166 | "indent": [ 167 | 2, 168 | 2, 169 | { 170 | "SwitchCase": 1 171 | } 172 | ], 173 | "no-console": 1, 174 | "max-len": 0, 175 | "prefer-template": 2, 176 | "no-use-before-define": 0, 177 | "newline-per-chained-call": 0, 178 | "arrow-body-style": [ 179 | 2, 180 | "as-needed" 181 | ] 182 | } 183 | }, 184 | "files": [ 185 | "dist", 186 | "internals", 187 | "lib", 188 | "src" 189 | ], 190 | "homepage": "https://github.com/ethjs/ethjs-contract#readme", 191 | "keywords": [ 192 | "ethereum", 193 | "events", 194 | "rpc" 195 | ], 196 | "license": "MIT", 197 | "lint-staged": { 198 | "lint:eslint": "*.js" 199 | }, 200 | "main": "lib/index.js", 201 | "name": "ethjs-contract", 202 | "pre-commit": "build", 203 | "repository": { 204 | "type": "git", 205 | "url": "git+ssh://git@github.com/ethjs/ethjs-contract.git" 206 | }, 207 | "scripts": { 208 | "build": "npm run build:commonjs && npm run test:lib && npm run build:umd && npm run build:umd:min", 209 | "build:clean": "npm run test:clean && rimraf ./dist", 210 | "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --copy-files", 211 | "build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --config ./internals/webpack/webpack.config.js ./lib/index.js --progress", 212 | "build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --config ./internals/webpack/webpack.config.js ./lib/index.js --progress", 213 | "coveralls": "npm run test-travis && cat ./coverage/lcov.info | coveralls", 214 | "lint": "npm run lint:js", 215 | "lint:eslint": "eslint --ignore-path .gitignore --ignore-pattern **/**.min.js", 216 | "lint:js": "npm run lint:eslint -- . ", 217 | "lint:staged": "lint-staged", 218 | "prebuild": "npm run build:clean && npm run test", 219 | "prepublish": "npm run build", 220 | "pretest": "npm run lint", 221 | "release": "npmpub", 222 | "start": "npm test", 223 | "test": "mocha ./src/tests/**/*.js -R spec --timeout 2000000", 224 | "test-travis": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- src/tests/**/*.js -R spec --timeout 2000000", 225 | "test:clean": "rimraf ./coverage", 226 | "test:lib": "mocha ./lib/tests/**/*.js -R spec --timeout 2000000" 227 | }, 228 | "version": "0.2.1" 229 | } 230 | -------------------------------------------------------------------------------- /src/contract.js: -------------------------------------------------------------------------------- 1 | const abi = require('ethjs-abi'); // eslint-disable-line 2 | const EthFilter = require('ethjs-filter'); // eslint-disable-line 3 | const getKeys = require('ethjs-util').getKeys; // eslint-disable-line 4 | const keccak256 = require('js-sha3').keccak_256; // eslint-disable-line 5 | const hasTransactionObject = require('./has-tx-object'); 6 | const promiseToCallback = require('promise-to-callback'); 7 | 8 | module.exports = Contract; 9 | 10 | function Contract(opts = {}) { 11 | const self = this; 12 | self.abi = opts.contractABI || []; 13 | self.query = opts.query; 14 | self.address = opts.address || '0x'; 15 | self.bytecode = opts.contractBytecode || '0x'; 16 | self.defaultTxObject = opts.contractDefaultTxObject || {}; 17 | self.filters = new EthFilter(self.query); 18 | 19 | getCallableMethodsFromABI(self.abi).forEach((methodObject) => { 20 | if (methodObject.type === 'function') { 21 | self[methodObject.name] = createContractFunction(methodObject); 22 | } else if (methodObject.type === 'event') { 23 | self[methodObject.name] = createContractEvent(methodObject); 24 | } 25 | }); 26 | 27 | function createContractEvent(methodObject) { 28 | return function contractEvent() { 29 | const methodArgs = [].slice.call(arguments); // eslint-disable-line 30 | 31 | const filterInputTypes = getKeys(methodObject.inputs, 'type', false); 32 | const filterTopic = `0x${keccak256(`${methodObject.name}(${filterInputTypes.join(',')})`)}`; 33 | const filterTopcis = [filterTopic]; 34 | const argsObject = Object.assign({}, methodArgs[0]) || {}; 35 | 36 | const defaultFilterObject = Object.assign({}, (methodArgs[0] || {}), { 37 | to: self.address, 38 | topics: filterTopcis, 39 | }); 40 | const filterOpts = Object.assign({}, argsObject, { 41 | decoder: (logData) => abi.decodeEvent(methodObject, logData, filterTopcis), 42 | defaultFilterObject, 43 | }); 44 | 45 | return new self.filters.Filter(filterOpts); 46 | }; 47 | } 48 | 49 | function createContractFunction(methodObject) { 50 | return function contractFunction() { 51 | let methodCallback; // eslint-disable-line 52 | const methodArgs = [].slice.call(arguments); // eslint-disable-line 53 | if (typeof methodArgs[methodArgs.length - 1] === 'function') { 54 | methodCallback = methodArgs.pop(); 55 | } 56 | 57 | const promise = performCall({ methodObject, methodArgs }); 58 | 59 | if (methodCallback) { 60 | return promiseToCallback(promise)(methodCallback); 61 | } 62 | 63 | return promise; 64 | }; 65 | } 66 | 67 | async function performCall({ methodObject, methodArgs }) { 68 | let queryMethod = 'call'; // eslint-disable-line 69 | let providedTxObject = {}; // eslint-disable-line 70 | 71 | if (hasTransactionObject(methodArgs)) providedTxObject = methodArgs.pop(); 72 | const methodTxObject = Object.assign({}, 73 | self.defaultTxObject, 74 | providedTxObject, { 75 | to: self.address, 76 | }); 77 | methodTxObject.data = abi.encodeMethod(methodObject, methodArgs); 78 | 79 | if (methodObject.constant === false) { 80 | queryMethod = 'sendTransaction'; 81 | } 82 | 83 | const queryResult = await self.query[queryMethod](methodTxObject); 84 | 85 | if (queryMethod === 'call') { 86 | // queryMethod is 'call', result is returned value 87 | try { 88 | const decodedMethodResult = abi.decodeMethod(methodObject, queryResult); 89 | return decodedMethodResult; 90 | } catch (decodeFormattingError) { 91 | const decodingError = new Error(`[ethjs-contract] while formatting incoming raw call data ${JSON.stringify(queryResult)} ${decodeFormattingError}`); 92 | throw decodingError; 93 | } 94 | } 95 | // queryMethod is 'sendTransaction', result is txHash 96 | return queryResult; 97 | } 98 | } 99 | 100 | function getCallableMethodsFromABI(contractABI) { 101 | return contractABI.filter((json) => ((json.type === 'function' || json.type === 'event') && json.name.length > 0)); 102 | } 103 | -------------------------------------------------------------------------------- /src/has-tx-object.js: -------------------------------------------------------------------------------- 1 | const txObjectProperties = ['from', 'to', 'data', 'value', 'gasPrice', 'gas']; 2 | 3 | module.exports = hasTransactionObject; 4 | 5 | function hasTransactionObject(args) { 6 | // bad/empty args: bad 7 | if (!Array.isArray(args) || args.length === 0) { 8 | return false; 9 | } 10 | const lastArg = args[args.length - 1]; 11 | // missing or non-object: bad 12 | if (!lastArg) return false; 13 | if (typeof lastArg !== 'object') { 14 | return false; 15 | } 16 | // empty object: good 17 | if (Object.keys(lastArg).length === 0) { 18 | return true; 19 | } 20 | // txParams object: good 21 | const keys = Object.keys(lastArg); 22 | const hasMatchingKeys = txObjectProperties.some((value) => keys.includes(value)); 23 | if (hasMatchingKeys) { 24 | return true; 25 | } 26 | // no match 27 | return false; 28 | } 29 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const abi = require('ethjs-abi'); // eslint-disable-line 2 | const keccak256 = require('js-sha3').keccak_256; // eslint-disable-line 3 | const EthFilter = require('ethjs-filter'); // eslint-disable-line 4 | const getKeys = require('ethjs-util').getKeys; // eslint-disable-line 5 | const Contract = require('./contract'); 6 | const hasTransactionObject = require('./has-tx-object'); 7 | 8 | module.exports = EthContract; 9 | 10 | function EthContract(query) { 11 | return function contractFactory(contractABI, contractBytecode, contractDefaultTxObject) { 12 | // validate params 13 | if (!Array.isArray(contractABI)) { throw new Error(`[ethjs-contract] Contract ABI must be type Array, got type ${typeof contractABI}`); } 14 | if (typeof contractBytecode !== 'undefined' && typeof contractBytecode !== 'string') { throw new Error(`[ethjs-contract] Contract bytecode must be type String, got type ${typeof contractBytecode}`); } 15 | if (typeof contractDefaultTxObject !== 'undefined' && typeof contractDefaultTxObject !== 'object') { throw new Error(`[ethjs-contract] Contract default tx object must be type Object, got type ${typeof contractABI}`); } 16 | 17 | // build contract object 18 | const output = {}; 19 | output.at = function contractAtAddress(address) { 20 | return new Contract({ 21 | address, 22 | query, 23 | contractBytecode, 24 | contractDefaultTxObject, 25 | contractABI, 26 | }); 27 | }; 28 | 29 | output.new = function newContract() { 30 | let providedTxObject = {}; // eslint-disable-line 31 | let newMethodCallback = null; // eslint-disable-line 32 | const newMethodArgs = [].slice.call(arguments); // eslint-disable-line 33 | if (typeof newMethodArgs[newMethodArgs.length - 1] === 'function') newMethodCallback = newMethodArgs.pop(); 34 | if (hasTransactionObject(newMethodArgs)) providedTxObject = newMethodArgs.pop(); 35 | const constructorMethod = getConstructorFromABI(contractABI); 36 | const assembleTxObject = Object.assign({}, contractDefaultTxObject, providedTxObject); 37 | 38 | // set contract deploy bytecode 39 | if (contractBytecode) { 40 | assembleTxObject.data = contractBytecode; 41 | } 42 | 43 | // append encoded constructor arguments 44 | if (constructorMethod) { 45 | const constructorBytecode = abi.encodeParams(getKeys(constructorMethod.inputs, 'type'), newMethodArgs).substring(2); // eslint-disable-line 46 | assembleTxObject.data = `${assembleTxObject.data}${constructorBytecode}`; 47 | } 48 | 49 | return newMethodCallback ? query.sendTransaction(assembleTxObject, newMethodCallback) : query.sendTransaction(assembleTxObject); 50 | }; 51 | 52 | return output; 53 | }; 54 | } 55 | 56 | function getConstructorFromABI(contractABI) { 57 | return contractABI.filter((json) => (json.type === 'constructor'))[0]; 58 | } 59 | -------------------------------------------------------------------------------- /src/tests/test-contracts.js: -------------------------------------------------------------------------------- 1 | const SimpleStoreABI = [{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]; // eslint-disable-line 2 | const SimpleStoreBytecode = '606060405234610000575b5b5b61010e8061001a6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b1146100435780636d4ce63c14610076575b610000565b346100005761005e6004808035906020019091905050610099565b60405180821515815260200191505060405180910390f35b3461000057610083610103565b6040518082815260200191505060405180910390f35b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b9056'; 3 | 4 | const ComplexStoreABI = [{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"someVal","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"addresses","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"_someVal","type":"uint256"},{"name":"_addresses","type":"address[]"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]; // eslint-disable-line 5 | const ComplexStoreBytecode = '606060405234610000576040516102e13803806102e1833981016040528080519060200190919080518201919060200150505b8160018190555080600290805190602001908280548282559060005260206000209081019282156100b9579160200282015b828111156100b85782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690836c0100000000000000000000000090810204021790555091602001919060010190610064565b5b5090506100fc91905b808211156100f857600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055506001016100c2565b5090565b50505b50505b6101d1806101106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b1146100595780636d4ce63c1461008c578063a55f8600146100af578063edf26d9b146100d2575b610000565b34610000576100746004808035906020019091905050610119565b60405180821515815260200191505060405180910390f35b3461000057610099610183565b6040518082815260200191505060405180910390f35b34610000576100bc61018e565b6040518082815260200191505060405180910390f35b34610000576100ed6004808035906020019091905050610194565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b90565b60015481565b600281815481101561000057906000526020600020900160005b915054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156'; 6 | 7 | const ExtraComplexStoreABI = [{"constant":false,"inputs":[{"name":"_val1","type":"int256"},{"name":"_val2","type":"uint256"},{"name":"_val3","type":"address[]"},{"name":"_val4","type":"string"},{"name":"_val5","type":"uint8"},{"name":"_val6","type":"bytes32"},{"name":"_val7","type":"bytes"},{"name":"_val8","type":"bytes8"},{"name":"_val9","type":"int8"},{"name":"_val10","type":"int16"},{"name":"_val11","type":"uint256[]"}],"name":"multiTypeSet","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"multiTypeReturn","outputs":[{"name":"_val1","type":"int256"},{"name":"_val2","type":"uint256"},{"name":"_val3","type":"address[]"},{"name":"_val4","type":"string"},{"name":"_val5","type":"uint8"},{"name":"_val6","type":"bytes32"},{"name":"_val7","type":"bytes"},{"name":"_val8","type":"bytes8"},{"name":"_val9","type":"int8"},{"name":"_val10","type":"int16"},{"name":"_val11","type":"uint256[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_nick","type":"string"}],"name":"somePayableMethod","outputs":[],"payable":true,"type":"function"},{"constant":true,"inputs":[],"name":"someVal","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"addresses","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"_someVal","type":"uint256"},{"name":"_addresses","type":"address[]"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}]; // eslint-disable-line 8 | const ExtraComplexStoreBytecode = '60606040523461000057604051610cc5380380610cc5833981016040528080519060200190919080518201919060200150505b8160018190555080600290805190602001908280548282559060005260206000209081019282156100b9579160200282015b828111156100b85782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690836c0100000000000000000000000090810204021790555091602001919060010190610064565b5b5090506100fc91905b808211156100f857600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055506001016100c2565b5090565b50505b50505b610bb5806101106000396000f36060604052361561007b576000357c0100000000000000000000000000000000000000000000000000000000900480632c0e463c14610080578063572c66e3146101d957806360fe47b1146103825780636d4ce63c146103b5578063a4b0d121146103d8578063a55f86001461042a578063edf26d9b1461044d575b610000565b34610000576101d760048080359060200190919080359060200190919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803590602001909190803590602001909190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803590602001909190803590602001909190803590602001909190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091905050610494565b005b34610000576101e661081e565b604051808c81526020018b815260200180602001806020018a60ff16815260200189600019168152602001806020018877ffffffffffffffffffffffffffffffffffffffffffffffff191681526020018760000b81526020018660010b81526020018060200185810385528e8181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f15090500185810384528d8181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156102d95780820380516001836020036101000a031916815260200191505b5085810383528a8181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156103325780820380516001836020036101000a031916815260200191505b508581038252868181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050019f5050505050505050505050505050505060405180910390f35b346100005761039d6004808035906020019091905050610af9565b60405180821515815260200191505060405180910390f35b34610000576103c2610b63565b6040518082815260200191505060405180910390f35b610428600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610b6e565b005b3461000057610437610b72565b6040518082815260200191505060405180910390f35b34610000576104686004808035906020019091905050610b78565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b8a600381905550896004819055508860059080519060200190828054828255906000526020600020908101928215610522579160200282015b828111156105215782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690836c01000000000000000000000000908102040217905550916020019190600101906104cd565b5b50905061056591905b8082111561056157600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555060010161052b565b5090565b50508760069080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b357805160ff19168380011785556105e1565b828001600101855582156105e1579182015b828111156105e05782518255916020019190600101906105c5565b5b50905061060691905b808211156106025760008160009055506001016105ea565b5090565b505086600760006101000a81548160ff02191690837f0100000000000000000000000000000000000000000000000000000000000000908102040217905550856008819055508460099080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061069857805160ff19168380011785556106c6565b828001600101855582156106c6579182015b828111156106c55782518255916020019190600101906106aa565b5b5090506106eb91905b808211156106e75760008160009055506001016106cf565b5090565b505083600a60006101000a81548167ffffffffffffffff021916908378010000000000000000000000000000000000000000000000009004021790555082600a60086101000a81548160ff02191690837f010000000000000000000000000000000000000000000000000000000000000090810204021790555081600a60096101000a81548161ffff02191690837e0100000000000000000000000000000000000000000000000000000000000090810204021790555080600b90805190602001908280548282559060005260206000209081019282156107e9579160200282015b828111156107e85782518255916020019190600101906107cd565b5b50905061080e91905b8082111561080a5760008160009055506001016107f2565b5090565b50505b5050505050505050505050565b600060006020604051908101604052806000815260200150602060405190810160405280600081526020015060006000602060405190810160405280600081526020015060006000600060206040519081016040528060008152602001506003549a50600454995060058054806020026020016040519081016040528092919081815260200182805480156108f257602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116108be575b5050505050985060068054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561098f5780601f106109645761010080835404028352916020019161098f565b820191906000526020600020905b81548152906001019060200180831161097257829003601f168201915b50505050509750600760009054906101000a900460ff169650600854955060098054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a435780601f10610a1857610100808354040283529160200191610a43565b820191906000526020600020905b815481529060010190602001808311610a2657829003601f168201915b50505050509450600a60009054906101000a90047801000000000000000000000000000000000000000000000000029350600a60089054906101000a900460000b9250600a60099054906101000a900460010b9150600b805480602002602001604051908101604052809291908181526020018280548015610ae457602002820191906000526020600020905b815481526020019060010190808311610ad0575b505050505090505b909192939495969798999a565b6000816000819055507f10e8e9bc5a1bde3dd6bb7245b52503fcb9d9b1d7c7b26743f82c51cc7cce917d60005433604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1600190505b919050565b600060005490505b90565b5b50565b60015481565b600281815481101561000057906000526020600020900160005b915054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156'; 9 | 10 | module.exports = { 11 | SimpleStore: { 12 | abi: SimpleStoreABI, 13 | bytecode: SimpleStoreBytecode, 14 | }, 15 | ComplexStore: { 16 | abi: ComplexStoreABI, 17 | bytecode: ComplexStoreBytecode, 18 | }, 19 | ExtraComplexStore: { 20 | abi: ExtraComplexStoreABI, 21 | bytecode: ExtraComplexStoreBytecode, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /src/tests/test.index.js: -------------------------------------------------------------------------------- 1 | require('hard-rejection')(); 2 | const EthContract = require('../index.js'); 3 | const Eth = require('ethjs-query'); 4 | const GanacheCore = require('ganache-core'); 5 | const assert = require('chai').assert; 6 | const BN = require('bn.js'); // eslint-disable-line 7 | const asyncWaterfall = require('async/waterfall'); 8 | const TestContracts = require('./test-contracts'); 9 | 10 | describe('EthContract', () => { 11 | let provider; 12 | beforeEach(() => { 13 | provider = GanacheCore.provider(); 14 | }); 15 | 16 | describe('should function normally', () => { 17 | it('should work normally with callbacks', (done) => { 18 | const eth = new Eth(provider); 19 | const contract = new EthContract(eth); 20 | assert.equal(typeof contract, 'function'); 21 | 22 | let SimpleStore; 23 | let newResult; 24 | let simpleStore; 25 | let setResult; 26 | let setNumberValue; 27 | 28 | asyncWaterfall([ 29 | (cb) => { 30 | eth.accounts(cb); 31 | }, 32 | (accounts, cb) => { 33 | assert.equal(Array.isArray(accounts), true); 34 | SimpleStore = contract(TestContracts.SimpleStore.abi, TestContracts.SimpleStore.bytecode, { 35 | from: accounts[0], 36 | gas: 300000, 37 | }); 38 | SimpleStore.new(cb); 39 | }, 40 | (_newResult, cb) => { 41 | newResult = _newResult; 42 | assert.equal(typeof newResult, 'string'); 43 | cb(); 44 | }, 45 | (cb) => { 46 | eth.getTransactionReceipt(newResult, cb); 47 | }, 48 | (receipt, cb) => { 49 | assert.equal(typeof receipt, 'object'); 50 | assert.equal(typeof receipt.contractAddress, 'string'); 51 | 52 | setNumberValue = 4500; 53 | simpleStore = SimpleStore.at(receipt.contractAddress); 54 | 55 | assert.equal(typeof simpleStore.abi, 'object'); 56 | assert.equal(typeof simpleStore.address, 'string'); 57 | assert.equal(simpleStore.address, receipt.contractAddress); 58 | assert.equal(typeof simpleStore.set, 'function'); 59 | assert.equal(typeof simpleStore.get, 'function'); 60 | assert.equal(typeof simpleStore.SetComplete, 'function'); 61 | 62 | simpleStore.set(setNumberValue, cb); 63 | }, 64 | (_setResult, cb) => { 65 | setResult = _setResult; 66 | assert.equal(typeof setResult, 'string'); 67 | cb(); 68 | }, 69 | (cb) => { 70 | eth.getTransactionReceipt(setResult, cb); 71 | }, 72 | (setTxReceipt, cb) => { 73 | assert.equal(typeof setTxReceipt, 'object'); 74 | simpleStore.get(cb); 75 | }, 76 | (getResult, cb) => { 77 | assert.equal(typeof getResult, 'object'); 78 | assert.equal(getResult[0].toNumber(10), setNumberValue); 79 | cb(); 80 | }, 81 | ], done); 82 | }); 83 | 84 | it('should work normally with promises', async () => { 85 | const eth = new Eth(provider); 86 | const { simpleStore } = await deploySimpleStore({ eth }); 87 | 88 | const setNumberValue = 4500; 89 | const setResult = await simpleStore.set(setNumberValue); 90 | assert.equal(typeof setResult, 'string'); 91 | 92 | const setTxReceipt = await eth.getTransactionReceipt(setResult); 93 | assert.equal(typeof setTxReceipt, 'object'); 94 | 95 | const getResult = await simpleStore.get(); 96 | assert.equal(typeof getResult, 'object'); 97 | assert.equal(getResult[0].toNumber(10), setNumberValue); 98 | }); 99 | 100 | it('should use events properly', async () => { 101 | function FakeProvider() { 102 | this.provider = provider; 103 | } 104 | 105 | FakeProvider.prototype.sendAsync = function sendAsync(payload, callback) { 106 | const self = this; 107 | const parsedPayload = payload; 108 | 109 | if (parsedPayload.method === 'eth_getFilterChanges') { 110 | self.provider.sendAsync(payload, () => { 111 | const fakeEventLog = { 112 | id: parsedPayload.id, 113 | jsonrpc: parsedPayload.jsonrpc, 114 | result: [{ 115 | logIndex: '0x0', 116 | blockNumber: '0x1b4', 117 | blockHash: '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d54', 118 | transactionHash: '0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dc23f', 119 | transactionIndex: '0x0', 120 | address: '0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d', 121 | data: '0x0000000000000000000000000000000000000000000000000000000000001194000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c', 122 | topics: ['0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5'], 123 | }], 124 | }; 125 | 126 | callback(null, fakeEventLog); 127 | }); 128 | } else { 129 | self.provider.sendAsync(payload, callback); 130 | } 131 | }; 132 | 133 | const eth = new Eth(new FakeProvider()); 134 | const { simpleStore } = await deploySimpleStore({ eth }); 135 | const { watchPromise } = await simpleStorePerformSetAndWatchOnce({ simpleStore }); 136 | 137 | try { 138 | await watchPromise; 139 | // expect to throw 140 | assert.fail(); 141 | } catch (err) { 142 | assert.ok(err); 143 | assert.equal(typeof err, 'object'); 144 | } 145 | }); 146 | 147 | it('should catch watch error under promise', async () => { 148 | function FakeProvider() { 149 | this.provider = provider; 150 | } 151 | 152 | FakeProvider.prototype.sendAsync = function sendAsync(payload, callback) { 153 | const self = this; 154 | const parsedPayload = payload; 155 | 156 | if (parsedPayload.method === 'eth_getFilterChanges') { 157 | self.provider.sendAsync(payload, () => { 158 | const fakeEventLog = { 159 | id: parsedPayload.id, 160 | jsonrpc: parsedPayload.jsonrpc, 161 | error: 'invalid data', 162 | }; 163 | 164 | callback(null, fakeEventLog); 165 | }); 166 | } else { 167 | self.provider.sendAsync(payload, callback); 168 | } 169 | }; 170 | 171 | const eth = new Eth(new FakeProvider()); 172 | const { simpleStore } = await deploySimpleStore({ eth }); 173 | const { watchPromise } = await simpleStorePerformSetAndWatchOnce({ simpleStore }); 174 | 175 | try { 176 | await watchPromise; 177 | // expect to throw 178 | assert.fail(); 179 | } catch (watchErr) { 180 | assert.ok(watchErr); 181 | assert.equal(typeof watchErr, 'object'); 182 | } 183 | }); 184 | 185 | it('should catch watch error under promise invalid decode', async () => { 186 | function FakeProvider() { 187 | this.provider = provider; 188 | } 189 | 190 | FakeProvider.prototype.sendAsync = function sendAsync(payload, callback) { 191 | const self = this; 192 | const parsedPayload = payload; 193 | 194 | if (parsedPayload.method === 'eth_getFilterChanges') { 195 | self.provider.sendAsync(payload, () => { 196 | const fakeEventLog = { 197 | id: parsedPayload.id, 198 | jsonrpc: parsedPayload.jsonrpc, 199 | result: [{ 200 | logIndex: '0x0', 201 | blockNumber: '0x1b4', 202 | blockHash: '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d54', 203 | transactionHash: '0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dc23f', 204 | transactionIndex: '0x0', 205 | address: '0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d', 206 | data: '0xkjdsfkjfskjs', 207 | topics: ['0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5'], 208 | }], 209 | }; 210 | 211 | callback(null, fakeEventLog); 212 | }); 213 | } else { 214 | self.provider.sendAsync(payload, callback); 215 | } 216 | }; 217 | 218 | const eth = new Eth(new FakeProvider()); 219 | const { simpleStore } = await deploySimpleStore({ eth }); 220 | const { watchPromise } = await simpleStorePerformSetAndWatchOnce({ simpleStore }); 221 | 222 | try { 223 | await watchPromise; 224 | // expect to throw 225 | assert.fail(); 226 | } catch (err) { 227 | assert.ok(err); 228 | assert.equal(typeof err, 'object'); 229 | } 230 | }); 231 | 232 | it('should catch event watch error', async () => { 233 | function FakeProvider() { 234 | this.provider = provider; 235 | } 236 | 237 | FakeProvider.prototype.sendAsync = function sendAsync(payload, callback) { 238 | const self = this; 239 | const parsedPayload = payload; 240 | 241 | if (parsedPayload.method === 'eth_getFilterChanges') { 242 | self.provider.sendAsync(payload, () => { 243 | const fakeEventLog = { 244 | id: parsedPayload.id, 245 | jsonrpc: parsedPayload.jsonrpc, 246 | error: 'invalid data', 247 | }; 248 | 249 | callback(null, fakeEventLog); 250 | }); 251 | } else { 252 | self.provider.sendAsync(payload, callback); 253 | } 254 | }; 255 | 256 | const eth = new Eth(new FakeProvider()); 257 | const { simpleStore } = await deploySimpleStore({ eth }); 258 | const { watchPromise } = await simpleStorePerformSetAndWatchOnce({ simpleStore }); 259 | 260 | try { 261 | await watchPromise; 262 | // expect to throw 263 | assert.fail(); 264 | } catch (err) { 265 | assert.ok(err); 266 | assert.equal(typeof err, 'object'); 267 | } 268 | }); 269 | 270 | it('should handle invalid call data with error', async () => { 271 | function FakeProvider() { 272 | this.provider = provider; 273 | } 274 | 275 | FakeProvider.prototype.sendAsync = function sendAsync(payload, callback) { 276 | const self = this; 277 | const parsedPayload = payload; 278 | 279 | if (parsedPayload.method === 'eth_call') { 280 | self.provider.sendAsync(payload, () => { 281 | const fakeEventLog = { 282 | id: parsedPayload.id, 283 | jsonrpc: parsedPayload.jsonrpc, 284 | result: '0xkfsdksdfkjfsdjk', 285 | }; 286 | 287 | callback(null, fakeEventLog); 288 | }); 289 | } else { 290 | self.provider.sendAsync(payload, callback); 291 | } 292 | }; 293 | 294 | const eth = new Eth(new FakeProvider()); 295 | const { simpleStore } = await deploySimpleStore({ eth }); 296 | 297 | try { 298 | await simpleStore.get(); 299 | // expect to throw 300 | assert.fail(); 301 | } catch (err) { 302 | assert.ok(err); 303 | assert.equal(typeof err, 'object'); 304 | } 305 | }); 306 | 307 | it('should construct properly with some overriding txObjects', async () => { 308 | const eth = new Eth(provider); 309 | 310 | const accounts = await eth.accounts(); 311 | const firstFrom = accounts[3]; 312 | const secondFrom = accounts[6]; 313 | 314 | const defaultTxObject = { from: firstFrom }; 315 | const { simpleStore, deployTx } = await deploySimpleStore({ eth, defaultTxObject }); 316 | assert.equal(deployTx.from, firstFrom); 317 | 318 | const setOpts = { from: secondFrom }; 319 | const { setTx } = await simpleStorePerformSetAndGet({ eth, simpleStore, setOpts }); 320 | assert.equal(setTx.from, secondFrom); 321 | }); 322 | 323 | it('should construct properly with hexed bytecode', async () => { 324 | const eth = new Eth(provider); 325 | const newOpts = { 326 | data: TestContracts.SimpleStore.bytecode, 327 | }; 328 | const { simpleStore } = await deploySimpleStore({ eth, newOpts }); 329 | await simpleStorePerformSetAndGet({ eth, simpleStore }); 330 | }); 331 | 332 | it('should construct properly with no default tx bytecode', async () => { 333 | const eth = new Eth(provider); 334 | const newOpts = { 335 | data: TestContracts.SimpleStore.bytecode, 336 | }; 337 | const { simpleStore } = await deploySimpleStore({ eth, newOpts, contractBytecode: null }); 338 | await simpleStorePerformSetAndGet({ eth, simpleStore }); 339 | }); 340 | 341 | it('should construct properly with no default tx object when specified in new', async () => { 342 | const eth = new Eth(provider); 343 | const accounts = await eth.accounts(); 344 | const newOpts = { 345 | from: accounts[0], 346 | gas: 300000, 347 | }; 348 | const { simpleStore } = await deploySimpleStore({ eth, defaultTxObject: null, newOpts }); 349 | await simpleStorePerformSetAndGet({ eth, simpleStore, setOpts: newOpts }); 350 | }); 351 | 352 | it('should construct properly constructor params', async () => { 353 | const eth = new Eth(provider); 354 | await deployAndTestComplexStore({ eth }); 355 | }); 356 | 357 | it('should construct properly constructor params and overriding tx object', async () => { 358 | const eth = new Eth(provider); 359 | const accounts = await eth.accounts(); 360 | const newTxParams = { from: accounts[3] }; 361 | const { deployTx } = await deployAndTestComplexStore({ eth, newTxParams }); 362 | assert.equal(deployTx.from, accounts[3]); 363 | }); 364 | 365 | it('should handle multi-type set and multi-type return', async () => { 366 | const eth = new Eth(provider); 367 | const contract = new EthContract(eth); 368 | const accounts = await eth.accounts(); 369 | 370 | const initalValue = 730483222; 371 | const initalAddressArray = [accounts[3], accounts[2], accounts[1]]; 372 | const SimpleStore = contract(TestContracts.ExtraComplexStore.abi, TestContracts.ExtraComplexStore.bytecode, { 373 | from: accounts[0], 374 | gas: 3000000, 375 | }); 376 | const deployTxHash = await SimpleStore.new(initalValue, initalAddressArray, { from: accounts[3] }); 377 | assert.equal(typeof deployTxHash, 'string'); 378 | 379 | const setTxReceipt = await eth.getTransactionReceipt(deployTxHash); 380 | const extraComplexStore = SimpleStore.at(setTxReceipt.contractAddress); 381 | 382 | const args = [ 383 | // int _val1 384 | 453, 385 | // uint _val2 386 | new BN('289234972'), 387 | // address[] _val3 388 | [accounts[4], accounts[2]], 389 | // string _val4 390 | 'some great string', 391 | // uint8 _val5 392 | 55, 393 | // bytes32 _val6 394 | '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad', 395 | // bytes _val7 396 | '0x47173285a8d73bbfa254cb01fad3', 397 | // bytes8 _val8 398 | '0x47173285a8d73b3d', 399 | // int8 _val9 400 | 2, 401 | // int16 _val10 402 | 12, 403 | // uint256[] _val11 404 | [12342, 923849, new BN('249829233')], 405 | ]; 406 | const multiTypeSetTxHash = await extraComplexStore.multiTypeSet(...args); 407 | const multiSetReceipt = await eth.getTransactionReceipt(multiTypeSetTxHash); 408 | assert.equal(typeof multiSetReceipt, 'object'); 409 | 410 | const multiReturn = await extraComplexStore.multiTypeReturn(); 411 | assert.equal(typeof multiReturn, 'object'); 412 | 413 | assert.equal(multiReturn[0].toNumber(10), args[0]); 414 | assert.equal(multiReturn[1].toNumber(10), args[1].toNumber(10)); 415 | assert.equal(multiReturn[2][0], args[2][0]); 416 | assert.equal(multiReturn[2][1], args[2][1]); 417 | assert.equal(multiReturn[3], args[3]); 418 | assert.equal(multiReturn[4].toNumber(10), args[4]); 419 | assert.equal(multiReturn[5], args[5]); 420 | assert.equal(multiReturn[6], args[6]); 421 | assert.equal(multiReturn[7], args[7]); 422 | assert.equal(multiReturn[8].toNumber(10), args[8]); 423 | assert.equal(multiReturn[9].toNumber(10), args[9]); 424 | assert.equal(multiReturn[10][0].toNumber(10), args[10][0]); 425 | assert.equal(multiReturn[10][1].toNumber(10), args[10][1]); 426 | assert.equal(multiReturn[10][2].toNumber(10), args[10][2].toNumber(10)); 427 | }); 428 | }); 429 | }); 430 | 431 | async function deploySimpleStore({ eth, defaultTxObject, newOpts = {}, contractBytecode }) { 432 | const contract = new EthContract(eth); 433 | assert.equal(typeof contract, 'function'); 434 | 435 | const accounts = await eth.accounts(); 436 | assert.equal(Array.isArray(accounts), true); 437 | 438 | // set `defaultTxObject` option to null to omit 439 | const finalDefaultTxObject = (defaultTxObject === null) ? undefined : Object.assign({ 440 | from: accounts[0], 441 | gas: 300000, 442 | }, defaultTxObject); 443 | // set `contractBytecode` option to null to omit 444 | const finalContractByteCode = (contractBytecode === null) ? undefined : (contractBytecode || TestContracts.SimpleStore.bytecode); 445 | const SimpleStore = contract(TestContracts.SimpleStore.abi, finalContractByteCode, finalDefaultTxObject); 446 | 447 | const deployTxHash = await SimpleStore.new(newOpts); 448 | assert.ok(deployTxHash); 449 | assert.equal(typeof deployTxHash, 'string'); 450 | 451 | const deployTx = await eth.getTransactionByHash(deployTxHash); 452 | assert.ok(deployTx); 453 | assert.equal(typeof deployTx, 'object'); 454 | 455 | const deployTxRx = await eth.getTransactionReceipt(deployTxHash); 456 | assert.equal(typeof deployTxRx, 'object'); 457 | assert.equal(typeof deployTxRx.contractAddress, 'string'); 458 | 459 | const simpleStore = SimpleStore.at(deployTxRx.contractAddress); 460 | assert.equal(typeof simpleStore.abi, 'object'); 461 | assert.equal(typeof simpleStore.address, 'string'); 462 | assert.equal(simpleStore.address, deployTxRx.contractAddress); 463 | assert.equal(typeof simpleStore.set, 'function'); 464 | assert.equal(typeof simpleStore.get, 'function'); 465 | assert.equal(typeof simpleStore.SetComplete, 'function'); 466 | 467 | return { simpleStore, deployTx, deployTxRx }; 468 | } 469 | 470 | async function watchEventOnce(contractEvent) { 471 | return await new Promise((resolve, reject) => { 472 | contractEvent.watch((watchErr) => { 473 | if (watchErr) { 474 | return reject(watchErr); 475 | } 476 | 477 | return contractEvent.uninstall((stopWatchingError) => { 478 | if (stopWatchingError) { 479 | return reject(stopWatchingError); 480 | } 481 | return resolve(); 482 | }); 483 | }); 484 | }); 485 | } 486 | 487 | async function simpleStorePerformSetAndWatchOnce({ simpleStore }) { 488 | const setCompleteEvent = simpleStore.SetComplete(); // eslint-disable-line 489 | const setCompleteFilterId = await setCompleteEvent.new({ fromBlock: 'earliest', toBlock: 'latest' }); 490 | assert.ok(setCompleteFilterId); 491 | assert.equal(typeof setCompleteFilterId, 'object'); 492 | assert.equal(setCompleteFilterId.toString(10) > 0, true); 493 | 494 | const watchPromise = watchEventOnce(setCompleteEvent); 495 | const setTxHash = await simpleStore.set(1337); 496 | assert.equal(typeof setTxHash, 'string'); 497 | 498 | return { watchPromise }; 499 | } 500 | 501 | async function simpleStorePerformSetAndGet({ eth, simpleStore, setNumberValue = 42, setOpts = {} }) { 502 | const setTxHash = await simpleStore.set(setNumberValue, setOpts); 503 | assert.equal(typeof setTxHash, 'string'); 504 | 505 | const setTx = await eth.getTransactionByHash(setTxHash); 506 | assert.ok(setTx); 507 | assert.equal(typeof setTx, 'object'); 508 | const setTxReceipt = await eth.getTransactionReceipt(setTxHash); 509 | assert.equal(typeof setTxReceipt, 'object'); 510 | 511 | const getResult = await simpleStore.get(); 512 | assert.equal(typeof getResult, 'object'); 513 | assert.equal(getResult[0].toNumber(10), setNumberValue); 514 | 515 | return { setTx, setTxReceipt }; 516 | } 517 | 518 | async function deployAndTestComplexStore({ eth, newTxParams }) { 519 | const accounts = await eth.accounts(); 520 | const contract = new EthContract(eth); 521 | 522 | const defaultTxObject = { from: accounts[0], gas: 300000 }; 523 | const ComplexStore = contract(TestContracts.ComplexStore.abi, TestContracts.ComplexStore.bytecode, defaultTxObject); 524 | 525 | const initialValue = 730483222; 526 | const initialAddressArray = [accounts[3], accounts[2], accounts[1]]; 527 | 528 | let deployTxHash; 529 | if (newTxParams) { 530 | deployTxHash = await ComplexStore.new(initialValue, initialAddressArray, newTxParams); 531 | } else { 532 | deployTxHash = await ComplexStore.new(initialValue, initialAddressArray); 533 | } 534 | 535 | const deployTx = await eth.getTransactionByHash(deployTxHash); 536 | const deployTxRx = await eth.getTransactionReceipt(deployTxHash); 537 | const complexStore = ComplexStore.at(deployTxRx.contractAddress); 538 | 539 | const addressResult0 = await complexStore.addresses(0); 540 | assert.equal(addressResult0[0], initialAddressArray[0]); 541 | const addressResult1 = await complexStore.addresses(1); 542 | assert.equal(addressResult1[0], initialAddressArray[1]); 543 | const addressResult2 = await complexStore.addresses(2); 544 | assert.equal(addressResult2[0], initialAddressArray[2]); 545 | const someValue = await complexStore.someVal(); 546 | assert.equal(someValue[0].toNumber(10), initialValue); 547 | 548 | return { deployTx }; 549 | } 550 | --------------------------------------------------------------------------------