Skip to content
Draft
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
23 changes: 22 additions & 1 deletion crates/iota-sdk-ffi/src/types/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,30 @@ pub struct CheckpointContents(pub iota_sdk::types::CheckpointContents);

#[uniffi::export]
impl CheckpointContents {
#[uniffi::constructor]
pub fn new_v1(checkpoint_contents_v1: &CheckpointContentsV1) -> Self {
Self(iota_sdk::types::CheckpointContents::V1(
checkpoint_contents_v1.0.clone(),
))
}

pub fn as_v1(&self) -> Arc<CheckpointContentsV1> {
match &self.0 {
iota_sdk::types::CheckpointContents::V1(tx) => {
Arc::new(CheckpointContentsV1(tx.clone()))
}
}
}
}

#[derive(derive_more::From, uniffi::Object)]
pub struct CheckpointContentsV1(pub iota_sdk::types::CheckpointContentsV1);

#[uniffi::export]
impl CheckpointContentsV1 {
#[uniffi::constructor]
pub fn new(transaction_info: Vec<Arc<CheckpointTransactionInfo>>) -> Self {
Self(iota_sdk::types::CheckpointContents::new(
Self(iota_sdk::types::CheckpointContentsV1::new(
transaction_info.into_iter().map(|v| v.0.clone()).collect(),
))
}
Expand Down
37 changes: 26 additions & 11 deletions crates/iota-sdk-types/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,40 @@ pub struct SignedCheckpointSummary {
/// ; length as the vector of digests
/// ```
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointContents(
pub enum CheckpointContents {
// #[cfg_attr(feature = "serde", serde(rename = "1"))]
V1(CheckpointContentsV1),
}

impl CheckpointContents {
crate::def_is_as_into_opt!(V1(CheckpointContentsV1));
}

impl From<CheckpointContentsV1> for CheckpointContents {
fn from(v1: CheckpointContentsV1) -> Self {
CheckpointContents::V1(v1)
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointContentsV1(
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
pub Vec<CheckpointTransactionInfo>,
);

impl CheckpointContents {
impl CheckpointContentsV1 {
pub fn new(transactions: Vec<CheckpointTransactionInfo>) -> Self {
Self(transactions)
}

pub fn transactions(&self) -> &[CheckpointTransactionInfo] {
&self.0
}

pub fn into_v1(self) -> Vec<CheckpointTransactionInfo> {
self.0
}
}

/// Transaction information committed to in a checkpoint
Expand Down Expand Up @@ -453,23 +468,23 @@ mod serialization {
}
}

impl Serialize for CheckpointContents {
impl Serialize for CheckpointContentsV1 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use serde::ser::{SerializeSeq, SerializeTupleVariant};

if serializer.is_human_readable() {
serializer.serialize_newtype_struct("CheckpointContents", &self.0)
serializer.serialize_newtype_struct("CheckpointContentsV1", &self.0)
} else {
#[derive(serde::Serialize)]
struct Digests<'a> {
transaction: &'a Digest,
effects: &'a Digest,
}

struct DigestSeq<'a>(&'a CheckpointContents);
struct DigestSeq<'a>(&'a CheckpointContentsV1);
impl Serialize for DigestSeq<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -487,7 +502,7 @@ mod serialization {
}
}

struct SignatureSeq<'a>(&'a CheckpointContents);
struct SignatureSeq<'a>(&'a CheckpointContentsV1);
impl Serialize for SignatureSeq<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -526,7 +541,7 @@ mod serialization {
V1(BinaryContentsV1),
}

impl<'de> Deserialize<'de> for CheckpointContents {
impl<'de> Deserialize<'de> for CheckpointContentsV1 {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand Down
8 changes: 8 additions & 0 deletions crates/iota-sdk-types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ mod type_digest {
}
}

impl crate::CheckpointContentsV1 {
pub fn digest(&self) -> Digest {
// TODO
const SALT: &str = "CheckpointContents::";
type_digest(SALT, self)
}
}

impl crate::Transaction {
pub fn digest(&self) -> Digest {
const SALT: &str = "TransactionData::";
Expand Down
7 changes: 4 additions & 3 deletions crates/iota-sdk-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ pub mod validator;

pub use address::{Address, AddressParseError};
pub use checkpoint::{
CheckpointCommitment, CheckpointContents, CheckpointData, CheckpointSequenceNumber,
CheckpointSummary, CheckpointTimestamp, CheckpointTransaction, CheckpointTransactionInfo,
EndOfEpochData, EpochId, ProtocolVersion, SignedCheckpointSummary, StakeUnit,
CheckpointCommitment, CheckpointContents, CheckpointContentsV1, CheckpointData,
CheckpointSequenceNumber, CheckpointSummary, CheckpointTimestamp, CheckpointTransaction,
CheckpointTransactionInfo, EndOfEpochData, EpochId, ProtocolVersion, SignedCheckpointSummary,
StakeUnit,
};
pub use crypto::{
Bls12381PublicKey, Bls12381Signature, Bn254FieldElement, CircomG1, CircomG2, Ed25519PublicKey,
Expand Down
Loading