lint and fixes that rls missed cuz of the version change

This commit is contained in:
Bryan Stitt 2023-10-26 11:04:11 -07:00
parent 45c5d33130
commit 7bd44b01df
2 changed files with 30 additions and 18 deletions

@ -1093,7 +1093,7 @@ impl App {
.params()
.as_array()
.ok_or_else(|| Web3ProxyError::BadRequest("Unable to get array from params".into()))?
.get(0)
.first()
.ok_or_else(|| Web3ProxyError::BadRequest("Unable to get item 0 from params".into()))?
.as_str()
.ok_or_else(|| {
@ -1177,8 +1177,9 @@ impl App {
// no idea how we got an array here, but lets force this to just the txid
// TODO: think about this more
if value.get().starts_with('[') {
let backend_rpcs = web3_request
.backend_rpcs_used()
let backend_rpcs = web3_request.backend_rpcs_used();
let backend_rpcs = backend_rpcs
.iter()
.map(|x| x.name.as_str())
.collect::<Vec<_>>();
@ -1584,7 +1585,7 @@ impl App {
serde_json::Value::Array(params) => {
// TODO: make a struct and use serde conversion to clean this up
if params.len() != 1
|| !params.get(0).map(|x| x.is_string()).unwrap_or(false)
|| !params.first().map(|x| x.is_string()).unwrap_or(false)
{
// TODO: what error code?
// TODO: use Web3ProxyError::BadRequest

@ -7,7 +7,7 @@
//! TODO: script that queries influx and calculates observed relative costs
use migration::sea_orm::prelude::Decimal;
use std::{ops::Add, str::FromStr};
use std::{ops::Add, ops::Mul, str::FromStr};
use tracing::{trace, warn};
/// TODO: i don't like how we use this inside the config and also have it available publicly. we should only getting this value from the config
@ -44,6 +44,17 @@ where
}
}
impl<T> Mul<T> for ComputeUnit
where
T: Into<Decimal>,
{
type Output = Self;
fn mul(self, rhs: T) -> Self::Output {
Self(self.0 * rhs.into())
}
}
impl ComputeUnit {
/// costs can vary widely depending on method and chain
pub fn new(method: &str, chain_id: u64, response_bytes: u64) -> Self {
@ -155,31 +166,31 @@ impl ComputeUnit {
(_, "web3_bundlerVersion") => 15,
(_, "web3_sha3") => 15,
(_, "ots_getInternalOperations") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_hasCode") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_getTransactionError") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_traceTransaction") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_getBlockDetails") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_getBlockDetailsByHash") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_getBlockTransactions") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_searchTransactionsBefore") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_searchTransactionsAfter") => {
return Self::variable_price(chain_id, method, response_bytes) + 100
return Self::variable_price(chain_id, method, response_bytes) + 100;
}
(_, "ots_getTransactionBySenderAndNonce") => 1000,
(_, "ots_getContractCreator") => 1000,
@ -204,11 +215,11 @@ impl ComputeUnit {
{
// maybe charge extra since they are doing things they aren't supposed to
return Self::unimplemented();
warn!(%response_bytes, "unknown method {}", method);
return Self::unimplemented()
+ Self::variable_price(chain_id, method, response_bytes).0;
}
warn!(%response_bytes, "unknown method {}", method);
return Self::unimplemented()
+ Self::variable_price(chain_id, method, response_bytes).0;
}
};