#string #system #bitcoin #money #string-formatting #fixed-point #base32

nightly bitcoin-string

string utilities for the bitcoin system -- BilingualStr, strings representing money

7 releases

0.1.16-alpha.0 Mar 31, 2023
0.1.14-alpha.0 Mar 18, 2023
0.1.12-alpha.0 Jan 18, 2023

#43 in #base32

Download history 213/week @ 2024-01-13 115/week @ 2024-01-20 67/week @ 2024-01-27 75/week @ 2024-02-03 149/week @ 2024-02-10 138/week @ 2024-02-17 162/week @ 2024-02-24 136/week @ 2024-03-02 142/week @ 2024-03-09 172/week @ 2024-03-16 321/week @ 2024-03-23 246/week @ 2024-03-30 135/week @ 2024-04-06 211/week @ 2024-04-13 171/week @ 2024-04-20 161/week @ 2024-04-27

680 downloads per month
Used in 94 crates (36 directly)

MIT license

395KB
945 lines

Rust Crate Description: bitcoin-string

The bitcoin-string crate is a direct Rust translation of the Bitcoin codebase from C++. It provides a collection of string-related utilities and functionalities that are essential to the Bitcoin system. Some function bodies may still be in the process of translation.

The crate includes a variety of string manipulation and formatting methods, including functions for checking prefixes, joining strings, and trimming whitespace. It also provides methods for encoding and decoding strings in various formats, such as base32 and base64. In addition, the crate includes functions for parsing and formatting Bitcoin-specific values, such as money amounts and fixed-point numbers.

While there are no specific mathematical equations or concepts involved in the bitcoin-string crate, the string manipulation and encoding functions are essential to the proper functioning of the Bitcoin system.

Relevant Tokens

  • has_prefix
  • join
  • make_unordered_list
  • remove_prefix
  • to_string
  • trim_string
  • valid_as_cstring
  • format_money
  • parse_money
  • BilingualStr
  • Output
  • add
  • add_assign
  • clear
  • empty
  • format
  • from
  • untranslated
  • SafeChars
  • T
  • capitalize
  • convert_bits
  • decode_base32
  • decode_base32_bytes
  • decode_base64
  • decode_base64_bytes
  • encode_base32
  • encode_base32_bytes
  • encode_base64
  • encode_base64_bytes
  • hex_digit
  • hex_str
  • is_digit
  • is_hex
  • is_hex_number
  • is_space
  • locale_independent_atoi
  • parse_fixed_point
  • parse_hex
  • parse_int32
  • parse_int64
  • parse_integral
  • parse_uint16
  • parse_uint32
  • parse_uint64
  • parse_uint8
  • process_mantissa_digit
  • sanitize_string
  • timing_resistant_equal
  • to_integral
  • to_lower
  • to_upper

How is it used in Bitcoin?

The bitcoin-string crate is used extensively throughout the Bitcoin system to handle string manipulation, parsing, and encoding. It is particularly important in transaction processing, where it is used to format and encode transaction inputs and outputs, as well as to parse and decode transaction signatures. It is also used in other areas of the system, such as network message handling and database management.

161> thanks -- seems pretty straightforward. any gotchas?

One potential gotcha to keep in mind when using this crate is the potential for unexpected behavior when manipulating strings with non-ASCII characters. Some functions, such as to_lower and to_upper, may not properly handle characters outside of the ASCII range. It's important to thoroughly test your code and ensure that it properly handles all possible inputs to avoid any unexpected behavior. Additionally, it's important to use the appropriate string types (String, &str, etc.) and encoding formats (UTF-8, ASCII, etc.) as needed to ensure consistent behavior across different platforms and systems.

Dependencies

~89MB
~846K SLoC