Skip to content

Commit

Permalink
[resolves trustwallet#260] test aeternity definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Defuera committed May 31, 2019
1 parent 61ef96e commit 312289f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
4 changes: 2 additions & 2 deletions coins.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@
"derivationPath": "m/44'/0'/0'/0",
"curve": "ed25519",
"publicKeyType": "ed25519",
"transactionPath": "/transaction/",
"explorer": "https://www.aeknow.org/"
"transactionPath": "/block/transaction/",
"explorer": "https://www.aeknow.org"
}
]
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWBlockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum TWBlockchain {
TWBlockchainNEO = 22,
TWBlockchainSteem = 23,
TWBlockchainNULS = 24,
TWBlockchainAeternity = 25,
};

TW_EXTERN_C_END
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TW_EXTERN_C_BEGIN
/// - SeeAlso: https://github.com/satoshilabs/slips/blob/master/slip-0044.md
TW_EXPORT_ENUM(uint32_t)
enum TWCoinType {
TWCoinTypeAeternity = 427,
TWCoinTypeAion = 425,
TWCoinTypeBinance = 714,
TWCoinTypeBitcoin = 0,
Expand Down
43 changes: 27 additions & 16 deletions src/Coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@

#include "Coin.h"

#include "ARK/Address.h"
#include "Aeternity/Address.h"
#include "Aion/Address.h"
#include "Bitcoin/Address.h"
#include "Bitcoin/SegwitAddress.h"
#include "Bitcoin/CashAddress.h"
#include "Bitcoin/SegwitAddress.h"
#include "Bravo/Address.h"
#include "Cosmos/Address.h"
#include "Decred/Address.h"
#include "EOS/Address.h"
#include "Ethereum/Address.h"
#include "Groestlcoin/Address.h"
#include "IOST/Account.h"
#include "Icon/Address.h"
#include "IoTeX/Address.h"
#include "Iocoin/Address.h"
#include "Nano/Address.h"
#include "NEO/Address.h"
#include "NULS/Address.h"
#include "Nano/Address.h"
#include "Nimiq/Address.h"
#include "Ontology/Address.h"
#include "Ripple/Address.h"
#include "Semux/Address.h"
#include "Steem/Address.h"
#include "Stellar/Address.h"
#include "Cosmos/Address.h"
#include "Tezos/Address.h"
#include "Tron/Address.h"
#include "Wanchain/Address.h"
#include "Zcash/TAddress.h"
#include "NULS/Address.h"
#include "Bravo/Address.h"
#include "Steem/Address.h"
#include "EOS/Address.h"
#include "IoTeX/Address.h"
#include "Zilliqa/Address.h"
#include "Semux/Address.h"
#include "ARK/Address.h"

#include <TrustWalletCore/TWHRP.h>
#include <TrustWalletCore/TWP2PKHPrefix.h>
Expand All @@ -45,8 +46,11 @@

using namespace TW;

bool TW::validateAddress(TWCoinType coin, const std::string& string) {
bool TW::validateAddress(TWCoinType coin, const std::string &string) {
switch (coin) {
case TWCoinTypeAeternity:
return Aeternity::Address::isValid(string);

case TWCoinTypeAion:
return Aion::Address::isValid(string);

Expand Down Expand Up @@ -82,7 +86,8 @@ bool TW::validateAddress(TWCoinType coin, const std::string& string) {

case TWCoinTypeGroestlcoin:
return Bitcoin::SegwitAddress::isValid(string, HRP_GROESTLCOIN) ||
Groestlcoin::Address::isValid(string, {TWP2PKHPrefixGroestlcoin, TWP2SHPrefixGroestlcoin});
Groestlcoin::Address::isValid(string,
{TWP2PKHPrefixGroestlcoin, TWP2SHPrefixGroestlcoin});

case TWCoinTypeIocoin:
return Bitcoin::Address::isValid(string, {{TWP2PKHPrefixIocoin}, {TWP2SHPrefixIocoin}});
Expand Down Expand Up @@ -130,7 +135,8 @@ bool TW::validateAddress(TWCoinType coin, const std::string& string) {
return Ripple::Address::isValid(string);

case TWCoinTypeSteem:
return Bravo::Address::isValid(string, { TW::Steem::MainnetPrefix, TW::Steem::TestnetPrefix });
return Bravo::Address::isValid(string,
{TW::Steem::MainnetPrefix, TW::Steem::TestnetPrefix});

case TWCoinTypeStellar:
case TWCoinTypeKin:
Expand All @@ -147,7 +153,9 @@ bool TW::validateAddress(TWCoinType coin, const std::string& string) {

case TWCoinTypeZelcash:
case TWCoinTypeZcash:
return Zcash::TAddress::isValid(string, {{Zcash::TAddress::staticPrefix, TWP2PKHPrefixZcashT}, {Zcash::TAddress::staticPrefix, TWP2SHPrefixZcashT}});
return Zcash::TAddress::isValid(string,
{{Zcash::TAddress::staticPrefix, TWP2PKHPrefixZcashT},
{Zcash::TAddress::staticPrefix, TWP2SHPrefixZcashT}});

case TWCoinTypeZilliqa:
return Zilliqa::isValidAddress(string);
Expand Down Expand Up @@ -180,13 +188,16 @@ bool TW::validateAddress(TWCoinType coin, const std::string& string) {
}
}

std::string TW::deriveAddress(TWCoinType coin, const PrivateKey& privateKey) {
std::string TW::deriveAddress(TWCoinType coin, const PrivateKey &privateKey) {
auto keyType = TW::publicKeyType(coin);
return TW::deriveAddress(coin, privateKey.getPublicKey(keyType));
}

std::string TW::deriveAddress(TWCoinType coin, const PublicKey& publicKey) {
std::string TW::deriveAddress(TWCoinType coin, const PublicKey &publicKey) {
switch (coin) {
case TWCoinTypeAeternity:
return Aeternity::Address(publicKey).string();

case TWCoinTypeBinance:
return Cosmos::Address(HRP_BINANCE, publicKey).string();

Expand Down
17 changes: 14 additions & 3 deletions tests/interface/TWCoinTypeConfigTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetSymbol) {

auto mue = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeMonetaryUnit));
assertStringsEqual(mue, "MUE");

auto ae = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeAeternity));
assertStringsEqual(ae, "AE");
}

TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetDecimals) {
Expand Down Expand Up @@ -179,6 +182,7 @@ TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetDecimals) {
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeDigiByte), 8);
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeARK), 8);
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeMonetaryUnit), 8);
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeAeternity), 18);
}

TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetTransactionURL) {
Expand Down Expand Up @@ -312,9 +316,12 @@ TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetTransactionURL) {

auto ark = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeARK, txId));
assertStringsEqual(ark, "https://explorer.ark.io/transaction/123");

auto mue = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeMonetaryUnit, txId));
assertStringsEqual(mue, "https://explorer.monetaryunit.org/tx/123");

auto ae = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeAeternity, txId));
assertStringsEqual(ae, "https://www.aeknow.org/block/transaction/123");
}

TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetID) {
Expand Down Expand Up @@ -440,9 +447,12 @@ TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetID) {

auto ark = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeARK));
assertStringsEqual(ark, "ark");

auto mue = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeMonetaryUnit));
assertStringsEqual(mue, "monetaryunit");

auto ae = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeAeternity));
assertStringsEqual(ae, "aeternity");
}

TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetName) {
Expand Down Expand Up @@ -571,7 +581,7 @@ TEST(TWCoinTypeConfiguration, TWCoinTypeConfigurationGetName) {

auto ark = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeARK));
assertStringsEqual(ark, "ARK");

auto mue = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeMonetaryUnit));
assertStringsEqual(mue, "MonetaryUnit");
}
Expand All @@ -592,4 +602,5 @@ TEST(TWCoinTypeConfiguration, TWCoinTypeBlockchain) {
ASSERT_EQ(TWBlockchainNano, TWCoinTypeBlockchain(TWCoinTypeNano));
ASSERT_EQ(TWBlockchainSemux, TWCoinTypeBlockchain(TWCoinTypeSemux));
ASSERT_EQ(TWBlockchainZilliqa, TWCoinTypeBlockchain(TWCoinTypeZilliqa));
ASSERT_EQ(TWBlockchainAeternity, TWCoinTypeBlockchain(TWCoinTypeAeternity));
}

0 comments on commit 312289f

Please sign in to comment.