From 6846db56b8dccb6d503f12ff6d6b8e7c94325868 Mon Sep 17 00:00:00 2001 From: weixuefeng Date: Tue, 31 Oct 2023 18:04:01 +0800 Subject: [PATCH] feat: add celestia like cosmos (#3510) --- .../blockchains/CoinAddressDerivationTests.kt | 1 + docs/registry.md | 1 + include/TrustWalletCore/TWCoinType.h | 1 + .../core/test/CoinAddressDerivationTests.kt | 1 + registry.json | 30 +++++++++++++++ swift/Tests/CoinAddressDerivationTests.swift | 3 ++ tests/chains/Cosmos/Tia/TWAnyAddressTests.cpp | 20 ++++++++++ tests/chains/Cosmos/Tia/TWCoinTypeTests.cpp | 37 +++++++++++++++++++ tests/common/CoinAddressDerivationTests.cpp | 3 ++ 9 files changed, 97 insertions(+) create mode 100644 tests/chains/Cosmos/Tia/TWAnyAddressTests.cpp create mode 100644 tests/chains/Cosmos/Tia/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 89f21271a53..135547a4b09 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 @@ -147,5 +147,6 @@ class CoinAddressDerivationTests { ROOTSTOCK -> assertEquals("0xA2D7065F94F838a3aB9C04D67B312056846424Df", address) SEI -> assertEquals("sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj", address) INTERNETCOMPUTER -> assertEquals("b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87", address) + TIA -> assertEquals("celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7", address) } } diff --git a/docs/registry.md b/docs/registry.md index 57cff87373f..74a8d9b829e 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -140,6 +140,7 @@ This list is generated from [./registry.json](../registry.json) | 20000118 | Stargaze | STARS | | | | 20000714 | BNB Smart Chain | BNB | | | | 20009001 | Native Evmos | EVMOS | | | +| 21000118 | Celestia | TIA | | | | 30000118 | Juno | JUNO | | | | 30000714 | TBNB | BNB | | | | 40000118 | Stride | STRD | | | diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index e993c7f1680..cd2780d8a55 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -178,6 +178,7 @@ enum TWCoinType { TWCoinTypeMantle = 5000, TWCoinTypeZenEON = 7332, TWCoinTypeInternetComputer = 223, + TWCoinTypeTia = 21000118, }; /// Returns the blockchain for a coin type. diff --git a/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt b/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt index f5966bbd65c..351e7d0aa8e 100644 --- a/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt +++ b/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt @@ -143,5 +143,6 @@ class CoinAddressDerivationTests { Rootstock -> "0xA2D7065F94F838a3aB9C04D67B312056846424Df" Sei -> "sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj" InternetComputer -> "b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87" + Tia -> "celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7" } } diff --git a/registry.json b/registry.json index 0487d8b03e6..f8dc1115bd1 100644 --- a/registry.json +++ b/registry.json @@ -1166,6 +1166,36 @@ "documentation": "https://docs.sei.io/" } }, + { + "id": "tia", + "name": "Tia", + "displayName": "Celestia", + "coinId": 21000118, + "symbol": "TIA", + "decimals": 6, + "blockchain": "Cosmos", + "chainId": "mocha-4", + "derivation": [ + { + "path": "m/44'/118'/0'/0/0" + } + ], + "curve": "secp256k1", + "publicKeyType": "secp256k1", + "hrp": "celestia", + "addressHasher": "sha256ripemd", + "explorer": { + "url": "https://www.mintscan.io/tia", + "txPath": "/txs/", + "accountPath": "/account/", + "sampleTx": "943B1A59EB724A1258CF167834A83558DE5A31E8C1E31FCBCBB99404222E5FBF", + "sampleAccount": "celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7" + }, + "info": { + "url": "https://celestia.org/", + "documentation": "https://docs.celestia.org/" + } + }, { "id": "coreum", "name": "Coreum", diff --git a/swift/Tests/CoinAddressDerivationTests.swift b/swift/Tests/CoinAddressDerivationTests.swift index 395a7a6e2ab..468aa0c5fbf 100644 --- a/swift/Tests/CoinAddressDerivationTests.swift +++ b/swift/Tests/CoinAddressDerivationTests.swift @@ -386,6 +386,9 @@ class CoinAddressDerivationTests: XCTestCase { case .internetComputer: let expectedResult = "b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87" assertCoinDerivation(coin, expectedResult, derivedAddress, address) + case .tia: + let expectedResult = "celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7" + assertCoinDerivation(coin, expectedResult, derivedAddress, address) @unknown default: fatalError() } diff --git a/tests/chains/Cosmos/Tia/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Tia/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..7a2c17bad5b --- /dev/null +++ b/tests/chains/Cosmos/Tia/TWAnyAddressTests.cpp @@ -0,0 +1,20 @@ +// 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. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gTiaAddr = "celestia1mry47pkga5tdswtluy0m8teslpalkdq00tp7xc"; +static const std::string gTiaHrp = "celestia"; + +TEST(TWTiaAnyAddress, AllTiaAddressTests) { + CosmosAddressParameters parameters{.hrp = gTiaHrp, .coinType = TWCoinTypeTia, .address = gTiaAddr}; + TestCosmosAddressParameters(parameters); +} + +} + \ No newline at end of file diff --git a/tests/chains/Cosmos/Tia/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Tia/TWCoinTypeTests.cpp new file mode 100644 index 00000000000..2a22712580a --- /dev/null +++ b/tests/chains/Cosmos/Tia/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 + +namespace TW::Cosmos::tests { + TEST(TWTiaCoinType, TWCoinType) { + const auto coin = TWCoinTypeTia; + 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("943B1A59EB724A1258CF167834A83558DE5A31E8C1E31FCBCBB99404222E5FBF")); + const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); + const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7")); + const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); + assertStringsEqual(id, "tia"); + assertStringsEqual(name, "Celestia"); + assertStringsEqual(symbol, "TIA"); + ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 6); + ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainCosmos); + ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0); + ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0); + assertStringsEqual(chainId, "mocha-4"); + assertStringsEqual(txUrl, "https://www.mintscan.io/tia/txs/943B1A59EB724A1258CF167834A83558DE5A31E8C1E31FCBCBB99404222E5FBF"); + assertStringsEqual(accUrl, "https://www.mintscan.io/tia/account/celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7"); + } +} diff --git a/tests/common/CoinAddressDerivationTests.cpp b/tests/common/CoinAddressDerivationTests.cpp index 233e4962907..d9a8736b834 100644 --- a/tests/common/CoinAddressDerivationTests.cpp +++ b/tests/common/CoinAddressDerivationTests.cpp @@ -381,6 +381,9 @@ TEST(Coin, DeriveAddress) { case TWCoinTypeInternetComputer: EXPECT_EQ(address, "cb3aa6a0471a417fc33d8e71f1d241750dfa29b4dc8f084265ce1301fb03b65b"); break; + case TWCoinTypeTia: + EXPECT_EQ(address, "celestia1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z0g3wnkv"); + break; // no default branch here, intentionally, to better notice any missing coins } }