Skip to content

Commit

Permalink
fix anyhow visibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Dec 19, 2023
1 parent 914e86e commit 41f913e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions antelope.trxstats/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use substreams::errors::Error;
use substreams::errors::Error as SubError;
use substreams_antelope::Block;
use substreams_database_change::pb::database::DatabaseChanges;
use substreams_database_change::tables::Tables as DatabaseChangeTables;
Expand All @@ -16,7 +16,7 @@ struct Params {
action_count: u32,
}

fn parse_params(input: String) -> Result<Params, Error> {
fn parse_params(input: String) -> Result<Params, SubError> {
let mut result = Params::default();
if input.is_empty() {
return Ok(result);
Expand All @@ -25,26 +25,26 @@ fn parse_params(input: String) -> Result<Params, Error> {
for param in input.split('&') {
let (key, value) = param
.split_once('=')
.ok_or_else(|| substreams::errors::Error::Unexpected(format!("Invalid parameter format: {}", param)))?;
.ok_or_else(|| SubError::Unexpected(format!("Invalid parameter format: {}", param)))?;
let parsed_value = value
.parse::<u32>()
.map_err(|_| substreams::errors::Error::Unexpected(format!("Invalid param value for key '{}'", key)))?;
.map_err(|_| SubError::Unexpected(format!("Invalid param value for key '{}'", key)))?;

match key {
"cpu_elapsed" => result.cpu_elapsed = parsed_value,
"net_elapsed" => result.net_elapsed = parsed_value,
"cpu_usage" => result.cpu_usage = parsed_value,
"net_usage" => result.net_usage = parsed_value,
"action_count" => result.action_count = parsed_value,
_ => return Err(substreams::errors::Error::Unexpected(format!("Unknown parameter: '{}'", key))),
_ => return Err(SubError::Unexpected(format!("Unknown parameter: '{}'", key))),
}
}

Ok(result)
}

#[substreams::handlers::map]
fn map_trxs(params: String, block: Block) -> Result<Transactions, Error> {
fn map_trxs(params: String, block: Block) -> Result<Transactions, SubError> {
let params = parse_params(params)?;
Ok(Transactions {
transactions: block
Expand Down Expand Up @@ -75,7 +75,7 @@ fn map_trxs(params: String, block: Block) -> Result<Transactions, Error> {
}

#[substreams::handlers::map]
fn db_out(trxs: Transactions) -> Result<DatabaseChanges, substreams::errors::Error> {
fn db_out(trxs: Transactions) -> Result<DatabaseChanges, SubError> {
let mut tables = DatabaseChangeTables::new();
trxs.transactions.into_iter().enumerate().for_each(|(i, trx)| {
tables
Expand Down

0 comments on commit 41f913e

Please sign in to comment.