#web3 #cryptocurrency #coin #metadata #associated #mapping #type

bin+lib slip44

SLIP-0044 代币类型与相关元数据之间的映射

5 个版本

0.1.4 2021年11月11日
0.1.3 2021年10月3日
0.1.2 2021年10月3日
0.1.1 2021年10月3日
0.1.0 2021年10月3日

#28#coin

Download history 26/week @ 2024-04-01 6/week @ 2024-04-08 10/week @ 2024-04-15 15/week @ 2024-04-22 4/week @ 2024-04-29 4/week @ 2024-05-06 13/week @ 2024-05-13 4/week @ 2024-05-20 16/week @ 2024-05-27 7/week @ 2024-06-03 19/week @ 2024-06-10 7/week @ 2024-06-17 14/week @ 2024-06-24 52/week @ 2024-07-08 18/week @ 2024-07-15

85 每月下载量
5 个crate中使用(通过 walletd_hd_key

MIT 许可证

195KB
3K SLoC

SLIP44

SLIP-0044 代币类型与相关元数据之间的映射

Github Actions

用法

将以下依赖项添加到您的 Cargo 清单中...

[dependencies]
slip44 = "0.1.3"

...有关如何使用的说明,请参阅下面的 文档我能做什么? 部分。

我能做什么?

use std::{convert::TryFrom, str::FromStr};
use slip44::{Coin, Symbol};

const BITCOIN_ID: u32 = Coin::Bitcoin.id(); // Coin ID is constant

fn main() {
    assert_eq!(BITCOIN_ID, 0);
    assert_eq!(Coin::Bitcoin.id(), 0);
    assert_eq!(Coin::Bitcoin.ids(), vec![0]); // Coin may have multiple IDs (e.g. Credits)
    assert_eq!(Coin::Bitcoin.name(), "Bitcoin");
    assert_eq!(Coin::Bitcoin.link(), Some("https://bitcoin.org/".to_string()));
    assert_eq!(Coin::Bitcoin.to_string(), "Bitcoin");

    assert_eq!(Coin::try_from(0), Ok(Coin::Bitcoin)); // Try to get Coin from its ID
    assert_eq!(Coin::from_str("Bitcoin"), Ok(Coin::Bitcoin));
    assert_eq!(Coin::from(Symbol::BTC), Coin::Bitcoin); // Get Coin from its Symbol (can't fail, all symbols have associated coins)

    assert_eq!(Symbol::BTC.to_string(), "BTC");

    assert_eq!(Symbol::try_from(0), Ok(Symbol::BTC)); // Try to get coin Symbol from its ID
    assert_eq!(Symbol::try_from(Coin::Bitcoin), Ok(Symbol::BTC)); // Try to convert Coin to Symbol (can fail if no Symbol for Coin is specified)
    assert_eq!(Symbol::from_str("BTC"), Ok(Symbol::BTC));
}

依赖项

~0–12MB
~128K SLoC