From 883522565579df6e2a49e268d3643f3b21f1f783 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 3 Nov 2017 01:30:56 -0500 Subject: [PATCH 1/5] Updated getTransactionReceipt for Byzantium. --- providers/package.json | 2 +- providers/provider.js | 29 ++++++- tests/test-providers.js | 164 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 185 insertions(+), 10 deletions(-) diff --git a/providers/package.json b/providers/package.json index ca7618f0..3831d535 100644 --- a/providers/package.json +++ b/providers/package.json @@ -1,6 +1,6 @@ { "name": "ethers-providers", - "version": "2.1.5", + "version": "2.1.6", "description": "Service provider for Ethereum wallet library.", "bugs": { "url": "http://github.com/ethers-io/ethers.js/issues", diff --git a/providers/provider.js b/providers/provider.js index 0ca489d0..96f567da 100644 --- a/providers/provider.js +++ b/providers/provider.js @@ -260,11 +260,13 @@ function checkTransactionRequest(transaction) { } var formatTransactionReceiptLog = { - transactionLogIndex: checkNumber, + transactionLogIndex: allowNull(checkNumber), + transactionIndex: checkNumber, blockNumber: checkNumber, transactionHash: checkHash, address: utils.getAddress, - type: checkString, + // @TODO: Next major release remove this + type: allowNull(checkString), topics: arrayOf(checkHash), transactionIndex: checkNumber, data: utils.hexlify, @@ -279,7 +281,7 @@ function checkTransactionReceiptLog(log) { var formatTransactionReceipt = { contractAddress: allowNull(utils.getAddress, null), transactionIndex: checkNumber, - root: checkHash, + root: allowNull(checkHash), gasUsed: utils.bigNumberify, logsBloom: utils.hexlify, blockHash: checkHash, @@ -287,10 +289,29 @@ var formatTransactionReceipt = { logs: arrayOf(checkTransactionReceiptLog), blockNumber: checkNumber, cumulativeGasUsed: utils.bigNumberify, + status: allowNull(checkNumber) }; function checkTransactionReceipt(transactionReceipt) { - return check(formatTransactionReceipt, transactionReceipt); + var status = transactionReceipt.status; + var root = transactionReceipt.root; + if (!((status != null) ^ (root != null))) { + throw new Error('invalid transaction receipt - exactly one of status and root should be present'); + } + var result = check(formatTransactionReceipt, transactionReceipt); + result.logs.forEach(function(entry, index) { + if (entry.transactionLogIndex == null) { + entry.transactionLogIndex = index; + } + // @TODO: Remove this is next major version + if (entry.type == null) { + entry.type = 'mined'; + } + }); + if (transactionReceipt.status != null) { + result.byzantium = true; + } + return result; } function checkTopics(topics) { diff --git a/tests/test-providers.js b/tests/test-providers.js index 4b6b61dc..04ae6d01 100644 --- a/tests/test-providers.js +++ b/tests/test-providers.js @@ -24,6 +24,70 @@ var blockchainData = { extraData: '0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34', transactions: [] }, + transactionReceipt: { + blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566", + blockNumber: 0x3c92b5, + contractAddress: null, + cumulativeGasUsed: 0x1cca2e, + gasUsed:0x14bb7, + logs: [ + { + address: "0x314159265dD8dbb310642f98f50C066173C1259b", + blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566", + blockNumber: 0x3c92b5, + data: "0x00000000000000000000000018c6045651826824febbd39d8560584078d1b247", + logIndex: 0x1a, + topics: [ "0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82", "0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae", "0xf0106919d12469348e14ad6a051d0656227e1aba2fefed41737fdf78421b20e1" ], + transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616", + transactionIndex: 0x39, + transactionLogIndex: 0x0, + type:"mined" + }, + { + address: "0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef", + blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566", + blockNumber: 0x3c92b5, + data: "0x000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000595a32ce", + logIndex: 0x1b, + topics: [ "0x0f0c27adfd84b60b6f456b0e87cdccb1e5fb9603991588d87fa99f5b6b61e670", "0xf0106919d12469348e14ad6a051d0656227e1aba2fefed41737fdf78421b20e1", "0x00000000000000000000000018c6045651826824febbd39d8560584078d1b247"], + transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616", + transactionIndex: 0x39, + transactionLogIndex: 0x1, + type: "mined" + } + ], + "logsBloom": "0x00000000000000040000000000100000010000000000000040000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000200000010000000004000000000000000000000000000000000002000000000000000000000000400000000020000000000000000000000000000000000000004000000000000000000000000000000000000000000000000801000000000000000000000020000000000040000000040000000000000000002000000004000000000000000000000000000000000000000000000010000000000000000000000000000000000200000000000000000", + "root": "0x9b550a9a640ce50331b64504ef87aaa7e2aaf97344acb6ff111f879b319d2590", + "status": null, + "transactionHash": "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616", + "transactionIndex": 0x39 + }, + transactionReceiptByzantium: { + byzantium: true, + blockHash: "0x34e5a6cfbdbb84f7625df1de69d218ade4da72f4a2558064a156674e72e976c9", + blockNumber: 0x444f76, + contractAddress: null, + cumulativeGasUsed: 0x15bfe7, + gasUsed: 0x1b968, + logs: [ + { + address: "0xb90E64082D00437e65A76d4c8187596BC213480a", + blockHash: "0x34e5a6cfbdbb84f7625df1de69d218ade4da72f4a2558064a156674e72e976c9", + blockNumber: 0x444f76, + data: "0x", + logIndex: 0x10, + topics: [ "0x748d071d1992ee1bfe7a39058114d0a50d5798fe8eb3a9bfb4687f024629a2ce", "0x5574aa58f7191ccab6de6cf75fe2ea0484f010b852fdd8c6b7ae151d6c2f4b83" ], + transactionHash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac", + transactionIndex: 0x1e, + transactionLogIndex: 0x0, + type:"mined" + } + ], + logsBloom: "0x00000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000200000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000800000000000000000800000000000000000000000000000000000000", + status:1, + transactionHash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac", + transactionIndex: 0x1e + } }, kovan: { balance: { @@ -80,21 +144,88 @@ var blockchainData = { extraData: '0xd883010503846765746887676f312e372e318664617277696e', transactions: [] }, + transactionReceipt: { + blockHash: "0xc9235b8253fce455942147aa8b450d23081b867ffbb2a1e4dec934827cd80f8f", + blockNumber: 0x1564d8, + contractAddress: null, + cumulativeGasUsed: bigNumberify("0x80b9"), + gasUsed: bigNumberify("0x80b9"), + logs: [ + { + address: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c", + blockHash: "0xc9235b8253fce455942147aa8b450d23081b867ffbb2a1e4dec934827cd80f8f", + blockNumber: 0x1564d8, + data: "0x00000000000000000000000006b5955a67d827cdf91823e3bb8f069e6c89c1d6000000000000000000000000000000000000000000000000016345785d8a0000", + logIndex: 0x0, + topics:[ "0xac375770417e1cb46c89436efcf586a74d0298fee9838f66a38d40c65959ffda" ], + transactionHash: "0x55c477790b105e69e98afadf0505cbda606414b0187356137132bf24945016ce", + transactionIndex: 0x0, + transactionLogIndex: 0x0, + type: "mined" + } + ], + logsBloom: "0x00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000010000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + root: "0xf1c3506ab619ac1b5e8f1ca355b16d6b9a1b7436b2960b0e9ec9a91f4238b5cc", + transactionHash: "0x55c477790b105e69e98afadf0505cbda606414b0187356137132bf24945016ce", + transactionIndex: 0x0 + }, + transactionReceiptByzantium: { + byzantium: true, + blockHash: "0x61d343e0e081b60ac53bab381e07bdd5d0815b204091a576fd05106b814e7e1e", + blockNumber: 0x1e1e3b, + contractAddress: null, + cumulativeGasUsed: bigNumberify("0x4142f"), + gasUsed: bigNumberify("0x1eb6d"), + logs:[ + { + address: "0xCBf1735Aad8C4B337903cD44b419eFE6538aaB40", + blockHash: "0x61d343e0e081b60ac53bab381e07bdd5d0815b204091a576fd05106b814e7e1e", + blockNumber: 0x1e1e3b, + data: "0x000000000000000000000000b70560a43a9abf6ea2016f40a3e84b8821e134c5f6c95607c490f4f379c0160ef5c8898770f8a52959abf0e9de914647b377fa290000000000000000000000000000000000000000000000000000000000001c20000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000355524c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c6a736f6e2868747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d455448555344292e726573756c742e584554485a5553442e632e300000000000000000000000000000000000000000", + logIndex: 0x1, + topics: [ "0xb76d0edd90c6a07aa3ff7a222d7f5933e29c6acc660c059c97837f05c4ca1a84" ], + transactionHash: "0xf724f1d6813f13fb523c5f6af6261d06d41138dd094fff723e09fb0f893f03e6", + transactionIndex: 0x2, + transactionLogIndex: 0x0, + type: "mined" + } + ], + logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000080000000202000000", + status: 1, + transactionHash: "0xf724f1d6813f13fb523c5f6af6261d06d41138dd094fff723e09fb0f893f03e6", + transactionIndex: 0x2 + }, }, } function equals(name, actual, expected) { - if (expected.eq) { + if (expected && expected.eq) { + if (actual == null) { assert.ok(false, name + ' - actual big number null'); } assert.ok(expected.eq(actual), name + ' matches'); } else if (Array.isArray(expected)) { + if (actual == null) { assert.ok(false, name + ' - actual array null'); } assert.equal(actual.length, expected.length, name + ' array lengths match'); for (var i = 0; i < expected.length; i++) { - equals(name + ' item ' + i, actual[i], expected[i]); + equals(name + ' - item ' + i, actual[i], expected[i]); + } + } else if (typeof(expected) === 'object') { + if (actual == null) { + if (expected === actual) { return; } + assert.ok(false, name + ' - actual object null'); } + var keys = {}; + Object.keys(expected).forEach(function(key) { keys[key] = true; }); + Object.keys(actual).forEach(function(key) { keys[key] = true; }); + + Object.keys(keys).forEach(function(key) { + equals(name + ' - key + ' + key, actual[key], expected[key]); + }); + } else { - assert.equal(actual, expected, name + ' matches'); + if (actual == null) { assert.ok(false, name + ' - actual null'); } + assert.equal(actual, expected, name + ' matches'); } } @@ -121,13 +252,37 @@ function testProvider(providerName, networkName) { // assert(_owner.send(this.balance - 0.0000314159 ether)); // } // } - this.timeout(20000); + this.timeout(100000); var test = blockchainData[networkName].balance; return provider.getBalance(test.address).then(function(balance) { equals('Balance', test.balance, balance); }); }); + function testTransactionReceipt(expected) { + var title = ('Receipt ' + expected.transactionHash.substring(0, 10) + ' - '); + return provider.getTransactionReceipt(expected.transactionHash).then(function(receipt) { + for (var key in receipt) { + equals((title + key), receipt[key], expected[key]); + } + //equals(('Receipt ' + expected.transactionHash.substring(0, 10)), receipt, expected); + }); + } + + if (blockchainData[networkName].transactionReceipt) { + it('fetches pre-Byzantium transaction receipt', function() { + this.timeout(100000); + return testTransactionReceipt(blockchainData[networkName].transactionReceipt); + }); + } + + if (blockchainData[networkName].transactionReceiptByzantium) { + it('fetches Byzantium transaction receipt', function() { + this.timeout(20000); + return testTransactionReceipt(blockchainData[networkName].transactionReceiptByzantium); + }); + } + // Obviously many more cases to add here // - getTransactionCount // - getCode @@ -137,7 +292,6 @@ function testProvider(providerName, networkName) { // - estimateGas // - sendTransaction // - getTransaction - // - getTransactionReceipt // - call // - getLogs // From 9cac6b06f5f6a09c43644391acd7e80fc670cfd4 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 3 Nov 2017 01:34:57 -0500 Subject: [PATCH 2/5] Updated list of networks (legacy provider list). --- providers/provider.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/providers/provider.js b/providers/provider.js index 958cc76e..64ff8dc4 100644 --- a/providers/provider.js +++ b/providers/provider.js @@ -512,10 +512,13 @@ utils.defineProperty(Provider, '_legacyConstructor', function(network, length, a return network; }); +// @TODO: Remove in next major version (use networks instead) utils.defineProperty(Provider, 'chainId', { homestead: 1, morden: 2, ropsten: 3, + rinkeby: 4, + kovan: 42 }); //utils.defineProperty(Provider, 'isProvider', function(object) { From 18cd678b71ff3a1dd923f59141f08a5d8ecaa5e5 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 3 Nov 2017 02:41:41 -0500 Subject: [PATCH 3/5] Version bump (patch) for providers. --- providers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/package.json b/providers/package.json index 3831d535..d231855d 100644 --- a/providers/package.json +++ b/providers/package.json @@ -1,6 +1,6 @@ { "name": "ethers-providers", - "version": "2.1.6", + "version": "2.1.7", "description": "Service provider for Ethereum wallet library.", "bugs": { "url": "http://github.com/ethers-io/ethers.js/issues", From 21c6fdce3a98a2afed1bd5d2007f972d27f91b90 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 3 Nov 2017 14:53:11 -0500 Subject: [PATCH 4/5] Creating license file in GitHub UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently GitHub doesn’t recognize license.txt, so adding license. --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..2c58757c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Richard Moore + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From e8bb624560127ee13f537a71fad49245131b376d Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sat, 4 Nov 2017 02:03:41 -0500 Subject: [PATCH 5/5] Adding default code of conduct Adding the default code of conduct document. --- CODE_OF_CONDUCT.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..2df30bfe --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@ethers.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/