Skip to content
Merged
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
45 changes: 45 additions & 0 deletions crates/iota-rust-sdk/src/types/execution_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ pub enum ExecutionError {
/// Certificate is cancelled due to congestion on shared objects
ExecutionCancelledDueToSharedObjectCongestion { congested_objects: Vec<ObjectId> },

/// Certificate is cancelled due to congestion on shared objects;
/// suggested gas price can be used to give this certificate more priority.
ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects: Vec<ObjectId>,
suggested_gas_price: u64,
},

/// Address is denied for this coin type
AddressDeniedForCoin { address: Address, coin_type: String },

Expand Down Expand Up @@ -470,6 +477,11 @@ mod serialization {
},

ExecutionCancelledDueToRandomnessUnavailable,

ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects: Vec<ObjectId>,
suggested_gas_price: u64,
},
}

#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
Expand Down Expand Up @@ -553,6 +565,11 @@ mod serialization {
},

ExecutionCancelledDueToRandomnessUnavailable,

ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects: Vec<ObjectId>,
suggested_gas_price: u64,
},
}

impl Serialize for ExecutionError {
Expand Down Expand Up @@ -671,6 +688,13 @@ mod serialization {
Self::ExecutionCancelledDueToRandomnessUnavailable => {
ReadableExecutionError::ExecutionCancelledDueToRandomnessUnavailable
}
Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
} => ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
},
};
readable.serialize(serializer)
} else {
Expand Down Expand Up @@ -780,6 +804,13 @@ mod serialization {
Self::ExecutionCancelledDueToRandomnessUnavailable => {
BinaryExecutionError::ExecutionCancelledDueToRandomnessUnavailable
}
Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
} => BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
},
};
binary.serialize(serializer)
}
Expand Down Expand Up @@ -900,6 +931,13 @@ mod serialization {
ReadableExecutionError::ExecutionCancelledDueToRandomnessUnavailable => {
Self::ExecutionCancelledDueToRandomnessUnavailable
}
ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
} => Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
},
})
} else {
BinaryExecutionError::deserialize(deserializer).map(|binary| match binary {
Expand Down Expand Up @@ -1006,6 +1044,13 @@ mod serialization {
BinaryExecutionError::ExecutionCancelledDueToRandomnessUnavailable => {
Self::ExecutionCancelledDueToRandomnessUnavailable
}
BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
} => Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
congested_objects,
suggested_gas_price,
},
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-rust-sdk/src/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ mod serialization {
ReadableObjectData::Move(ReadableMoveStruct { contents }),
) => {
// check id matches in contents
if !id_opt(&contents).is_some_and(|id| id == object_id) {
if id_opt(&contents).is_none_or(|id| id != object_id) {
return Err(serde::de::Error::custom("id from contents doesn't match"));
}

Expand Down Expand Up @@ -799,7 +799,7 @@ mod serialization {
ReadableObjectData::Move(ReadableMoveStruct { contents }),
) => {
// check id matches in contents
if !id_opt(&contents).is_some_and(|id| id == object_id) {
if id_opt(&contents).is_none_or(|id| id != object_id) {
return Err(serde::de::Error::custom("id from contents doesn't match"));
}

Expand Down
18 changes: 9 additions & 9 deletions crates/iota-rust-sdk/src/types/type_tag/parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winnow::{
PResult, Parser,
ModalResult, Parser,
ascii::space0,
combinator::{alt, delimited, eof, opt, separated},
stream::AsChar,
Expand All @@ -12,11 +12,11 @@ use super::{Address, Identifier, StructTag, TypeTag};
// r"(?:[a-zA-Z][a-zA-Z0-9_]*)|(?:_[a-zA-Z0-9_]+)";
static MAX_IDENTIFIER_LENGTH: usize = 128;

pub(super) fn parse_identifier(mut input: &str) -> PResult<&str> {
pub(super) fn parse_identifier(mut input: &str) -> ModalResult<&str> {
(identifier, eof).take().parse_next(&mut input)
}

fn identifier<'s>(input: &mut &'s str) -> PResult<&'s str> {
fn identifier<'s>(input: &mut &'s str) -> ModalResult<&'s str> {
alt((
(one_of(|c: char| c.is_alpha()), valid_remainder(0)),
('_', valid_remainder(1)),
Expand All @@ -38,17 +38,17 @@ fn valid_remainder<'a>(
}
}

fn parse_address<'s>(input: &mut &'s str) -> PResult<&'s str> {
fn parse_address<'s>(input: &mut &'s str) -> ModalResult<&'s str> {
("0x", take_while(1..=64, AsChar::is_hex_digit))
.take()
.parse_next(input)
}

pub(super) fn parse_type_tag(mut input: &str) -> PResult<TypeTag> {
pub(super) fn parse_type_tag(mut input: &str) -> ModalResult<TypeTag> {
(type_tag, eof).parse_next(&mut input).map(|(t, _)| t)
}

fn type_tag(input: &mut &str) -> PResult<TypeTag> {
fn type_tag(input: &mut &str) -> ModalResult<TypeTag> {
alt((
"u8".value(TypeTag::U8),
"u16".value(TypeTag::U16),
Expand All @@ -65,11 +65,11 @@ fn type_tag(input: &mut &str) -> PResult<TypeTag> {
.parse_next(input)
}

pub(super) fn parse_struct_tag(mut input: &str) -> PResult<StructTag> {
pub(super) fn parse_struct_tag(mut input: &str) -> ModalResult<StructTag> {
(struct_tag, eof).parse_next(&mut input).map(|(s, _)| s)
}

fn struct_tag(input: &mut &str) -> PResult<StructTag> {
fn struct_tag(input: &mut &str) -> ModalResult<StructTag> {
let (address, _, module, _, name) = (
parse_address.try_map(|s| s.parse::<Address>()),
"::",
Expand All @@ -92,7 +92,7 @@ fn struct_tag(input: &mut &str) -> PResult<StructTag> {
})
}

fn generics(input: &mut &str) -> PResult<Vec<TypeTag>> {
fn generics(input: &mut &str) -> ModalResult<Vec<TypeTag>> {
separated(1.., delimited(space0, type_tag, space0), ",").parse_next(input)
}

Expand Down
Loading