daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate serde_json; // 1.0.33
  2. #[macro_use]
  3. extern crate serde_derive; // 1.0.80
  4.  
  5. #[derive(Serialize, Deserialize, Debug, Clone)]
  6. #[serde(tag = "type")]
  7. pub enum IpcResponse {
  8.     GetRegistrationParams { id: String, result: IpcResults },
  9.     IdentityChallenge { id: String, nonce: String, signature: String, },
  10.     GetTip { id: String , result: IpcDelta, },
  11.     GetTips {id: String, result: IpcResults },
  12.     GetAllTips { id: String, result: Vec<IpcDelta> },
  13.     GetAllAddrs { id: String, result: IpcResults },
  14.     GetDelta { id: String, result: IpcResults },
  15.     GetDeltas { id: String, result: IpcResults },
  16.     GetContract { id: String, result: IpcResults },
  17.     UpdateNewContract { id: String, address: String, result: IpcResults },
  18.     UpdateDeltas { id: String, general_status: String, result: IpcResults },
  19. }
  20.  
  21. #[derive(Serialize, Deserialize, Debug, Clone)]
  22. #[serde(rename_all = "lowercase")]
  23. #[serde(rename = "result")]
  24. pub enum IpcResults {
  25.     Addresses(Vec<String>),
  26.     Delta(String),
  27.     Deltas(Vec<IpcDelta>),
  28.     Bytecode(String),
  29.     Status(String),
  30.     Tips(Vec<IpcDelta>),
  31.     RegistrationParams { #[serde(rename = "signingKey")] sigining_key: String, quote: String },
  32. }
  33.  
  34. #[derive(Serialize, Deserialize, Debug, Clone)]
  35. pub struct IpcDelta {
  36.     pub address: Option<String>,
  37.     pub key: u32,
  38.     pub delta: Option<String>,
  39. }
  40.  
  41.  
  42.  
  43. fn main() {
  44.     let a = r#"{
  45.     "id" : "gdfgergferfd",
  46.     "type" : "GetRegistrationParams",
  47.     "result" : {
  48.         "signingKey": "fdsfew4f34",
  49.         "quote": "fd43jkr5lwkrmd"
  50.     }
  51. }"#;
  52.  
  53.     let b: IpcResponse = serde_json::from_str(&a).unwrap();
  54.     println!("{:#?}", b);
  55. }
  56.  
  57. /*
  58. Until now the JSONs looked like:
  59. {
  60.     id : <unique_request_id>
  61.     type : GetTips
  62.     result : {
  63.         tips : [Array<{address,key,delta}>]
  64.     }
  65. }
  66.  
  67. Now they look like this too:
  68. {
  69.    id : <unique_request_id>
  70.    type : GetTip
  71.    result : {
  72.        key : [],
  73.        delta : [],
  74.    }
  75. }
  76. How do I do that?
  77. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top