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

Implement RPC api calls for integrated address #134

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
**/*.rs.bk
Cargo.lock
.idea
58 changes: 58 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ use monero::{
};
use serde::{de::IgnoredAny, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{json, Value};
use std::str::FromStr;
use std::{
collections::HashMap,
convert::TryFrom,
Expand All @@ -83,6 +84,7 @@ use uuid::Uuid;

#[cfg(feature = "rpc_authentication")]
use diqwest::WithDigestAuth;
use hex::FromHex;

enum RpcParams {
Array(Box<dyn Iterator<Item = Value> + Send + 'static>),
Expand Down Expand Up @@ -814,6 +816,62 @@ impl WalletClient {
Ok((rsp.address, rsp.address_index))
}

/// Make an integrated address from the wallet address and a payment id.
pub async fn make_integrated_address(
&self,
standard_address: Option<Address>,
payment_id: Option<PaymentId>,
) -> anyhow::Result<(Address, PaymentId)> {
#[derive(Deserialize)]
struct Rsp {
integrated_address: String,
payment_id: HashString<Vec<u8>>,
}

let params = empty()
.chain(standard_address.map(|v| ("standard_address", v.to_string().into())))
.chain(payment_id.map(|v| ("payment_id", HashString(v).to_string().into())));

let rsp = self
.inner
.request::<Rsp>("make_integrated_address", RpcParams::map(params))
.await?;

Ok((
Address::from_str(&rsp.integrated_address)?,
PaymentId::from_hex(rsp.payment_id.to_string())?,
))
}

/// Retrieve the standard address and payment id corresponding to an integrated address.
pub async fn split_integrated_address(
&self,
integrated_address: Address,
) -> anyhow::Result<(bool, PaymentId, Address)> {
#[derive(Deserialize)]
struct Rsp {
is_subaddress: bool,
payment: HashString<Vec<u8>>,
standard_address: String,
}

let params = empty().chain(once((
"integrated_address",
integrated_address.to_string().into(),
)));

let rsp = self
.inner
.request::<Rsp>("split_integrated_address", RpcParams::map(params))
.await?;

Ok((
rsp.is_subaddress,
PaymentId::from_hex(rsp.payment.to_string())?,
Address::from_str(&rsp.standard_address)?,
))
}

/// Label an address.
pub async fn label_address(
&self,
Expand Down