diff --git a/Cargo.lock b/Cargo.lock index 0d9044ee..d89de8ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2544,7 +2544,7 @@ dependencies = [ [[package]] name = "orga" version = "0.3.1" -source = "git+https://github.com/nomic-io/orga.git?rev=f35f1f6be228345e6e3a5d8617e049c6c203c8d1#f35f1f6be228345e6e3a5d8617e049c6c203c8d1" +source = "git+https://github.com/nomic-io/orga.git?rev=38682a1eafc9c3566aa5de4601a1aff06eb79c4f#38682a1eafc9c3566aa5de4601a1aff06eb79c4f" dependencies = [ "abci2", "async-trait", @@ -2605,7 +2605,7 @@ dependencies = [ [[package]] name = "orga-macros" version = "0.3.1" -source = "git+https://github.com/nomic-io/orga.git?rev=f35f1f6be228345e6e3a5d8617e049c6c203c8d1#f35f1f6be228345e6e3a5d8617e049c6c203c8d1" +source = "git+https://github.com/nomic-io/orga.git?rev=38682a1eafc9c3566aa5de4601a1aff06eb79c4f#38682a1eafc9c3566aa5de4601a1aff06eb79c4f" dependencies = [ "darling", "heck 0.3.3", diff --git a/Cargo.toml b/Cargo.toml index 2871cc79..bf573a83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ default-run = "nomic" [dependencies] bitcoin = { version = "0.29.2", features = ["serde", "rand"] } -orga = { git = "https://github.com/nomic-io/orga.git", rev = "f35f1f6be228345e6e3a5d8617e049c6c203c8d1", features = [ +orga = { git = "https://github.com/nomic-io/orga.git", rev = "38682a1eafc9c3566aa5de4601a1aff06eb79c4f", features = [ "merk-verify", ] } thiserror = "1.0.30" diff --git a/rest/Cargo.lock b/rest/Cargo.lock index 1f81b72d..1d20c762 100644 --- a/rest/Cargo.lock +++ b/rest/Cargo.lock @@ -2518,7 +2518,7 @@ dependencies = [ [[package]] name = "orga" version = "0.3.1" -source = "git+https://github.com/nomic-io/orga.git?rev=f35f1f6be228345e6e3a5d8617e049c6c203c8d1#f35f1f6be228345e6e3a5d8617e049c6c203c8d1" +source = "git+https://github.com/nomic-io/orga.git?rev=38682a1eafc9c3566aa5de4601a1aff06eb79c4f#38682a1eafc9c3566aa5de4601a1aff06eb79c4f" dependencies = [ "abci2", "async-trait", @@ -2579,7 +2579,7 @@ dependencies = [ [[package]] name = "orga-macros" version = "0.3.1" -source = "git+https://github.com/nomic-io/orga.git?rev=f35f1f6be228345e6e3a5d8617e049c6c203c8d1#f35f1f6be228345e6e3a5d8617e049c6c203c8d1" +source = "git+https://github.com/nomic-io/orga.git?rev=38682a1eafc9c3566aa5de4601a1aff06eb79c4f#38682a1eafc9c3566aa5de4601a1aff06eb79c4f" dependencies = [ "darling", "heck 0.3.3", diff --git a/rest/src/main.rs b/rest/src/main.rs index 23c4ea5a..93ca0ebd 100644 --- a/rest/src/main.rs +++ b/rest/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate rocket; +use chrono::{Utc, TimeZone}; use nomic::{ app::{InnerApp, Nom}, bitcoin::Nbtc, @@ -468,25 +469,26 @@ async fn staking_delegators_delegations(address: &str) -> Value { .await .unwrap(); - let total_staked: u64 = delegations - .iter() - .map(|(_, d)| -> u64 { d.staked.into() }) - .sum(); + let mut entries = vec![]; - json!({ - "delegation_responses": [ - { + for (validator_address, delegation) in delegations { + entries.push(json!({ "delegation": { - "delegator_address": "", - "validator_address": "", - "shares": "0" + "delegator_address": address.to_string(), + "validator_address": validator_address.to_string(), + "shares": delegation.staked.to_string(), }, "balance": { "denom": "unom", - "amount": total_staked.to_string(), - } - } - ], "pagination": { "next_key": null, "total": "0" } }) + "amount": delegation.staked.to_string(), + }, + })) + } + + json!({ + "delegation_responses": entries, + "pagination": { "next_key": null, "total": entries.len().to_string() } + }) } #[get("/staking/delegators/
/delegations")] @@ -534,8 +536,8 @@ async fn staking_delegators_unbonding_delegations(address: &str) -> Value { entries.push(json!({ "creation_height": "0", // TODO "completion_time": t, // TODO - "initial_balance": "0", // TODO - "balance": "0" // TODO + "initial_balance": unbond.amount.to_string(), + "balance": unbond.amount.to_string() })) } unbonds.push(json!({ @@ -553,6 +555,106 @@ fn staking_delegators_unbonding_delegations_2(_address: &str) -> Value { json!({ "height": "0", "result": [] }) } +#[get("/cosmos/staking/v1beta1/validators//delegations")] +async fn staking_validators_delegations(address: &str) -> Value { + let validator_address: Address = address.parse().unwrap(); + let delegations: Vec<(Address, DelegationInfo)> = app_client() + .query(|app: InnerApp| app.staking.validator_delegations(validator_address)) + .await + .unwrap(); + + let mut entries = vec![]; + + for (delegator_address, delegation) in delegations { + entries.push(json!({ + "delegation": { + "delegator_address": delegator_address.to_string(), + "validator_address": validator_address.to_string(), + "shares": delegation.staked.to_string(), + }, + "balance": { + "denom": "unom", + "amount": delegation.staked.to_string(), + }, + })) + } + + json!({ + "delegation_responses": entries, + "pagination": { "next_key": null, "total": entries.len().to_string() } + }) +} + +#[get("/cosmos/staking/v1beta1/validators/