Skip to content

Can't parse Cosmos transactions with empty Denom anymore #477

@penso

Description

@penso

This PR #470 breaks parsing successful Stargaze transactions (and probably other chains) like this one (mintscan) with:

cosmrs::Tx::from_bytes error: invalid denomination: ""

Anything earlier than this commit works. This code sample will show you how to reproduce the issue:

#[test]
pub fn denom_error() {
    unsafe {
        std::env::set_var("RUST_BACKTRACE", "1");
    }

    let block_url = "https://rpc.full-nodes.stargaze-1.stargaze.build/block?height=1931505";

    let response = reqwest::blocking::get(block_url).expect("Can't fetch block");

    let data: serde_json::Value = response.json().expect("Can't get block JSON");

    let Some(txs) = data
        .get("result")
        .and_then(|c| c.get("block"))
        .and_then(|c| c.get("data"))
        .and_then(|c| c.get("txs"))
        .and_then(|c| c.as_array())
    else {
        return;
    };

    for (idx, tx) in txs.into_iter().enumerate() {
        let tx = tx.as_str().expect("Can't get tx str");

        #[allow(deprecated)]
        let bytes = base64::decode(tx).expect("Can't decode");

        let res = cosmrs::Tx::from_bytes(&bytes);
        let hash = sha256::digest(bytes.as_slice()).to_uppercase();

        match res {
            Ok(_) => {
                println!("[{}] [{hash}] ok", idx);
            }
            Err(e) => {
                println!("[{}] [{hash}] error: {:?}", idx, e);
                panic!("Transaction can't be parsed");
            }
        }
    }
}

Error:

   13 ---- denom_error stdout ----
   14 [0] [D15627C06F05575A6840B06631260AD563A6BD503CDA58F38AB35F76A10D9550] ok
   15 [1] [C810347BC8C97F5883C8213289DDBF3E526A8F392605EE5EB84D9AAC6ED06F8B] ok
   16 [2] [D3EFB0314EACB63C3689749D943A5F08D6FE804B83574800CA033BE932A88666] error: invalid denomination: ""
   17
   18 Location:
   19     /home/penso/.cargo/git/checkouts/cosmos-rust-5eb3768b2a88fb5e/ced74a7/cosmrs/src/base/denom.rs:36:60

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions