#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

#51 in #base32

Download history 161/week @ 2024-08-31 120/week @ 2024-09-07 90/week @ 2024-09-14 166/week @ 2024-09-21 119/week @ 2024-09-28 84/week @ 2024-10-12 77/week @ 2024-10-19 105/week @ 2024-10-26 98/week @ 2024-11-02 37/week @ 2024-11-09 48/week @ 2024-11-16 124/week @ 2024-11-23 175/week @ 2024-11-30 256/week @ 2024-12-07 149/week @ 2024-12-14

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

MIT license

395KB
946 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

~88MB
~851K SLoC