Skip to content

Commit

Permalink
dbg
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jun 27, 2024
1 parent 5e60597 commit 89ee914
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,50 @@ impl TendermintCoin {
timeout_height: u64,
memo: String,
) -> cosmrs::Result<SerializedUnsignedTx> {
fn remove_type(msg: &mut Json) {
match msg {
Json::Array(ref mut v) => v.iter_mut().for_each(remove_type),
Json::Object(ref mut obj) => {
obj.remove("@type");
obj.values_mut().for_each(remove_type);
obj.iter_mut().for_each(|(k, v)| {
if k.ends_with("_id") {
*v = Json::String(v.to_string())
}
if k.ends_with("_timestamp") {
*v = Json::String(v.to_string())
}
if v.is_null() {
*v = serde_json::json!({});
}
})
},
_ => {},
}
}

fn amino_json(mut msg: Json) -> Json {
let map = msg.as_object_mut().unwrap();

let (_, msg_type) = map.remove_entry("@type").unwrap();
let msg_type = msg_type.as_str().unwrap();
remove_type(&mut msg);

let split_msg_type = msg_type.rsplit_once('.').unwrap().1;

let split_msg_type = match split_msg_type {
"MsgWithdrawDelegatorReward" => "MsgWithdrawDelegationReward",
_ => split_msg_type,
};

let msg_type = format!("cosmos-sdk/{split_msg_type}");

serde_json::json!({
"type": msg_type,
"value": msg,
})
}

let tx_body = tx::Body::new(vec![tx_payload], memo.clone(), timeout_height as u32).into_proto();
let body_bytes = tx_body.to_bytes()?;

Expand All @@ -1308,6 +1352,7 @@ impl TendermintCoin {

serde_json::to_value(t).expect("TODO")
})
.map(amino_json)
.collect();

/// Serde fails to serialize u128 in `Coin`, this is a workaround type using u64.
Expand Down

0 comments on commit 89ee914

Please sign in to comment.