Skip to content

Commit 1cd3489

Browse files
committed
Fix
1 parent 0fe8008 commit 1cd3489

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/lib.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
use payjoin::{
2-
PayjoinRequest,
3-
PayjoinResponse,
4-
};
1+
use std::str::FromStr;
2+
use payjoin::bitcoin::Address;
3+
use payjoin::Url;
4+
use payjoin::PjUri;
55

6-
#[no_mangle]
7-
pub extern "C" fn main() {
8-
// Main function implementation
9-
}
6+
fn main() {
7+
// Initialize URL
8+
let url = Url::parse("https://example.com/pay?amount=1.23¤cy=USD&label=Alice&message=Hello%20world")
9+
.expect("Failed to parse URL");
1010

11+
// Convert URL to PjUri
12+
let pjuri = PjUri::from(&url).expect("Failed to create PjUri from URL");
13+
14+
// Convert PjUri to string
15+
let pjuri_str = pjuri.to_string();
16+
println!("PjUri as string: {}", pjuri_str);
17+
18+
// Convert string back to PjUri
19+
let pjuri_parsed = PjUri::from(&pjuri_str).amount.message.expect("Failed to parse PjUri from string");
20+
21+
// Convert PjUri back to URL
22+
let final_url = pjuri_parsed.to_url().expect("Failed to convert PjUri to URL");
23+
24+
// Print the final URL
25+
println!("Final URL: {}", final_url);
26+
27+
// Bitcoin address parsing
28+
let bitcoin_address = Address::from_str("1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2")
29+
.expect("Failed to parse Bitcoin address");
30+
31+
println!("Bitcoin address: {:?}", bitcoin_address);
32+
}

0 commit comments

Comments
 (0)