Skip to content

Commit

Permalink
fix err
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Mar 15, 2024
1 parent 7a5d273 commit 72b5bc9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 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 SubstreamsError;
use substreams_antelope::pb::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, SubstreamsError> {
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(|| SubstreamsError::Unexpected(format!("Invalid parameter format: {}", param)))?;
let parsed_value = value
.parse::<u32>()
.map_err(|_| Error::Unexpected(format!("Invalid param value for key '{}'", key)))?;
.map_err(|_| SubstreamsError::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(Error::Unexpected(format!("Unknown parameter: '{}'", key))),
_ => return Err(SubstreamsError::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, SubstreamsError> {
let params = parse_params(params)?;
Ok(Transactions {
transactions: block
Expand Down

0 comments on commit 72b5bc9

Please sign in to comment.