-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
use payjoin::{ | ||
PayjoinRequest, | ||
PayjoinResponse, | ||
}; | ||
use std::str::FromStr; | ||
use payjoin::bitcoin::Address; | ||
use payjoin::Url; | ||
use payjoin::PjUri; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() { | ||
// Main function implementation | ||
} | ||
fn main() { | ||
// Initialize URL | ||
let url = Url::parse("https://example.com/pay?amount=1.23¤cy=USD&label=Alice&message=Hello%20world") | ||
.expect("Failed to parse URL"); | ||
|
||
// Convert URL to PjUri | ||
let pjuri = PjUri::from(&url).expect("Failed to create PjUri from URL"); | ||
|
||
// Convert PjUri to string | ||
let pjuri_str = pjuri.to_string(); | ||
println!("PjUri as string: {}", pjuri_str); | ||
|
||
// Convert string back to PjUri | ||
let pjuri_parsed = PjUri::from(&pjuri_str).amount.message.expect("Failed to parse PjUri from string"); | ||
|
||
// Convert PjUri back to URL | ||
let final_url = pjuri_parsed.to_url().expect("Failed to convert PjUri to URL"); | ||
|
||
// Print the final URL | ||
println!("Final URL: {}", final_url); | ||
|
||
// Bitcoin address parsing | ||
let bitcoin_address = Address::from_str("1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2") | ||
.expect("Failed to parse Bitcoin address"); | ||
|
||
println!("Bitcoin address: {:?}", bitcoin_address); | ||
} |