forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 6a56461 Author: Maxim <59533214+biryukovmaxim@users.noreply.github.com> Date: Tue Jun 18 18:09:29 2024 +0300 Implement PSKT(Partially Signed Kaspa Transaction) (kaspanet#481) * initial support of pskt: supported roles: creator, constructor, updater, signer roles * add builder * handle combine errors * finalize * extractor * chore: typo * style: fmt * expose txid to global * chore: change version * feat: serde for optional bytes * feat: impl (de)serialization * style: fmt * add example, fixes * style: fmt * style: clippy * rollback unrelated changes * psbt -> pskt * refactor: avoid copy-paste by using recursion * docs: add description of roles commit a797e1e Author: George Bogodukhov <gvbgduh@gmail.com> Date: Mon Jun 17 15:50:16 2024 +1000 Add support for IP only for --rpclisten-borsh/json (kaspanet#402) (kaspanet#439) * Add support for IP only for --rpclisten-borsh/json * Fix cehck complaints
- Loading branch information
1 parent
b917e21
commit 99eed7c
Showing
19 changed files
with
1,359 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
pub use de::Deserialize; | ||
pub use ser::Serialize; | ||
|
||
pub fn serialize<T, S>(bytes: &T, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
T: ?Sized + Serialize, | ||
S: serde::Serializer, | ||
{ | ||
Serialize::serialize(bytes, serializer) | ||
} | ||
|
||
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error> | ||
where | ||
T: Deserialize<'de>, | ||
D: serde::Deserializer<'de>, | ||
{ | ||
Deserialize::deserialize(deserializer) | ||
} | ||
|
||
mod de { | ||
use std::fmt::Display; | ||
|
||
pub trait Deserialize<'de>: Sized { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de>; | ||
} | ||
|
||
impl<'de, T: crate::serde_bytes::Deserialize<'de>> Deserialize<'de> for Option<T> | ||
where | ||
<T as TryFrom<&'de [u8]>>::Error: Display, | ||
{ | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
struct OptionalVisitor<T> { | ||
out: std::marker::PhantomData<T>, | ||
} | ||
|
||
impl<'de, T> serde::de::Visitor<'de> for OptionalVisitor<T> | ||
where | ||
T: crate::serde_bytes::Deserialize<'de>, | ||
{ | ||
type Value = Option<T>; | ||
|
||
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
f.write_str("optional string, str or slice, vec of bytes") | ||
} | ||
|
||
fn visit_unit<E: serde::de::Error>(self) -> Result<Self::Value, E> { | ||
Ok(None) | ||
} | ||
|
||
fn visit_none<E: serde::de::Error>(self) -> Result<Self::Value, E> { | ||
Ok(None) | ||
} | ||
|
||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
T::deserialize(deserializer).map(Some) | ||
} | ||
} | ||
|
||
let visitor = OptionalVisitor { out: std::marker::PhantomData }; | ||
deserializer.deserialize_option(visitor) | ||
} | ||
} | ||
} | ||
|
||
mod ser { | ||
use serde::Serializer; | ||
|
||
pub trait Serialize { | ||
#[allow(missing_docs)] | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer; | ||
} | ||
|
||
impl<T> Serialize for Option<T> | ||
where | ||
T: crate::serde_bytes::Serialize + std::convert::AsRef<[u8]>, | ||
{ | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
struct AsBytes<T>(T); | ||
|
||
impl<T> serde::Serialize for AsBytes<T> | ||
where | ||
T: crate::serde_bytes::Serialize, | ||
{ | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
crate::serde_bytes::Serialize::serialize(&self.0, serializer) | ||
} | ||
} | ||
|
||
match self { | ||
Some(b) => serializer.serialize_some(&AsBytes(b)), | ||
None => serializer.serialize_none(), | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.