nash_protocol/protocol/dh_fill_pool/
request.rs

1use crate::graphql;
2use graphql::dh_fill_pool;
3use graphql_client::GraphQLQuery;
4use nash_mpc::curves::traits::ECPoint;
5
6use super::{DhFillPoolRequest, K1FillPool, R1FillPool};
7use crate::types::Blockchain;
8
9impl DhFillPoolRequest {
10    /// Build a GraphQL request to get R values for MPC signing. These values can be for
11    /// `secp256k1` or `secp256r1` depending on `curve`. This sets the state `r1` or `k1`
12    /// in the client with the secret values associated with DH, which will be used on
13    /// a future request to `set_pool`
14    pub fn make_query(&self) -> graphql_client::QueryBody<dh_fill_pool::Variables> {
15        // FIXME: this is ugly
16        let dh_publics = match self {
17            Self::Bitcoin(K1FillPool {
18                publics,
19                secrets: _,
20            }) => publics.iter().map(|x| Some(x.to_hex())).collect(),
21            Self::Ethereum(K1FillPool {
22                publics,
23                secrets: _,
24            }) => publics.iter().map(|x| Some(x.to_hex())).collect(),
25            Self::NEO(R1FillPool {
26                publics,
27                secrets: _,
28            }) => publics.iter().map(|x| Some(x.to_hex())).collect(),
29        };
30        let dh_args = dh_fill_pool::Variables {
31            dh_publics,
32            blockchain: self.blockchain().into(),
33        };
34        graphql::DhFillPool::build_query(dh_args)
35    }
36}
37
38impl Into<dh_fill_pool::Blockchain> for Blockchain {
39    fn into(self) -> dh_fill_pool::Blockchain {
40        match self {
41            Blockchain::Ethereum => dh_fill_pool::Blockchain::ETH,
42            Blockchain::Bitcoin => dh_fill_pool::Blockchain::BTC,
43            Blockchain::NEO => dh_fill_pool::Blockchain::NEO,
44        }
45    }
46}