diff --git a/web3_proxy/src/frontend/users/payment.rs b/web3_proxy/src/frontend/users/payment.rs index a2293dca..481bb14c 100644 --- a/web3_proxy/src/frontend/users/payment.rs +++ b/web3_proxy/src/frontend/users/payment.rs @@ -82,23 +82,21 @@ pub async fn user_deposits_get( .await?; // Return the response, all except the user ... - let mut response = HashMap::new(); let receipts = receipts .into_iter() .map(|x| { - let mut out = HashMap::new(); - out.insert("amount", serde_json::Value::String(x.amount.to_string())); - out.insert("chain_id", serde_json::Value::Number(x.chain_id.into())); - out.insert("tx_hash", serde_json::Value::String(x.tx_hash)); - // TODO: log_index - out + json!({ + "amount": x.amount, + "chain_id": x.chain_id, + "tx_hash": x.tx_hash, + }) }) .collect::>(); - response.insert( - "user", - json!(format!("{:?}", Address::from_slice(&user.address))), - ); - response.insert("deposits", json!(receipts)); + + let response = json!({ + "user": Address::from_slice(&user.address), + "deposits": receipts, + }); Ok(Json(response).into_response()) } diff --git a/web3_proxy/src/frontend/users/subuser.rs b/web3_proxy/src/frontend/users/subuser.rs index 9adfeb94..a3fd2617 100644 --- a/web3_proxy/src/frontend/users/subuser.rs +++ b/web3_proxy/src/frontend/users/subuser.rs @@ -68,17 +68,19 @@ pub async fn get_keys_as_subuser( // Now return the list let response_json = json!({ - "subuser": format!("{:?}", Address::from_slice(&subuser.address)), + "subuser": Address::from_slice(&subuser.address), "rpc_keys": rpc_key_entities .into_iter() .flat_map(|(rpc_key, rpc_owner)| { match rpc_owner { Some(inner_rpc_owner) => { - let mut tmp = HashMap::new(); - tmp.insert("rpc-key", serde_json::Value::String(Ulid::from(rpc_key.secret_key).to_string())); - tmp.insert("rpc-owner", serde_json::Value::String(format!("{:?}", Address::from_slice(&inner_rpc_owner.address)))); - tmp.insert("role", serde_json::Value::String(format!("{:?}", secondary_user_entities.get(&rpc_key.id).unwrap().role))); // .to_string() returns ugly "'...'" - Some(tmp) + let x = json!({ + "rpc-key": Ulid::from(rpc_key.secret_key), + "rpc-owner": Address::from_slice(&inner_rpc_owner.address), + // TODO: prettier serialize for role + "role": format!("{:?}", secondary_user_entities.get(&rpc_key.id).unwrap().role), + }); + Some(x) }, None => { // error!("Found RPC secret key with no user!".to_owned()); @@ -148,16 +150,16 @@ pub async fn get_subusers( // Now return the list let response_json = json!({ - "caller": format!("{:?}", Address::from_slice(&user.address)), + "caller": Address::from_slice(&user.address), "rpc_key": rpc_key, "subusers": subusers .into_iter() .map(|subuser| { - let mut tmp = HashMap::new(); - // .encode_hex() - tmp.insert("address", serde_json::Value::String(format!("{:?}", Address::from_slice(&subuser.address)))); - tmp.insert("role", serde_json::Value::String(format!("{:?}", secondary_user_entities.get(&subuser.id).unwrap().role))); - json!(tmp) + json!({ + "address": Address::from_slice(&subuser.address), + // TODO: prettier serialize for role + "role": format!("{:?}", secondary_user_entities.get(&subuser.id).unwrap().role), + }) }) .collect::>(), }); diff --git a/web3_proxy/src/jsonrpc.rs b/web3_proxy/src/jsonrpc.rs index 1d57d197..84353a21 100644 --- a/web3_proxy/src/jsonrpc.rs +++ b/web3_proxy/src/jsonrpc.rs @@ -36,9 +36,7 @@ impl JsonRpcId { pub fn to_raw_value(self) -> Box { // TODO: is this a good way to do this? we should probably use references match self { - Self::None => { - to_raw_value(&json!(None::>)).expect("null id should always work") - } + Self::None => Default::default(), Self::Number(x) => { serde_json::from_value(json!(x)).expect("number id should always work") }