Implements
cashaddr
codec for transcoding between cashaddr strings and bytes. The main use of this crate is via the
[CashEnc] trait which provides and implementation for encoding any borrowed sequence of u8
into a cashaddr string with arbirary prefix. Also, the library supports parsing cashaddr string
via the [Payload] struct, which implements [FromStr]
Encoding Examples
Encoding a sequence of bytes into a cashaddr string is acheived via the [CashEnc] trait. This
trait's methods are used to encode the bytes sequence, and is implemented for all types which
implement [AsRef<[u8]>]
use hex;
use ;
let payload: = decode.unwrap;
// encode the payload bytes as a p2sh cashaddr, using "bchtest" as the prefix
let cashaddr = "bchtest:pr6m7j9njldwwzlg9v7v53unlr4jkmx6eyvwc0uz5t";
assert_eq!;
// encode the payload bytes as a p2pkh cashaddr, using "bitcoincash" as the prefix
let cashaddr = "bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2";
assert_eq!;
Decoding Examples
use hex;
use Payload;
let cashaddr = "bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2";
let addr: Payload = cashaddr.parse.unwrap;
let payload = decode.unwrap;
assert_eq!;
Attribution
Most of this code was forked from
bitcoincash-addr. This library
was created to both provide a more convenient user interface, as well as support arbitrary
prefixes.