Skip to content

Commit

Permalink
feat: add celestia like cosmos (#3510)
Browse files Browse the repository at this point in the history
  • Loading branch information
weixuefeng authored Oct 31, 2023
1 parent 6a93cb8 commit 6846db5
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ class CoinAddressDerivationTests {
ROOTSTOCK -> assertEquals("0xA2D7065F94F838a3aB9C04D67B312056846424Df", address)
SEI -> assertEquals("sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj", address)
INTERNETCOMPUTER -> assertEquals("b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87", address)
TIA -> assertEquals("celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7", address)
}
}
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ This list is generated from [./registry.json](../registry.json)
| 20000118 | Stargaze | STARS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/stargaze/info/logo.png" width="32" /> | <https://www.stargaze.zone/> |
| 20000714 | BNB Smart Chain | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/info/logo.png" width="32" /> | <https://www.binance.org/en/smartChain> |
| 20009001 | Native Evmos | EVMOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nativeevmos/info/logo.png" width="32" /> | <https://evmos.org/> |
| 21000118 | Celestia | TIA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tia/info/logo.png" width="32" /> | <https://celestia.org/> |
| 30000118 | Juno | JUNO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/juno/info/logo.png" width="32" /> | <https://www.junonetwork.io/> |
| 30000714 | TBNB | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tbinance/info/logo.png" width="32" /> | <https://www.bnbchain.org> |
| 40000118 | Stride | STRD | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/stride/info/logo.png" width="32" /> | <https://stride.zone/> |
Expand Down
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ enum TWCoinType {
TWCoinTypeMantle = 5000,
TWCoinTypeZenEON = 7332,
TWCoinTypeInternetComputer = 223,
TWCoinTypeTia = 21000118,
};

/// Returns the blockchain for a coin type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ class CoinAddressDerivationTests {
Rootstock -> "0xA2D7065F94F838a3aB9C04D67B312056846424Df"
Sei -> "sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj"
InternetComputer -> "b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87"
Tia -> "celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7"
}
}
30 changes: 30 additions & 0 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions swift/Tests/CoinAddressDerivationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
20 changes: 20 additions & 0 deletions tests/chains/Cosmos/Tia/TWAnyAddressTests.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

}

37 changes: 37 additions & 0 deletions tests/chains/Cosmos/Tia/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
@@ -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 <TrustWalletCore/TWCoinTypeConfiguration.h>
#include <gtest/gtest.h>

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");
}
}
3 changes: 3 additions & 0 deletions tests/common/CoinAddressDerivationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 6846db5

Please sign in to comment.