Skip to content

Commit

Permalink
use Vec<Felt> for ack
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Jan 9, 2025
1 parent 91e9218 commit 9973ba6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cgp_preset! {
(ViaCairo, Felt): EncodeFelt,
(ViaCairo, u128): EncodeU128,
(ViaCairo, U256): EncodeU256,
// TODO(rano): ByteArray and Array<u8> are different types in Cairo
// for now, we CANNOT use Vec<u8> to deserialize to Array<u8>
(ViaCairo, Vec<u8>): EncodeByteArray,
(ViaCairo, Vec<Felt>): EncodeList,
(ViaCairo, bool): EncodeBool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ where
}

fn write_acknowledgement(ack: &WriteAcknowledgementEvent) -> impl AsRef<Vec<u8>> + Send {
ack.acknowledgement.ack.clone()
ack.acknowledgement
.ack
.iter()
.map(|&felt| felt.try_into().unwrap())
.collect::<Vec<_>>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ where
let ack_packet_msg = MsgAckPacket {
packet: from_cosmos_to_cairo_packet(packet, chain.encoding()),
acknowledgement: CairoAck {
ack: counterparty_payload.ack,
ack: counterparty_payload
.ack
.into_iter()
.map(Felt::from)
.collect(),
},
proof_ack_on_b,
proof_height_on_b,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ impl Transformer for EncodePacket {

#[derive(HasField)]
pub struct StateProof {
// TODO(rano): Array<u8> in Cairo
// Currently, Vec<u8> is serialized for ByteArray
pub proof: Vec<Felt>,
}

Expand Down Expand Up @@ -139,7 +141,9 @@ impl Transformer for EncodeMsgRecvPacket {

#[derive(HasField, Debug, Clone)]
pub struct Acknowledgement {
pub ack: Vec<u8>,
// TODO(rano): Array<u8> in Cairo
// Currently, Vec<u8> is serialized for ByteArray
pub ack: Vec<Felt>,
}

pub struct EncodeAcknowledgement;
Expand All @@ -156,7 +160,7 @@ delegate_components! {
}

impl Transformer for EncodeAcknowledgement {
type From = Product![Vec<u8>];
type From = Product![Vec<Felt>];
type To = Acknowledgement;

fn transform(product![ack]: Self::From) -> Acknowledgement {
Expand Down

0 comments on commit 9973ba6

Please sign in to comment.