Skip to content

Commit

Permalink
add ram bytes based on dbOps
Browse files Browse the repository at this point in the history
(not available yet)
  • Loading branch information
YaroShkvorets committed Mar 29, 2023
1 parent d038729 commit 5ed9216
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 11 additions & 0 deletions accounts/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Name = String;
type PublicKey = String;
type Uint16 = u16;
type Uint32 = u32;
type Int64 = i64;


macro_rules! impl_try_from_str {
Expand Down Expand Up @@ -91,6 +92,16 @@ pub struct WaitWeight {
}
impl_try_from_str!(WaitWeight);

#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct UserResources {
pub owner: Name,
pub net_weight: Asset,
pub cpu_weight: Asset,
pub ram_bytes: Int64,
}
impl_try_from_str!(UserResources);


#[cfg(test)]
mod tests {
Expand Down
21 changes: 17 additions & 4 deletions accounts/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,31 @@ fn map_accounts(block: Block) -> Result<accounts::Accounts, Error> {
}

// parse buy RAM actions (normally one transaction per new account created)
// TODO: instead, get the RAM usage and CPU/NET staked from dbOps (this will also cover buyram)
// TODO: instead, get the RAM usage and CPU/NET staked from dbOps (uncomment below) BLOCKED: need to replay blockchain to get dbOps
if action.account == "eosio" && action.name == "buyrambytes" {
if let Ok(params) = abi::Buyrambytes::try_from(action.json_data.as_str()) {
if let Some(last) = accounts.last_mut() {
for acc in accounts.iter_mut() {
log::debug!("buyrambytes={:?}", params);
if last.name == params.receiver {
last.ram_bytes += params.bytes;
if acc.name == params.receiver {
acc.ram_bytes += params.bytes
}
}
}
}
}

// for db_op in &trx.db_ops {
// if db_op.code == "eosio" && db_op.table_name == "userres" {
// log::info!("db_op={:?}", db_op);
// if let Ok(params) = abi::UserResources::try_from(db_op.new_data_json.as_str()) {
// for acc in accounts.iter_mut() {
// if acc.name == params.owner {
// acc.ram_bytes = params.ram_bytes as u32
// }
// }
// }
// }
// }
}
Ok(accounts::Accounts { accounts })
}

0 comments on commit 5ed9216

Please sign in to comment.