|
@@ -1,29 +1,30 @@
|
|
|
//! Type conversions between Rust types and the generated protobuf types.
|
|
|
use std::collections::BTreeMap;
|
|
|
-use std::str::FromStr;
|
|
|
|
|
|
-use cashu::secret::Secret;
|
|
|
+use cashu::{secret::Secret, util::hex};
|
|
|
use cdk_common::{HTLCWitness, P2PKWitness};
|
|
|
use tonic::Status;
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
-impl From<cashu::Id> for Id {
|
|
|
- fn from(value: cashu::Id) -> Self {
|
|
|
- Id {
|
|
|
- inner: value.to_bytes().to_vec(),
|
|
|
+impl From<cdk_common::Error> for Error {
|
|
|
+ fn from(err: cdk_common::Error) -> Self {
|
|
|
+ let code = match err {
|
|
|
+ cdk_common::Error::AmountError(_) => ErrorCode::AmountOutsideLimit,
|
|
|
+ cdk_common::Error::DuplicateInputs => ErrorCode::DuplicateInputsProvided,
|
|
|
+ cdk_common::Error::DuplicateOutputs => ErrorCode::DuplicateInputsProvided,
|
|
|
+ cdk_common::Error::UnknownKeySet => ErrorCode::KeysetNotKnown,
|
|
|
+ cdk_common::Error::InactiveKeyset => ErrorCode::KeysetInactive,
|
|
|
+ _ => ErrorCode::Unknown,
|
|
|
+ };
|
|
|
+
|
|
|
+ Error {
|
|
|
+ code: code.into(),
|
|
|
+ detail: err.to_string(),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl TryInto<cashu::Id> for Id {
|
|
|
- type Error = cdk_common::error::Error;
|
|
|
-
|
|
|
- fn try_into(self) -> Result<cashu::Id, Self::Error> {
|
|
|
- Ok(cashu::Id::from_bytes(&self.inner)?)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
impl From<cdk_common::BlindSignatureDleq> for BlindSignatureDleq {
|
|
|
fn from(value: cdk_common::BlindSignatureDleq) -> Self {
|
|
|
BlindSignatureDleq {
|
|
@@ -43,33 +44,9 @@ impl TryInto<cdk_common::BlindSignatureDleq> for BlindSignatureDleq {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl From<crate::signatory::SignatoryKeySet> for SignatoryKeySet {
|
|
|
- fn from(value: crate::signatory::SignatoryKeySet) -> Self {
|
|
|
- SignatoryKeySet {
|
|
|
- key: Some(value.key.into()),
|
|
|
- info: Some(value.info.into()),
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl TryInto<crate::signatory::SignatoryKeySet> for SignatoryKeySet {
|
|
|
- type Error = cdk_common::error::Error;
|
|
|
-
|
|
|
- fn try_into(self) -> Result<crate::signatory::SignatoryKeySet, Self::Error> {
|
|
|
- Ok(crate::signatory::SignatoryKeySet {
|
|
|
- key: self
|
|
|
- .key
|
|
|
- .ok_or(cdk_common::Error::RecvError(
|
|
|
- "Missing property key".to_owned(),
|
|
|
- ))?
|
|
|
- .try_into()?,
|
|
|
- info: self
|
|
|
- .info
|
|
|
- .ok_or(cdk_common::Error::RecvError(
|
|
|
- "Missing property info".to_owned(),
|
|
|
- ))?
|
|
|
- .try_into()?,
|
|
|
- })
|
|
|
+impl From<Vec<crate::signatory::SignatoryKeySet>> for SignatoryKeysets {
|
|
|
+ fn from(_value: Vec<crate::signatory::SignatoryKeySet>) -> Self {
|
|
|
+ todo!()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -84,15 +61,21 @@ impl From<cdk_common::BlindSignature> for BlindSignature {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+impl From<Vec<cdk_common::Proof>> for Proofs {
|
|
|
+ fn from(value: Vec<cdk_common::Proof>) -> Self {
|
|
|
+ Proofs {
|
|
|
+ proof: value.into_iter().map(|x| x.into()).collect(),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl From<cdk_common::Proof> for Proof {
|
|
|
fn from(value: cdk_common::Proof) -> Self {
|
|
|
Proof {
|
|
|
amount: value.amount.into(),
|
|
|
keyset_id: value.keyset_id.to_string(),
|
|
|
- secret: value.secret.to_string(),
|
|
|
+ secret: value.secret.to_bytes(),
|
|
|
c: value.c.to_bytes().to_vec(),
|
|
|
- witness: value.witness.map(|w| w.into()),
|
|
|
- dleq: value.dleq.map(|dleq| dleq.into()),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -100,17 +83,23 @@ impl From<cdk_common::Proof> for Proof {
|
|
|
impl TryInto<cdk_common::Proof> for Proof {
|
|
|
type Error = Status;
|
|
|
fn try_into(self) -> Result<cdk_common::Proof, Self::Error> {
|
|
|
+ let secret = if let Ok(str) = String::from_utf8(self.secret.clone()) {
|
|
|
+ str
|
|
|
+ } else {
|
|
|
+ hex::encode(&self.secret)
|
|
|
+ };
|
|
|
+
|
|
|
Ok(cdk_common::Proof {
|
|
|
amount: self.amount.into(),
|
|
|
keyset_id: self
|
|
|
.keyset_id
|
|
|
.parse()
|
|
|
.map_err(|e| Status::from_error(Box::new(e)))?,
|
|
|
- secret: Secret::from_str(&self.secret).map_err(|e| Status::from_error(Box::new(e)))?,
|
|
|
+ secret: Secret::new(secret),
|
|
|
c: cdk_common::PublicKey::from_slice(&self.c)
|
|
|
.map_err(|e| Status::from_error(Box::new(e)))?,
|
|
|
- witness: self.witness.map(|w| w.try_into()).transpose()?,
|
|
|
- dleq: self.dleq.map(|x| x.try_into()).transpose()?,
|
|
|
+ witness: None,
|
|
|
+ dleq: None,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -159,7 +148,6 @@ impl From<cdk_common::BlindedMessage> for BlindedMessage {
|
|
|
amount: value.amount.into(),
|
|
|
keyset_id: value.keyset_id.to_string(),
|
|
|
blinded_secret: value.blinded_secret.to_bytes().to_vec(),
|
|
|
- witness: value.witness.map(|x| x.into()),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -175,7 +163,7 @@ impl TryInto<cdk_common::BlindedMessage> for BlindedMessage {
|
|
|
.map_err(|e| Status::from_error(Box::new(e)))?,
|
|
|
blinded_secret: cdk_common::PublicKey::from_slice(&self.blinded_secret)
|
|
|
.map_err(|e| Status::from_error(Box::new(e)))?,
|
|
|
- witness: self.witness.map(|x| x.try_into()).transpose()?,
|
|
|
+ witness: None,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -222,13 +210,13 @@ impl TryInto<cdk_common::Witness> for Witness {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl From<()> for Empty {
|
|
|
+impl From<()> for EmptyRequest {
|
|
|
fn from(_: ()) -> Self {
|
|
|
- Empty {}
|
|
|
+ EmptyRequest {}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl TryInto<()> for Empty {
|
|
|
+impl TryInto<()> for EmptyRequest {
|
|
|
type Error = cdk_common::error::Error;
|
|
|
|
|
|
fn try_into(self) -> Result<(), Self::Error> {
|
|
@@ -382,7 +370,7 @@ impl TryInto<cdk_common::mint::MintKeySetInfo> for MintKeySetInfo {
|
|
|
impl From<cashu::KeySet> for KeySet {
|
|
|
fn from(value: cashu::KeySet) -> Self {
|
|
|
Self {
|
|
|
- id: Some(value.id.into()),
|
|
|
+ id: value.id.to_string(),
|
|
|
unit: Some(value.unit.into()),
|
|
|
keys: Some(Keys {
|
|
|
keys: value
|
|
@@ -401,8 +389,8 @@ impl TryInto<cashu::KeySet> for KeySet {
|
|
|
Ok(cashu::KeySet {
|
|
|
id: self
|
|
|
.id
|
|
|
- .ok_or(cdk_common::error::Error::Custom("id not set".to_owned()))?
|
|
|
- .try_into()?,
|
|
|
+ .parse()
|
|
|
+ .map_err(|e| cdk_common::error::Error::Custom("id not set".to_owned()))?,
|
|
|
unit: self
|
|
|
.unit
|
|
|
.ok_or(cdk_common::error::Error::Custom("unit not set".to_owned()))?
|