Skip to content

Commit

Permalink
Feature/support dogecoin (#116)
Browse files Browse the repository at this point in the history
* add dogecoin testnet & mainnet

* add dogecoin extend public key tests

* fix: fix derive dogecoin unsupported_chain error

---------

Co-authored-by: xiaoguang <xiaoguang101010@163.com>
  • Loading branch information
tyrone98 and xiaoguang1010 authored Aug 15, 2024
1 parent 3fbf1da commit 4039e2f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
4 changes: 2 additions & 2 deletions token-core/tcx-btc-kin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub enum Error {
}

pub mod bitcoin {
use crate::{BITCOIN, LITECOIN};
pub const CHAINS: [&str; 2] = [BITCOIN, LITECOIN];
use crate::{BITCOIN, DOGECOIN, LITECOIN};
pub const CHAINS: [&str; 3] = [BITCOIN, LITECOIN, DOGECOIN];
pub type Address = crate::BtcKinAddress;
pub type TransactionInput = crate::transaction::BtcKinTxInput;
pub type TransactionOutput = crate::transaction::BtcKinTxOutput;
Expand Down
56 changes: 56 additions & 0 deletions token-core/tcx-constants/src/coin_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,62 @@ lazy_static! {
seg_wit: "".to_string(),
hrp: "".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/44'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/44'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "NONE".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/49'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "P2WPKH".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/49'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "P2WPKH".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/84'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_0".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/84'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "VERSION_0".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/86'/3'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_1".to_string(),
},
CoinInfo {
coin: "DOGECOIN".to_string(),
derivation_path: "m/86'/1'/0'/0/0".to_string(),
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "VERSION_1".to_string(),
},
];

RwLock::new(coin_infos)
Expand Down
42 changes: 41 additions & 1 deletion token-core/tcx/tests/derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,33 @@ pub fn test_derive_accounts() {
curve: "ed25519".to_string(),
hrp: "".to_string(),
},
Derivation {
chain_type: "DOGECOIN".to_string(),
path: "m/44'/3'/0'/0/0".to_string(),
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
chain_id: "".to_string(),
curve: "secp256k1".to_string(),
bech32_prefix: "".to_string(),
},
Derivation {
chain_type: "DOGECOIN".to_string(),
path: "m/44'/1'/0'/0/0".to_string(),
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
chain_id: "".to_string(),
curve: "secp256k1".to_string(),
bech32_prefix: "".to_string(),
},
Derivation {
chain_type: "DOGECOIN".to_string(),
path: "m/44'/1'/0'/0/0".to_string(),
network: "MAINNET".to_string(),
seg_wit: "VERSION_1".to_string(),
chain_id: "".to_string(),
curve: "secp256k1".to_string(),
bech32_prefix: "".to_string(),
},
];

let param = DeriveAccountsParam {
Expand All @@ -206,7 +233,7 @@ pub fn test_derive_accounts() {
let derived_accounts_bytes = call_api("derive_accounts", param).unwrap();
let derived_accounts: DeriveAccountsResult =
DeriveAccountsResult::decode(derived_accounts_bytes.as_slice()).unwrap();
assert_eq!(17, derived_accounts.accounts.len());
assert_eq!(20, derived_accounts.accounts.len());
assert_eq!(
"LQ3JqCohgLQ3x1CJXYERnJTy1ySaqr1E32",
derived_accounts.accounts[0].address
Expand Down Expand Up @@ -290,6 +317,19 @@ pub fn test_derive_accounts() {
derived_accounts.accounts[16].address
);

assert_eq!(
"DGUrMnbLGQzZV3H1AYackWuykSKqqUMGEf",
derived_accounts.accounts[17].address
);
assert_eq!(
"DP48ckynvMTDkxC7SEvxtDztyFmZxviDCf",
derived_accounts.accounts[18].address
);
assert_eq!(
"1p37xv5xzd92c4wh8zt96f77a8jlf3n2qh4cps03xgurmpnllxy5us2dwgfl",
derived_accounts.accounts[19].address
);

remove_created_wallet(&import_result.id);
})
}
Expand Down

0 comments on commit 4039e2f

Please # to comment.