From 2b289fa80f56a076535214b88306696360580f5f Mon Sep 17 00:00:00 2001 From: Ahsan Javaid <104683677+ahsan-javaiid@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:08:40 +0500 Subject: [PATCH] Add rootstock chain (#3205) --- .../blockchains/CoinAddressDerivationTests.kt | 1 + docs/registry.md | 1 + include/TrustWalletCore/TWCoinType.h | 1 + registry.json | 30 +++++++++++++++ swift/Tests/CoinAddressDerivationTests.swift | 3 ++ tests/chains/Rootstock/TWCoinTypeTests.cpp | 37 +++++++++++++++++++ tests/common/CoinAddressDerivationTests.cpp | 3 ++ 7 files changed, 76 insertions(+) create mode 100644 tests/chains/Rootstock/TWCoinTypeTests.cpp diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt index f53e8ce190f..4875d089244 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt @@ -132,5 +132,6 @@ class CoinAddressDerivationTests { PERSISTENCE -> assertEquals("persistence142j9u5eaduzd7faumygud6ruhdwme98q7gv2ch", address) AKASH -> assertEquals("akash142j9u5eaduzd7faumygud6ruhdwme98qal870f", address) NOBLE -> assertEquals("noble142j9u5eaduzd7faumygud6ruhdwme98qc8l3wa", address) + ROOTSTOCK -> assertEquals("0xA2D7065F94F838a3aB9C04D67B312056846424Df", address) } } diff --git a/docs/registry.md b/docs/registry.md index cccda5dde41..42744680e18 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -19,6 +19,7 @@ This list is generated from [./registry.json](../registry.json) | 118 | Cosmos Hub | ATOM | | | | 133 | Zcash | ZEC | | | | 136 | Firo | FIRO | | | +| 137 | Rootstock | RBTC | | | | 144 | XRP | XRP | | | | 145 | Bitcoin Cash | BCH | | | | 148 | Stellar | XLM | | | diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index 42248fe75e3..3ab5166d70b 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -152,6 +152,7 @@ enum TWCoinType { TWCoinTypeAkash = 17000118, TWCoinTypeNoble = 18000118, TWCoinTypeScroll = 534353, + TWCoinTypeRootstock = 137, }; /// Returns the blockchain for a coin type. diff --git a/registry.json b/registry.json index 123c3e77701..3f718065e6a 100644 --- a/registry.json +++ b/registry.json @@ -2599,6 +2599,36 @@ "documentation": "https://eth.wiki/json-rpc/API" } }, + { + "id": "rootstock", + "name": "Rootstock", + "coinId": 137, + "symbol": "RBTC", + "decimals": 18, + "blockchain": "Ethereum", + "derivation": [ + { + "path": "m/44'/137'/0'/0/0" + } + ], + "curve": "secp256k1", + "publicKeyType": "secp256k1Extended", + "chainId": "30", + "addressHasher": "keccak256", + "explorer": { + "url": "https://explorer.rsk.co", + "txPath": "/tx/", + "accountPath": "/address/", + "sampleTx": "0xeb8fa0488a655f8dc975153bffd066800bcaae5f21cf372356365b2a1d6d2288", + "sampleAccount": "0x4e5dabc28e4a0f5e5b19fcb56b28c5a1989352c1" + }, + "info": { + "url": "https://rootstock.io", + "source": "https://github.com/rsksmart/rskj", + "rpc": "https://public-node.rsk.co", + "documentation": "https://dev.rootstock.io" + } + }, { "id": "thorchain", "name": "THORChain", diff --git a/swift/Tests/CoinAddressDerivationTests.swift b/swift/Tests/CoinAddressDerivationTests.swift index 48604cbfdc7..1472f49f55f 100644 --- a/swift/Tests/CoinAddressDerivationTests.swift +++ b/swift/Tests/CoinAddressDerivationTests.swift @@ -104,6 +104,9 @@ class CoinAddressDerivationTests: XCTestCase { case .ethereumClassic: let expectedResult = "0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c" assertCoinDerivation(coin, expectedResult, derivedAddress, address) + case .rootstock: + let expectedResult = "0xA2D7065F94F838a3aB9C04D67B312056846424Df" + assertCoinDerivation(coin, expectedResult, derivedAddress, address) case .filecoin: let expectedResult = "f1zzykebxldfcakj5wdb5n3n7priul522fnmjzori" assertCoinDerivation(coin, expectedResult, derivedAddress, address) diff --git a/tests/chains/Rootstock/TWCoinTypeTests.cpp b/tests/chains/Rootstock/TWCoinTypeTests.cpp new file mode 100644 index 00000000000..adf559b3644 --- /dev/null +++ b/tests/chains/Rootstock/TWCoinTypeTests.cpp @@ -0,0 +1,37 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. +// +// This is a GENERATED FILE, changes made here MAY BE LOST. +// Generated one-time (codegen/bin/cointests) +// + +#include "TestUtilities.h" +#include +#include + + +TEST(TWRootstockCoinType, TWCoinType) { + const auto coin = TWCoinTypeRootstock; + const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin)); + const auto id = WRAPS(TWCoinTypeConfigurationGetID(coin)); + const auto name = WRAPS(TWCoinTypeConfigurationGetName(coin)); + const auto chainId = WRAPS(TWCoinTypeChainId(coin)); + const auto txId = WRAPS(TWStringCreateWithUTF8Bytes("0xeb8fa0488a655f8dc975153bffd066800bcaae5f21cf372356365b2a1d6d2288")); + const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); + const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("0x4e5dabc28e4a0f5e5b19fcb56b28c5a1989352c1")); + const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); + + assertStringsEqual(id, "rootstock"); + assertStringsEqual(name, "Rootstock"); + assertStringsEqual(symbol, "RBTC"); + ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 18); + ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainEthereum); + ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0); + ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0); + assertStringsEqual(chainId, "30"); + assertStringsEqual(txUrl, "https://explorer.rsk.co/tx/0xeb8fa0488a655f8dc975153bffd066800bcaae5f21cf372356365b2a1d6d2288"); + assertStringsEqual(accUrl, "https://explorer.rsk.co/address/0x4e5dabc28e4a0f5e5b19fcb56b28c5a1989352c1"); +} diff --git a/tests/common/CoinAddressDerivationTests.cpp b/tests/common/CoinAddressDerivationTests.cpp index 0beeb993b32..16b97a655ad 100644 --- a/tests/common/CoinAddressDerivationTests.cpp +++ b/tests/common/CoinAddressDerivationTests.cpp @@ -328,6 +328,9 @@ TEST(Coin, DeriveAddress) { case TWCoinTypeNoble: EXPECT_EQ(address, "noble1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z03c2t50"); break; + case TWCoinTypeRootstock: + EXPECT_EQ(address, "0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F"); + break; // no default branch here, intentionally, to better notice any missing coins } }