#stack #web3 #cryptocurrency #bitcoin

bin+lib nil-slip44

Mapping between SLIP-0044 coin types and the associated metadata

9 releases

0.3.8 Feb 11, 2025
0.3.7 Feb 10, 2025
0.2.0 Feb 8, 2025

#709 in Magic Beans

Download history 491/week @ 2025-02-04 447/week @ 2025-02-11

938 downloads per month
Used in nil-zonefile

MIT license

195KB
4K SLoC

NIL-SLIP44

Mapping between SLIP-0044 coin types and the associated metadata

SLIP-0044 is a standard that defines coin type values for use in hierarchical deterministic wallets. This crate provides type-safe access to coin types and their metadata.

Github Actions

Usage

Add the following dependency to your Cargo manifest...

[dependencies]
nil-slip44 = "0.3.8"

...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 nil_slip44::{Coin, Symbol};


    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.to_string(), "Bitcoin");

    assert_eq!(Coin::Stacks.id(), 5757);
    assert_eq!(Coin::Stacks.ids(), vec![5757]); // Coin may have multiple IDs (e.g. Credits)
    assert_eq!(Coin::Stacks.name(), "Stacks");
    assert_eq!(Coin::Stacks.to_string(), "Stacks");
    
    assert_eq!(Coin::try_from(0), Ok(Coin::Bitcoin)); // Try to get Coin from its ID
    assert_eq!(Coin::try_from(5757), Ok(Coin::Stacks)); // Try to get Coin from its ID
    assert_eq!(Coin::from_str("Bitcoin"), Ok(Coin::Bitcoin));
    assert_eq!(Coin::from_str("Stacks"), Ok(Coin::Stacks));
    assert_eq!(Coin::from(Symbol::BTC), Coin::Bitcoin); // Get Coin from its Symbol (can't fail, all symbols have associated coins)
    assert_eq!(Coin::from(Symbol::STX), Coin::Stacks);
    assert_eq!(Symbol::BTC.to_string(), "BTC");
    assert_eq!(Symbol::STX.to_string(), "STX");
    
    assert_eq!(Symbol::try_from(0), Ok(Symbol::BTC)); // Try to get coin Symbol from its ID
    assert_eq!(Symbol::try_from(5757), Ok(Symbol::STX)); // 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::try_from(Coin::Stacks), Ok(Symbol::STX));

    assert_eq!(Symbol::from_str("BTC"), Ok(Symbol::BTC));
    assert_eq!(Symbol::from_str("STX"), Ok(Symbol::STX));

Updating coins list

cargo run --bin parse-coins

Dependencies

~0–15MB
~133K SLoC