Skip to content

Commit

Permalink
formatter and clippy pass
Browse files Browse the repository at this point in the history
  • Loading branch information
guilledk committed Aug 1, 2024
1 parent a1ad141 commit 4a0ed13
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 37 deletions.
9 changes: 6 additions & 3 deletions crates/antelope/src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ impl<P: Provider> APIClient<P> {
pub fn default_provider(base_url: String) -> Result<APIClient<DefaultProvider>, String> {
Self::default_provider_debug(base_url, false)
}

pub fn default_provider_debug(base_url: String, debug: bool) -> Result<APIClient<DefaultProvider>, String> {

pub fn default_provider_debug(
base_url: String,
debug: bool,
) -> Result<APIClient<DefaultProvider>, String> {
let mut provider = DefaultProvider::new(base_url).unwrap();
provider.set_debug(debug);

APIClient::custom_provider(provider)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/antelope/src/api/default_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ impl Provider for DefaultProvider {
if self.debug {
println!("Error: {}", err_str);
}

return Err(err_str);
}

let response = res.unwrap().text().await.unwrap();
if self.debug {
println!("Response: {}", response);
}

Ok(response)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/antelope/src/api/system/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod structs;

use std::path::Path;
use crate::api::client::{APIClient, Provider};
use crate::api::system::structs::{
CreateAccountParams, DelegateBandwidthAction, NewAccountAction, SetAbiAction, SetCodeAction,
Expand All @@ -15,6 +14,7 @@ use crate::chain::private_key::PrivateKey;
use crate::name;
use crate::serializer::Encoder;
use sha2::{Digest, Sha256};
use std::path::Path;

#[derive(Debug, Default, Clone)]
pub struct SystemAPI<T: Provider> {
Expand Down
24 changes: 18 additions & 6 deletions crates/antelope/src/api/v1/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::fmt::Debug;

use serde_json::{self, Value};

use crate::api::v1::structs::{ABIResponse, EncodingError, GetBlockResponse, GetTransactionStatusResponse, ServerError};
use crate::api::v1::structs::{
ABIResponse, EncodingError, GetBlockResponse, GetTransactionStatusResponse, ServerError,
};
use crate::chain::checksum::{Checksum160, Checksum256};
use crate::{
api::{
client::Provider,
Expand All @@ -21,7 +24,6 @@ use crate::{
serializer::formatter::{JSONObject, ValueTo},
util::hex_to_bytes,
};
use crate::chain::checksum::{Checksum160, Checksum256};

#[derive(Debug, Default, Clone)]
pub struct ChainAPI<T: Provider> {
Expand Down Expand Up @@ -191,14 +193,20 @@ impl<T: Provider> ChainAPI<T> {
}
}

pub async fn get_transaction_status(&self, trx_id: Checksum256) -> Result<GetTransactionStatusResponse, ClientError<ErrorResponse>> {
pub async fn get_transaction_status(
&self,
trx_id: Checksum256,
) -> Result<GetTransactionStatusResponse, ClientError<ErrorResponse>> {
let payload = serde_json::json!({
"id": trx_id,
});

let result = self
.provider
.post(String::from("/v1/chain/get_transaction_status"), Some(payload.to_string()))
.post(
String::from("/v1/chain/get_transaction_status"),
Some(payload.to_string()),
)
.await;

match result {
Expand Down Expand Up @@ -264,10 +272,14 @@ impl<T: Provider> ChainAPI<T> {
next_key = Some(TableIndexType::UINT128(next_key_str.parse().unwrap()));
}
Some(TableIndexType::CHECKSUM160(_)) => {
next_key = Some(TableIndexType::CHECKSUM160(Checksum160::from_bytes(hex_to_bytes(&next_key_str).as_slice()).unwrap()));
next_key = Some(TableIndexType::CHECKSUM160(
Checksum160::from_bytes(hex_to_bytes(&next_key_str).as_slice()).unwrap(),
));
}
Some(TableIndexType::CHECKSUM256(_)) => {
next_key = Some(TableIndexType::CHECKSUM256(Checksum256::from_bytes(hex_to_bytes(&next_key_str).as_slice()).unwrap()));
next_key = Some(TableIndexType::CHECKSUM256(
Checksum256::from_bytes(hex_to_bytes(&next_key_str).as_slice()).unwrap(),
));
}
Some(TableIndexType::FLOAT64(_)) => {
next_key = Some(TableIndexType::FLOAT64(next_key_str.parse().unwrap()));
Expand Down
8 changes: 3 additions & 5 deletions crates/antelope/src/api/v1/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde::{Deserialize, Deserializer, Serialize};
use serde_json::{json, Value};
use std::fmt;
use std::mem::discriminant;
use digest::block_buffer::Block;

use crate::chain::abi::ABI;
use crate::chain::public_key::PublicKey;
Expand All @@ -16,8 +15,8 @@ use crate::chain::{
authority::Authority,
block_id::{deserialize_block_id, deserialize_optional_block_id, BlockId},
checksum::{deserialize_checksum256, Checksum160, Checksum256},
signature::deserialize_signature,
name::{deserialize_name, deserialize_optional_name, deserialize_vec_name, Name},
signature::deserialize_signature,
time::{deserialize_optional_timepoint, deserialize_timepoint, TimePoint, TimePointSec},
transaction::TransactionHeader,
varint::VarUint32,
Expand Down Expand Up @@ -364,7 +363,7 @@ impl TableIndexType {
TableIndexType::CHECKSUM160(value) => json!(value.as_string()),
}
}

pub fn get_key_type(&self) -> Value {
match self {
TableIndexType::NAME(_) => Value::String("name".to_string()),
Expand Down Expand Up @@ -411,7 +410,7 @@ impl GetTableRowsParams {
if let Some(reverse) = &self.reverse {
req.insert("reverse", Value::Bool(*reverse));
}

if self.lower_bound.is_some() || self.upper_bound.is_some() {
if self.upper_bound.is_none() {
let lower = self.lower_bound.as_ref().unwrap();
Expand All @@ -435,7 +434,6 @@ impl GetTableRowsParams {
if let Some(index_position) = &self.index_position {
req.insert("index_position", index_position.to_json());
}

}

json!(req).to_string()
Expand Down
5 changes: 4 additions & 1 deletion crates/antelope/src/chain/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::fmt::{Display, Formatter};
use ecdsa::RecoveryId;
use k256::Secp256k1;
use p256::NistP256;
use serde::{de::{self, Visitor}, Deserialize, Deserializer, Serialize};
use serde::{
de::{self, Visitor},
Deserialize, Deserializer, Serialize,
};

use crate::{
base58,
Expand Down
16 changes: 7 additions & 9 deletions crates/antelope/src/serializer/packer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,19 @@ pub struct Float128 {

impl Float128 {
///

Check failure on line 307 in crates/antelope/src/serializer/packer.rs

View workflow job for this annotation

GitHub Actions / Clippy

empty doc comment

Check failure on line 307 in crates/antelope/src/serializer/packer.rs

View workflow job for this annotation

GitHub Actions / Clippy

empty doc comment
pub fn new(data: [u8;16]) -> Self {
Self {
data: data
}
pub fn new(data: [u8; 16]) -> Self {
Self { data }
}

///

Check failure on line 312 in crates/antelope/src/serializer/packer.rs

View workflow job for this annotation

GitHub Actions / Clippy

empty doc comment

Check failure on line 312 in crates/antelope/src/serializer/packer.rs

View workflow job for this annotation

GitHub Actions / Clippy

empty doc comment
pub fn data(&self) -> &[u8; 16] {
return &self.data;
&self.data
}
}

impl Packer for Float128 {
fn size(&self) -> usize {
return 16;
16
}

fn pack(&self, enc: &mut Encoder) -> usize {
Expand All @@ -332,7 +330,7 @@ impl Packer for Float128 {
let size = self.size();
assert!(raw.len() >= size, "Float128.unpack: buffer overflow!");
slice_copy(&mut self.data, &raw[..size]);
return self.size();
self.size()
}
}

Expand Down Expand Up @@ -470,8 +468,8 @@ where

/// Implement `Packer` for `Box<T>` type.
impl<T> Packer for Box<T>
where
T: Packer + Default,
where
T: Packer + Default,
{
/// Returns the size of this value in bytes.
fn size(&self) -> usize {
Expand Down
22 changes: 14 additions & 8 deletions crates/antelope/tests/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use antelope::api::client::DefaultProvider;
use antelope::api::v1::structs::{ErrorResponse, IndexPosition, TableIndexType};
use antelope::{
api::{
Expand All @@ -9,8 +10,6 @@ use antelope::{
serializer::{Decoder, Encoder, Packer},
StructPacker,
};
use antelope::api::client::DefaultProvider;
use antelope::util::bytes_to_hex;

mod utils;
use utils::mock_provider::MockProvider;
Expand Down Expand Up @@ -368,8 +367,6 @@ pub async fn chain_get_table_rows() {
// assert.equal(Number(res2.rows[1].balance).toFixed(6), (0.02566).toFixed(6))
}



#[tokio::test]
pub async fn secondary_index() {
#[derive(Clone, Eq, PartialEq, Default, Debug, StructPacker)]
Expand All @@ -381,8 +378,14 @@ pub async fn secondary_index() {

let mock_provider = MockProvider {};

Check warning on line 379 in crates/antelope/tests/client.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `mock_provider`

Check warning on line 379 in crates/antelope/tests/client.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `mock_provider`
//let client = APIClient::custom_provider(mock_provider).unwrap();
let mut client = APIClient::<DefaultProvider>::default_provider_debug(String::from("https://testnet.telos.caleos.io"), true).unwrap();
let checksum = Checksum256::from_hex("dc3264876b721aac60fe7270684c58bcd7e2c9e98ccdfdf4ed960a70b94fad32").unwrap();
let client = APIClient::<DefaultProvider>::default_provider_debug(
String::from("https://testnet.telos.caleos.io"),
true,
)
.unwrap();
let checksum =
Checksum256::from_hex("dc3264876b721aac60fe7270684c58bcd7e2c9e98ccdfdf4ed960a70b94fad32")
.unwrap();

let res1 = client
.v1_chain
Expand All @@ -401,7 +404,6 @@ pub async fn secondary_index() {
.await
.unwrap();


// "cbcbbc9c75ab9df67dbf6809a57396769c7d38bf922346c908726016bbc28069"
// "c8b2bb18bf9e660d4dbe02ffd63a99e1787ad39e805f80454875818b810b4dad"
// "0d53b3c0bc34ffefe4f605530fab2d4f567b894fe957034ac2361c63dabf82d1"
Expand Down Expand Up @@ -441,5 +443,9 @@ pub async fn secondary_index() {
}

assert_eq!(res1.rows.len(), 1, "Should get exactly 1 row back");
assert_eq!(res1.rows[0].proof_digest.as_string(), checksum.as_string(), "Should get back the matching proof_digest");
assert_eq!(
res1.rows[0].proof_digest.as_string(),
checksum.as_string(),
"Should get back the matching proof_digest"
);
}
2 changes: 1 addition & 1 deletion crates/antelope/tests/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ fn variant() {
MyVariant::StructOption(opt) => {
assert!(opt.is_some(), "Option should be Some");
let my_struct = opt.as_ref().unwrap();
assert_eq!(my_struct.field1, true);
assert!(my_struct.field1);
}
_ => {
panic!("Expected MyUint8");
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn enum_packer_macro(input: TokenStream) -> TokenStream {

let gen = match input.data {
syn::Data::Enum(data_enum) => {
let size_variants = data_enum.variants.iter().enumerate().map(|(_i, variant)| {
let size_variants = data_enum.variants.iter().map(|variant| {
let variant_ident = &variant.ident;
match &variant.fields {
Fields::Unnamed(fields) => {
Expand Down

0 comments on commit 4a0ed13

Please sign in to comment.