Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ids to use Baid58 v0.4 format (URLs, URNs) #92

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ license = "Apache-2.0"

[workspace.dependencies]
amplify = "4.0.0"
baid58 = "0.3.1"
baid58 = "0.4.1"
strict_encoding = "2.5.0"
strict_types = "1.5.0"
commit_verify = { version = "0.10.4", features = ["stl"] }
bp-core = { version = "0.10.5", features = ["stl"] }
rgb-core = { version = "0.10.5", features = ["stl"] }
strict_types = "1.6.0"
commit_verify = { version = "0.10.5", features = ["stl"] }
bp-core = { version = "0.10.6", features = ["stl"] }
rgb-core = { version = "0.10.6", features = ["stl"] }

[package]
name = "rgb-wallet"
Expand Down
78 changes: 42 additions & 36 deletions src/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,81 +428,84 @@ mod test {
fn parse() {
// all path parameters
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// no amount
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// no contract ID
let invoice_str = "rgb:~/RGB20/6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
let invoice_str = "rgb:~/RGB20/utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// no contract ID nor iface
let invoice_str = "rgb:~/~/6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
let invoice_str = "rgb:~/~/utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// contract ID provided but no iface
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/~/\
6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::ContractIdNoIface)));

// invalid contract ID
let invalid_contract_id = "invalid";
let invoice_str =
format!("rgb:{invalid_contract_id}/RGB20/6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve");
let invoice_str = format!(
"rgb:{invalid_contract_id}/RGB20/\
utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb"
);
let result = RgbInvoice::from_str(&invoice_str);
assert!(matches!(result,
Err(InvoiceParseError::InvalidContractId(c)) if c == invalid_contract_id));

// with expiration
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?expiry=1682086371";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
expiry=1682086371";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// bad expiration
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?expiry=six";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?expiry=six";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidExpiration(_))));

// with bad query parameter
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?expiry";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?expiry";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidQueryParam(_))));

// with an unknown query parameter
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?unknown=new";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?unknown=new";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// with two unknown query parameters
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?unknown=new&\
another=new";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
unknown=new&another=new";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// with expiration and an unknown query parameter
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?expiry=1682086371&\
unknown=new";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
expiry=1682086371&unknown=new";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.to_string(), invoice_str);

// with an unknown query parameter containing percent-encoded text
let invoice_base = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?";
let query_key_encoded = ":@-%20%23";
let query_key_decoded = ":@- #";
let query_val_encoded = "?/.%26%3D";
Expand All @@ -519,39 +522,40 @@ mod test {

// no scheme
let invoice_str = "EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/~/\
6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::Invalid)));

// invalid scheme
let invoice_str = "bad:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/~/\
6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve";
utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidScheme(_))));

// empty transport endpoint specification
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?endpoints=";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidQueryParam(_))));

// invalid transport endpoint specification
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=bad";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=bad";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidQueryParam(_))));

// invalid transport variant
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpca://host.\
example.com";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpca://host.example.com";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidQueryParam(_))));

// rgb-rpc variant
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpc://host.\
example.com";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpc://host.example.com";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.transports, vec![RgbTransport::JsonRpc {
tls: false,
Expand All @@ -561,8 +565,8 @@ mod test {

// rgb-rpc variant, host containing authentication, "-" characters and port
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpcs://user:\
[email protected]:1234";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpcs://user:[email protected]:1234";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.transports, vec![RgbTransport::JsonRpc {
tls: true,
Expand All @@ -572,8 +576,8 @@ mod test {

// rgb-rpc variant, IPv6 host
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpcs://%\
5B2001:db8::1%5D:1234";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpcs://%5B2001:db8::1%5D:1234";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
assert_eq!(invoice.transports, vec![RgbTransport::JsonRpc {
tls: true,
Expand All @@ -583,27 +587,29 @@ mod test {

// rgb-rpc variant with missing host
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpc://";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpc://";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidQueryParam(_))));

// rgb-rpc variant with invalid separator
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpc/host.\
example.com";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpc/host.example.com";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::InvalidQueryParam(_))));

// rgb-rpc variant with invalid transport host specification
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpc://ho]t";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=rpc://ho]t";
let result = RgbInvoice::from_str(invoice_str);
assert!(matches!(result, Err(InvoiceParseError::Uri(_))));

// rgb+http variant
let invoice_str = "rgb:\
EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=https://\
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?endpoints=https://\
host.example.com";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
let transports = vec![RgbTransport::RestHttp {
Expand All @@ -615,8 +621,8 @@ mod test {

// rgb+ws variant
let invoice_str = "rgb:EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=wss://host.\
example.com";
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?\
endpoints=wss://host.example.com";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
let transports = vec![RgbTransport::WebSockets {
tls: true,
Expand All @@ -630,7 +636,7 @@ mod test {
// multiple transports
let invoice_str = "rgb:\
EKkb7TMfbPxzn7UhvXqhoCutzdZkSZCNYxVAVjsA67fW/RGB20/\
100+6kzbKKffP6xftkxn9UP8gWqiC41W16wYKE5CYaVhmEve?endpoints=rpcs://\
100+utxob0egXsFnw5Eud7WKYn7DVQvcPbcrR69YmgmGveacwmUFouMFKFb?endpoints=rpcs://\
host1.example.com,http://host2.example.com,ws://host3.example.com";
let invoice = RgbInvoice::from_str(invoice_str).unwrap();
let transports = vec![
Expand Down
2 changes: 1 addition & 1 deletion std/src/containers/bindle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<C: BindleContent> FromStr for Bindle<C> {
impl<C: BindleContent> Display for Bindle<C> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
writeln!(f, "-----BEGIN {}-----", C::PLATE_TITLE)?;
writeln!(f, "Id: {}", self.id)?;
writeln!(f, "Id: {:-}", self.id)?;
for (header, value) in self.bindle_headers() {
writeln!(f, "{header}: {value}")?;
}
Expand Down
Loading
Loading