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

bin+lib slip44

Mapping between SLIP-0044 coin types and the associated metadata

5 releases

0.1.4 Nov 11, 2021
0.1.3 Oct 3, 2021
0.1.2 Oct 3, 2021
0.1.1 Oct 3, 2021
0.1.0 Oct 3, 2021

#24 in #coin

Download history 14/week @ 2024-02-18 20/week @ 2024-02-25 13/week @ 2024-03-03 16/week @ 2024-03-10 11/week @ 2024-03-17 8/week @ 2024-03-24

51 downloads per month
Used in 5 crates (via walletd_hd_key)

MIT license

195KB
3K SLoC

SLIP44

Mapping between SLIP-0044 coin types and the associated metadata

Github Actions

Usage

Add the following dependency to your Cargo manifest...

[dependencies]
slip44 = "0.1.3"

...and see the docs or What can I do? section below for how to use it.

What can I do?

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));
}

Dependencies

~0–13MB
~145K SLoC