Skip to content

Commit

Permalink
Fix clippy warnings in codec module (#183)
Browse files Browse the repository at this point in the history
* Fix clippy warnings in codec module

* Use DateTime instead of NaiveDateTime

* Update network-runner version for CI
  • Loading branch information
richardpringle authored Apr 3, 2024
1 parent 58f3ed6 commit 1bfa6d5
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 38 deletions.
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/codec/serde/base64_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
.map_err(serde::de::Error::custom)
}

pub struct Base64Bytes(Vec<u8>);
pub struct Base64Bytes;

impl SerializeAs<Vec<u8>> for Base64Bytes {
fn serialize_as<S>(x: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/codec/serde/hex_0x_big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ where
from_hex_to_big_int(&s).map_err(serde::de::Error::custom)
}

pub struct Hex0xBigInt(BigInt);
pub struct Hex0xBigInt;

impl SerializeAs<BigInt> for Hex0xBigInt {
fn serialize_as<S>(x: &BigInt, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
H160::from_str(s).map_err(serde::de::Error::custom)
}

pub struct Hex0xH160(H160);
pub struct Hex0xH160;

impl SerializeAs<H160> for Hex0xH160 {
fn serialize_as<S>(x: &H160, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
H256::from_str(s).map_err(serde::de::Error::custom)
}

pub struct Hex0xH256(H256);
pub struct Hex0xH256;

impl SerializeAs<H256> for Hex0xH256 {
fn serialize_as<S>(x: &H256, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
U256::from_str_radix(s, 16).map_err(serde::de::Error::custom)
}

pub struct Hex0xU256(U256);
pub struct Hex0xU256;

impl SerializeAs<U256> for Hex0xU256 {
fn serialize_as<S>(x: &U256, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/codec/serde/hex_0x_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
u64::from_str_radix(s, 16).map_err(serde::de::Error::custom)
}

pub struct Hex0xU64(u64);
pub struct Hex0xU64;

impl SerializeAs<u64> for Hex0xU64 {
fn serialize_as<S>(x: &u64, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/codec/serde/hex_0x_utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
Utxo::from_hex(&s).map_err(serde::de::Error::custom)
}

pub struct Hex0xUtxo(Utxo);
pub struct Hex0xUtxo;

impl SerializeAs<Utxo> for Hex0xUtxo {
fn serialize_as<S>(x: &Utxo, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/codec/serde/ip_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
}
}

pub struct IpPort(SocketAddr);
pub struct IpPort;

impl SerializeAs<SocketAddr> for IpPort {
fn serialize_as<S>(x: &SocketAddr, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/codec/serde/rfc_3339.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
}
}

pub struct DateTimeUtc(DateTime<Utc>);
pub struct DateTimeUtc;

impl SerializeAs<DateTime<Utc>> for DateTimeUtc {
fn serialize_as<S>(x: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
jsonrpc::client::p as client_p,
key, platformvm, txs, units,
};
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use chrono::{DateTime, Utc};
use tokio::time::{sleep, Duration, Instant};

/// Represents P-chain "AddPermissionlessValidator" transaction.
Expand Down Expand Up @@ -64,15 +64,13 @@ where
.as_secs();

let start_time = now_unix + 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(start_time as i64, 0).unwrap();
let start_time = Utc.from_utc_datetime(&naive_dt);
let start_time = DateTime::from_timestamp(start_time as i64, 0).unwrap();

// 100-day
// must be smaller than the primary network default
// otherwise "staking period must be a subset of the primary network"
let end_time = now_unix + 100 * 24 * 60 * 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(end_time as i64, 0).unwrap();
let end_time = Utc.from_utc_datetime(&naive_dt);
let end_time = DateTime::from_timestamp(end_time as i64, 0).unwrap();

Self {
inner: p.clone(),
Expand Down Expand Up @@ -135,14 +133,12 @@ where
.as_secs();

let start_time = now_unix + offset_seconds;
let naive_dt = NaiveDateTime::from_timestamp_opt(start_time as i64, 0).unwrap();
let start_time = Utc.from_utc_datetime(&naive_dt);
let start_time = DateTime::from_timestamp(start_time as i64, 0).unwrap();

// must be smaller than the primary network default
// otherwise "staking period must be a subset of the primary network"
let end_time = now_unix + days * 24 * 60 * 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(end_time as i64, 0).unwrap();
let end_time = Utc.from_utc_datetime(&naive_dt);
let end_time = DateTime::from_timestamp(end_time as i64, 0).unwrap();

self.start_time = start_time;
self.end_time = end_time;
Expand Down
14 changes: 5 additions & 9 deletions crates/avalanche-types/src/wallet/p/add_subnet_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
jsonrpc::client::p as client_p,
key, platformvm, txs,
};
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use chrono::{DateTime, Utc};
use tokio::time::{sleep, Duration, Instant};

/// Represents P-chain "AddSubnetValidator" transaction.
Expand Down Expand Up @@ -52,16 +52,14 @@ where
.as_secs();

let start_time = now_unix + 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(start_time as i64, 0).unwrap();
let start_time = Utc.from_utc_datetime(&naive_dt);
let start_time = DateTime::from_timestamp(start_time as i64, 0).unwrap();

// 14-day + 5-min
// must be smaller than the primary network default
// otherwise "staking period must be a subset of the primary network"
// ref. "Validator.BoundedBy"
let end_time = now_unix + 15 * 24 * 60 * 60 + 5 * 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(end_time as i64, 0).unwrap();
let end_time = Utc.from_utc_datetime(&naive_dt);
let end_time = DateTime::from_timestamp(end_time as i64, 0).unwrap();

Self {
inner: p.clone(),
Expand Down Expand Up @@ -122,14 +120,12 @@ where
.as_secs();

let start_time = now_unix + offset_seconds;
let naive_dt = NaiveDateTime::from_timestamp_opt(start_time as i64, 0).unwrap();
let start_time = Utc.from_utc_datetime(&naive_dt);
let start_time = DateTime::from_timestamp(start_time as i64, 0).unwrap();

// must be smaller than the primary network default
// otherwise "staking period must be a subset of the primary network"
let end_time = now_unix + days * 24 * 60 * 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(end_time as i64, 0).unwrap();
let end_time = Utc.from_utc_datetime(&naive_dt);
let end_time = DateTime::from_timestamp(end_time as i64, 0).unwrap();

self.start_time = start_time;
self.end_time = end_time;
Expand Down
14 changes: 5 additions & 9 deletions crates/avalanche-types/src/wallet/p/add_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
jsonrpc::client::p as client_p,
key, platformvm, txs, units,
};
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use chrono::{DateTime, Utc};
use tokio::time::{sleep, Duration, Instant};

/// Represents P-chain "AddValidator" transaction.
Expand Down Expand Up @@ -60,17 +60,15 @@ where
.as_secs();

let start_time = now_unix + 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(start_time as i64, 0).unwrap();
let start_time = Utc.from_utc_datetime(&naive_dt);
let start_time = DateTime::from_timestamp(start_time as i64, 0).unwrap();

// 15-day + 5-min
// must be smaller than the primary network default
// otherwise "staking period must be a subset of the primary network"
// 15 that subnet validator defaults can be bounded within
// ref. "Validator.BoundedBy"
let end_time = now_unix + 14 * 24 * 60 * 60 + 5 * 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(end_time as i64, 0).unwrap();
let end_time = Utc.from_utc_datetime(&naive_dt);
let end_time = DateTime::from_timestamp(end_time as i64, 0).unwrap();

Self {
inner: p.clone(),
Expand Down Expand Up @@ -124,14 +122,12 @@ where
.as_secs();

let start_time = now_unix + offset_seconds;
let naive_dt = NaiveDateTime::from_timestamp_opt(start_time as i64, 0).unwrap();
let start_time = Utc.from_utc_datetime(&naive_dt);
let start_time = DateTime::from_timestamp(start_time as i64, 0).unwrap();

// must be smaller than the primary network default
// otherwise "staking period must be a subset of the primary network"
let end_time = now_unix + days * 24 * 60 * 60;
let naive_dt = NaiveDateTime::from_timestamp_opt(end_time as i64, 0).unwrap();
let end_time = Utc.from_utc_datetime(&naive_dt);
let end_time = DateTime::from_timestamp(end_time as i64, 0).unwrap();

self.start_time = start_time;
self.end_time = end_time;
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.avalanchego-byzantine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo NETWORK_RUNNER_AVALANCHEGO_PATH: "${NETWORK_RUNNER_AVALANCHEGO_PATH}"
# https://github.com/ava-labs/avalanche-network-runner
# TODO: use "go install -v github.com/ava-labs/avalanche-network-runner/cmd/avalanche-network-runner@v${NETWORK_RUNNER_VERSION}"
GOOS=$(go env GOOS)
NETWORK_RUNNER_VERSION=1.7.1
NETWORK_RUNNER_VERSION=1.7.7
DOWNLOAD_PATH=/tmp/avalanche-network-runner.tar.gz
DOWNLOAD_URL=https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_linux_amd64.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.avalanchego-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ E2E_FLAGS=${E2E_FLAGS:-"--keys-to-generate 30"}
# https://github.com/ava-labs/avalanche-network-runner
# TODO: use "go install -v github.com/ava-labs/avalanche-network-runner/cmd/avalanche-network-runner@v${NETWORK_RUNNER_VERSION}"
GOOS=$(go env GOOS)
NETWORK_RUNNER_VERSION=1.7.1
NETWORK_RUNNER_VERSION=1.7.7
DOWNLOAD_PATH=/tmp/avalanche-network-runner.tar.gz
DOWNLOAD_URL=https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_linux_amd64.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
Expand Down

0 comments on commit 1bfa6d5

Please sign in to comment.