Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony1060 committed Feb 21, 2024
1 parent e556f59 commit c4c03c9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion shared/src/core/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ENSService {
let lookup_state = LookupState {
rpc,
opensea_api_key: self.opensea_api_key.clone(),
ipfs_gateway: self.ipfs_gateway.clone()
ipfs_gateway: self.ipfs_gateway.clone(),
};

// Assume results & calldata have the same length
Expand Down
9 changes: 7 additions & 2 deletions shared/src/models/ipfs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::models::lookup::image::IPFS_REGEX;
use lazy_static::lazy_static;
use reqwest::header::HeaderValue;
use thiserror::Error;

use crate::models::lookup::image::IPFS_REGEX;
use crate::models::lookup::LookupState;

use super::erc721::metadata::NFTMetadata;

use lazy_static::lazy_static;

#[derive(Debug, PartialEq)]
pub enum IPFSURLUnparsed {
URL(String),
Expand Down Expand Up @@ -51,7 +54,9 @@ impl IPFSURLUnparsed {
pub fn to_url_or_gateway(&self, state: &LookupState) -> String {
match self {
IPFSURLUnparsed::URL(url) => url.to_string(),
IPFSURLUnparsed::IPFS(hash) => format!("{gateway}/{hash}", gateway=state.ipfs_gateway),
IPFSURLUnparsed::IPFS(hash) => {
format!("{gateway}/{hash}", gateway = state.ipfs_gateway)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion shared/src/models/lookup/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ pub async fn decode(data: &[u8], state: &LookupState) -> Result<String, ENSLooku

#[cfg(test)]
mod tests {
use crate::models::lookup::ENSLookup;
use ethers::providers::namehash;

use crate::models::lookup::ENSLookup;

#[test]
fn test_calldata_avatar() {
assert_eq!(
Expand Down
12 changes: 9 additions & 3 deletions shared/src/models/multicoin/decoding/p2pkh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ impl MulticoinDecoder for P2PKHDecoder {
fn decode(&self, data: &[u8]) -> Result<String, MulticoinDecoderError> {
let bytes_len = data.len();
if bytes_len < 3 {
return Err(MulticoinDecoderError::InvalidStructure("len < 3".to_string()));
return Err(MulticoinDecoderError::InvalidStructure(
"len < 3".to_string(),
));
}

if data[..2] != [0x76, 0xa9] {
return Err(MulticoinDecoderError::InvalidStructure("invalid header".to_string()));
return Err(MulticoinDecoderError::InvalidStructure(
"invalid header".to_string(),
));
}

let len = data[2] as usize;
Expand All @@ -29,7 +33,9 @@ impl MulticoinDecoder for P2PKHDecoder {
}

if data[bytes_len - 2..bytes_len] != [0x88, 0xac] {
return Err(MulticoinDecoderError::InvalidStructure("invalid end".to_string()));
return Err(MulticoinDecoderError::InvalidStructure(
"invalid end".to_string(),
));
}

let pub_key_hash = &data[3..3 + len];
Expand Down
36 changes: 22 additions & 14 deletions shared/src/models/multicoin/decoding/p2sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,45 @@ impl MulticoinDecoder for P2SHDecoder {
fn decode(&self, data: &[u8]) -> Result<String, MulticoinDecoderError> {
let bytes_len = data.len();
if bytes_len < 2 {
return Err(MulticoinDecoderError::InvalidStructure("len < 2".to_string()));
return Err(MulticoinDecoderError::InvalidStructure(
"len < 2".to_string(),
));
}

if data[0] != 0xa9 {
return Err(MulticoinDecoderError::InvalidStructure("invalid header".to_string()));
return Err(MulticoinDecoderError::InvalidStructure(
"invalid header".to_string(),
));
}

let len = data[1] as usize;
let expected_len = 2 + len + 1;

if bytes_len != expected_len {
return Err(MulticoinDecoderError::InvalidStructure(format!("invalid length ({bytes_len:?} != {expected_len:?})")));
return Err(MulticoinDecoderError::InvalidStructure(format!(
"invalid length ({bytes_len:?} != {expected_len:?})"
)));
}

if data[bytes_len - 1] != 0x87 {
return Err(MulticoinDecoderError::InvalidStructure("invalid end".to_string()));
return Err(MulticoinDecoderError::InvalidStructure(
"invalid end".to_string(),
));
}

let script_hash = &data[2..2 + len];

let mut full = script_hash.to_vec();
full.insert(0, self.version);

let full_checksum = utils::sha256::hash(utils::sha256::hash(full.clone()));

full.extend_from_slice(&full_checksum[..4]);

let value = bs58::encode(full)
.with_alphabet(Alphabet::BITCOIN)
.into_string();

Ok(value)
}
}
2 changes: 1 addition & 1 deletion shared/src/utils/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub fn hash<T: AsRef<[u8]>>(data: T) -> Vec<u8> {
hasher.update(data);

hasher.finalize().as_slice().into()
}
}
4 changes: 3 additions & 1 deletion worker/src/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub fn parse_query<T: DeserializeOwned>(req: &Request) -> worker::Result<T> {
let url = req.url()?;
let query = url.query().unwrap_or("");

SERDE_QS_CONFIG.deserialize_str::<T>(query).map_err(|_| http_simple_status_error(StatusCode::BAD_REQUEST))
SERDE_QS_CONFIG
.deserialize_str::<T>(query)
.map_err(|_| http_simple_status_error(StatusCode::BAD_REQUEST))
}

#[derive(Error, Debug)]
Expand Down

0 comments on commit c4c03c9

Please sign in to comment.