nash_protocol/protocol/sign_states/
response.rs1use super::types::{
4 ContractBalanceState, RecycledOrder, ServerSignedData, SignStatesResponse, StateData,
5};
6use crate::graphql::sign_states;
7use crate::types::Blockchain;
8
9impl From<sign_states::ResponseData> for SignStatesResponse {
12 fn from(res: sign_states::ResponseData) -> Self {
13 let mut recycled_orders = Vec::new();
14 let mut server_signed_states = Vec::new();
15 let mut states = Vec::new();
16 let data = res.sign_states;
17 for state in &data.recycled_orders {
18 recycled_orders.push(RecycledOrder(StateData {
19 payload_hash: state.payload_hash.clone(),
20 payload: state.payload.clone(),
21 blockchain: (&state.blockchain).into(),
22 }));
23 }
24 for state in &data.server_signed_states {
25 server_signed_states.push(ServerSignedData {
26 signed_data: state.message.clone(),
27 blockchain: (&state.blockchain).into(),
28 });
29 }
30 for state in &data.states {
31 states.push(ContractBalanceState(StateData {
32 payload_hash: state.payload_hash.clone(),
33 payload: state.payload.clone(),
34 blockchain: (&state.blockchain).into(),
35 }));
36 }
37 Self {
38 recycled_orders,
39 server_signed_states,
40 states,
41 }
42 }
43}
44
45impl From<&sign_states::Blockchain> for Blockchain {
46 fn from(chain: &sign_states::Blockchain) -> Self {
47 match chain {
48 sign_states::Blockchain::ETH => Self::Ethereum,
49 sign_states::Blockchain::NEO => Self::NEO,
50 sign_states::Blockchain::BTC => Self::Bitcoin,
51 sign_states::Blockchain::Other(_) => {
53 panic!("Nash API is serving non-supported blockchain")
54 }
55 }
56 }
57}