Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Nov 22, 2024
1 parent 6c8d38f commit 659f8d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 6 additions & 6 deletions crates/context/config/src/client/env/proxy/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ impl Method<Starknet> for Mutate {
if response.is_empty() {
return Ok(None);
}

// Skip first 32 bytes (array length)
let response = &response[32..];

// Get proposal_id from the next 64 bytes (32 for high, 32 for low)
let proposal_id = Repr::new(ProposalId::from_bytes(|bytes| {
// Take 16 bytes from high and 16 bytes from low
bytes[..16].copy_from_slice(&response[16..32]); // Last 16 bytes of high
bytes[16..].copy_from_slice(&response[48..64]); // Last 16 bytes of low
bytes[..16].copy_from_slice(&response[16..32]); // Last 16 bytes of high
bytes[16..].copy_from_slice(&response[48..64]); // Last 16 bytes of low
Ok(32)
})?);

// Get num_approvals from the last 32 bytes
let num_approvals = u32::from_be_bytes(response[64..][28..32].try_into()?) as usize;

Ok(Some(ProposalWithApprovals {
proposal_id,
num_approvals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use crate::client::env::proxy::types::starknet::{StarknetApprovers, StarknetProp
use crate::client::env::Method;
use crate::client::protocol::near::Near;
use crate::client::protocol::starknet::Starknet;
use crate::repr::Repr;
use crate::repr::ReprBytes;
use crate::repr::{Repr, ReprBytes};
use crate::types::ContextIdentity;

#[derive(Clone, Debug, Serialize)]
Expand Down Expand Up @@ -50,16 +49,16 @@ impl Method<Starknet> for ProposalApproversRequest {
fn encode(self) -> eyre::Result<Vec<u8>> {
// Get the full 32 bytes
let bytes = self.proposal_id.as_bytes();

// Split into high and low parts (16 bytes each)
let (high_bytes, low_bytes) = bytes.split_at(16);

// Create Felts with proper padding
let mut high = [0u8; 32];
let mut low = [0u8; 32];
high[16..].copy_from_slice(high_bytes); // Put in last 16 bytes
low[16..].copy_from_slice(low_bytes); // Put in last 16 bytes
high[16..].copy_from_slice(high_bytes); // Put in last 16 bytes
low[16..].copy_from_slice(low_bytes); // Put in last 16 bytes

let starknet_id = StarknetProposalId {
high: Felt::from_bytes_be(&high),
low: Felt::from_bytes_be(&low),
Expand Down
5 changes: 2 additions & 3 deletions crates/context/config/src/client/env/proxy/types/starknet.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use starknet::core::codec::{Decode, Encode};
use starknet::core::types::{Felt, U256};

use crate::repr::{Repr, ReprBytes};
use crate::repr::ReprTransmute;
use crate::repr::{Repr, ReprBytes, ReprTransmute};
use crate::types::{ContextIdentity, ProposalId, SignerId};
use crate::{
Proposal, ProposalAction, ProposalApprovalWithSigner, ProposalWithApprovals, ProxyMutateRequest,
Expand Down Expand Up @@ -311,7 +310,7 @@ impl From<StarknetApprovers> for Vec<ContextIdentity> {
ContextIdentity::from_bytes(|bytes| {
let mut combined = [0u8; 32];
combined[..16].copy_from_slice(&identity.high.to_bytes_be()[16..]);
combined[16..].copy_from_slice(&identity.low.to_bytes_be()[16..]); // Changed this line
combined[16..].copy_from_slice(&identity.low.to_bytes_be()[16..]); // Changed this line
bytes.copy_from_slice(&combined);
Ok(32)
})
Expand Down

0 comments on commit 659f8d0

Please sign in to comment.