From dea4df6c676c19ef34e078a9ed00e351877604ad Mon Sep 17 00:00:00 2001 From: beckkles <34546339+beckkles@users.noreply.github.com> Date: Tue, 17 Sep 2019 13:42:23 -0400 Subject: [PATCH 1/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2f3e86d..0d29004 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Core interface definitions and default implementations for uPort kotlin SDK classes. +[FAQ and helpdesk support](http://bit.ly/uPort_helpdesk) + ## Modules ### core From 5f53af30bbbb1ba2745eb817bf35128abb9ad058 Mon Sep 17 00:00:00 2001 From: Ugo Amanoh Date: Fri, 13 Dec 2019 14:30:10 +0100 Subject: [PATCH 2/8] refactor: added new fun to register default networks using infura --- README.md | 3 +++ core/src/main/java/me/uport/sdk/core/Networks.kt | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0d29004..d081341 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ Networks.registerNetwork( ) ) +//register all defaults using infura +Networks.registerAllNetworksWithInfura("") + //use testnet val net = Networks.get("0x1234") diff --git a/core/src/main/java/me/uport/sdk/core/Networks.kt b/core/src/main/java/me/uport/sdk/core/Networks.kt index 8bc0ab7..1873faf 100644 --- a/core/src/main/java/me/uport/sdk/core/Networks.kt +++ b/core/src/main/java/me/uport/sdk/core/Networks.kt @@ -23,11 +23,15 @@ object Networks { private val NETWORK_CONFIG = emptyMap().toMutableMap() init { + registerAllNetworksWithInfura("e72b472993ff46d3b5b88faa47214d7f") + } + + fun registerAllNetworksWithInfura(infuraId: String) { registerNetwork( EthNetwork( name = "mainnet", networkId = mainnetId, - rpcUrl = "https://mainnet.infura.io/v3/e72b472993ff46d3b5b88faa47214d7f", + rpcUrl = "https://mainnet.infura.io/v3/${infuraId}", ethrDidRegistry = DEFAULT_ERC1056_REGISTRY, explorerUrl = "https://etherscan.io", // MNID.encode(mainnetId, "0xab5c8051b9a1df1aab0149f8b0630848b7ecabf6"), @@ -41,7 +45,7 @@ object Networks { EthNetwork( name = "rinkeby", networkId = rinkebyId, - rpcUrl = "https://rinkeby.infura.io/v3/e72b472993ff46d3b5b88faa47214d7f", + rpcUrl = "https://rinkeby.infura.io/v3/${infuraId}", ethrDidRegistry = DEFAULT_ERC1056_REGISTRY, explorerUrl = "https://rinkeby.etherscan.io", //MNID.encode(rinkebyId, "0x2cc31912b2b0f3075a87b3640923d45a26cef3ee"), @@ -55,7 +59,7 @@ object Networks { EthNetwork( name = "ropsten", networkId = ropstenId, - rpcUrl = "https://ropsten.infura.io/v3/e72b472993ff46d3b5b88faa47214d7f", + rpcUrl = "https://ropsten.infura.io/v3/${infuraId}", ethrDidRegistry = DEFAULT_ERC1056_REGISTRY, explorerUrl = "https://ropsten.etherscan.io", //MNID.encode(ropstenId, "0x41566e3a081f5032bdcad470adb797635ddfe1f0"), @@ -69,7 +73,7 @@ object Networks { EthNetwork( name = "kovan", networkId = kovanId, - rpcUrl = "https://kovan.infura.io/v3/e72b472993ff46d3b5b88faa47214d7f", + rpcUrl = "https://kovan.infura.io/v3/${infuraId}", ethrDidRegistry = DEFAULT_ERC1056_REGISTRY, explorerUrl = "https://kovan.etherscan.io", //MNID.encode(kovanId, "0x5f8e9351dc2d238fb878b6ae43aa740d62fc9758"), From a065e1db76de9b517566de01de3edee892722e58 Mon Sep 17 00:00:00 2001 From: Ugo Amanoh Date: Tue, 17 Dec 2019 11:48:30 +0100 Subject: [PATCH 3/8] feat: adding the functionality to search for a network using it's name --- .../main/java/me/uport/sdk/core/Networks.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/me/uport/sdk/core/Networks.kt b/core/src/main/java/me/uport/sdk/core/Networks.kt index 1873faf..b4d067c 100644 --- a/core/src/main/java/me/uport/sdk/core/Networks.kt +++ b/core/src/main/java/me/uport/sdk/core/Networks.kt @@ -121,13 +121,26 @@ object Networks { } /** - * Gets an [EthNetwork] based on a [networkId] + * Gets an [EthNetwork] based on a [networkId] or [name] */ - fun get(networkId: String): EthNetwork { - val cleanNetId = cleanId(networkId) + fun get(nameOrId: String): EthNetwork { + val cleanNetId = cleanId(nameOrId) return NETWORK_CONFIG[cleanNetId] - ?: NETWORK_CONFIG[networkId] - ?: throw IllegalStateException("network [$networkId] not configured") + ?: NETWORK_CONFIG[nameOrId] + ?: getNetworkByName(nameOrId) + ?: throw IllegalStateException("network [$nameOrId] not configured") + } + + /** + * Searches for an [EthNetwork] based on a [name] + */ + private fun getNetworkByName(name: String): EthNetwork? { + for ((_, value) in NETWORK_CONFIG) { + if (value.name === name) { + return value + } + } + return null } private fun cleanId(id: String) = id.clean0xPrefix().trimStart('0').prepend0xPrefix() From c15b516dd403df4372cc8b598a50ceac58f2e752 Mon Sep 17 00:00:00 2001 From: Ugo Amanoh Date: Tue, 17 Dec 2019 11:55:49 +0100 Subject: [PATCH 4/8] test: added tests for finding a network using its name --- .../java/me/uport/sdk/core/NetworksTest.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/core/src/test/java/me/uport/sdk/core/NetworksTest.kt b/core/src/test/java/me/uport/sdk/core/NetworksTest.kt index a75e79a..f2c7b02 100644 --- a/core/src/test/java/me/uport/sdk/core/NetworksTest.kt +++ b/core/src/test/java/me/uport/sdk/core/NetworksTest.kt @@ -39,6 +39,36 @@ class NetworksTest { .isEqualTo(Networks.mainnet.ethrDidRegistry) } + @Test + fun `can find a registered network using the name`() { + + assertThat(Networks.get("mainnet")).isEqualTo(Networks.mainnet) + + assertThat(Networks.get("rinkeby")).isEqualTo(Networks.rinkeby) + + assertThat(Networks.get("kovan")).isEqualTo(Networks.kovan) + + assertThat(Networks.get("ropsten")).isEqualTo(Networks.ropsten) + } + + @Test + fun `throws error if the network name does not match`() { + assertThat { + Networks.get("manet") + }.thrownError { + isInstanceOf(IllegalStateException::class) + } + } + + @Test + fun `throws error if the network name cases does not match`() { + assertThat { + Networks.get("Mainnet") + }.thrownError { + isInstanceOf(IllegalStateException::class) + } + } + @Test fun `getting an unknown network throws`() { assertThat { From 0388ef40af4ec24b177b3a3b1aeed523506c0cc0 Mon Sep 17 00:00:00 2001 From: Ugo Amanoh Date: Tue, 17 Dec 2019 13:21:36 +0100 Subject: [PATCH 5/8] refactor: remove case-sensitivity during network name search --- core/src/main/java/me/uport/sdk/core/Networks.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/me/uport/sdk/core/Networks.kt b/core/src/main/java/me/uport/sdk/core/Networks.kt index b4d067c..a2f2c2d 100644 --- a/core/src/main/java/me/uport/sdk/core/Networks.kt +++ b/core/src/main/java/me/uport/sdk/core/Networks.kt @@ -136,7 +136,7 @@ object Networks { */ private fun getNetworkByName(name: String): EthNetwork? { for ((_, value) in NETWORK_CONFIG) { - if (value.name === name) { + if (value.name.toLowerCase() === name.toLowerCase()) { return value } } From 7ff682dcb585abb3e37a61a80c352f30e6f5120a Mon Sep 17 00:00:00 2001 From: Ugo Amanoh Date: Tue, 17 Dec 2019 13:28:13 +0100 Subject: [PATCH 6/8] test: added test to show network name case-insensitive search --- core/src/main/java/me/uport/sdk/core/Networks.kt | 2 +- .../test/java/me/uport/sdk/core/NetworksTest.kt | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/me/uport/sdk/core/Networks.kt b/core/src/main/java/me/uport/sdk/core/Networks.kt index a2f2c2d..78b2b3b 100644 --- a/core/src/main/java/me/uport/sdk/core/Networks.kt +++ b/core/src/main/java/me/uport/sdk/core/Networks.kt @@ -136,7 +136,7 @@ object Networks { */ private fun getNetworkByName(name: String): EthNetwork? { for ((_, value) in NETWORK_CONFIG) { - if (value.name.toLowerCase() === name.toLowerCase()) { + if (value.name.toLowerCase() == name.toLowerCase()) { return value } } diff --git a/core/src/test/java/me/uport/sdk/core/NetworksTest.kt b/core/src/test/java/me/uport/sdk/core/NetworksTest.kt index f2c7b02..ba9307d 100644 --- a/core/src/test/java/me/uport/sdk/core/NetworksTest.kt +++ b/core/src/test/java/me/uport/sdk/core/NetworksTest.kt @@ -52,18 +52,14 @@ class NetworksTest { } @Test - fun `throws error if the network name does not match`() { - assertThat { - Networks.get("manet") - }.thrownError { - isInstanceOf(IllegalStateException::class) - } + fun `can find a registered network using the different case name`() { + assertThat(Networks.get("MainNet")).isEqualTo(Networks.mainnet) } - @Test - fun `throws error if the network name cases does not match`() { + @Test + fun `throws error if the network name does not match`() { assertThat { - Networks.get("Mainnet") + Networks.get("manet") }.thrownError { isInstanceOf(IllegalStateException::class) } From 36c4831bd7553c7601673545f946d6e38929028d Mon Sep 17 00:00:00 2001 From: Ugo Amanoh Date: Tue, 17 Dec 2019 13:57:02 +0100 Subject: [PATCH 7/8] refactor: use find as opposed to forEach to search a map --- core/src/main/java/me/uport/sdk/core/Networks.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/me/uport/sdk/core/Networks.kt b/core/src/main/java/me/uport/sdk/core/Networks.kt index 78b2b3b..1fa9877 100644 --- a/core/src/main/java/me/uport/sdk/core/Networks.kt +++ b/core/src/main/java/me/uport/sdk/core/Networks.kt @@ -135,12 +135,8 @@ object Networks { * Searches for an [EthNetwork] based on a [name] */ private fun getNetworkByName(name: String): EthNetwork? { - for ((_, value) in NETWORK_CONFIG) { - if (value.name.toLowerCase() == name.toLowerCase()) { - return value - } - } - return null + val queryName = name.toLowerCase() + return NETWORK_CONFIG.values.find { it.name.toLowerCase() == queryName } } private fun cleanId(id: String) = id.clean0xPrefix().trimStart('0').prepend0xPrefix() From aa20d7535098cbad9d37e1c22fb9cbf7dc242726 Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Tue, 17 Dec 2019 14:29:21 +0100 Subject: [PATCH 8/8] docs: release notes for version 0.4.0 --- CHANGELOG.md | 4 ++++ README.md | 8 ++++---- build.gradle | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f939207..b594e84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +* 0.4.0 + * feat - easy configuration with infuraProjectID ( #8 ) + * feat - find networks by name after configuration ( #9 ) + * 0.3.2 * build - bump kethereum to 0.76.2 ( 61d7582d ) diff --git a/README.md b/README.md index 98f8f1a..3fac1e0 100644 --- a/README.md +++ b/README.md @@ -32,18 +32,18 @@ Networks.registerNetwork( ) ) -//register all defaults using infura +//register all popular public networks using your infura project ID Networks.registerAllNetworksWithInfura("") //use testnet val net = Networks.get("0x1234") - +or +val net = Networks.get("local") // override defaults Networks.registerNetwork( Networks.mainnet.copy(rpcUrl = "http://localhost:8545") ) - assertTrue(Networks.mainnet.rpcUrl == "http://localhost:8545") ``` @@ -92,7 +92,7 @@ allprojects { In your module `build.gradle` file, add: ```groovy -def uport_kotlin_common_version = "0.3.2" +def uport_kotlin_common_version = "0.4.0" dependencies { //... // core lib diff --git a/build.gradle b/build.gradle index e1ed434..54f7701 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { kethereum_version = "0.76.2" khex_version = "1.0.0-RC3" - current_release_version = "0.3.2" + current_release_version = "0.4.0" } repositories {