Skip to content

Commit

Permalink
final changes to sv2_serde_json
Browse files Browse the repository at this point in the history
  • Loading branch information
Shourya742 committed Jan 14, 2025
1 parent 23dc9bf commit 5aa5775
Show file tree
Hide file tree
Showing 5 changed files with 659 additions and 367 deletions.
12 changes: 7 additions & 5 deletions utils/sv2_serde_json/examples/derive_macro_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sv2_serde_json::value::Value;
use sv2_serde_json::value::{FromJsonValue, ToJsonValue};
use sv2_serde_json_macros::{DeJson, SerJson};

#[derive(SerJson, DeJson, Debug, Clone)]
Expand All @@ -9,12 +9,13 @@ struct Person {
here: Vec<String>,
check: sv2_serde_json::value::Value,
optional_check: Option<sv2_serde_json::value::Value>,
non_optional_check: Option<String>
non_optional_check: Option<String>,
}

#[derive(SerJson, DeJson, Debug)]
struct Person2 {
person: Person,
optional_struct: Option<Person>
}

#[derive(SerJson, DeJson, Debug)]
Expand All @@ -38,24 +39,25 @@ fn main() {

let person2 = Person2 {
person: person.clone(),
optional_struct: Some(person.clone())
};

let person_json = person.to_json_value();
println!("Serialized: {:?}", person_json.to_json_string());

let deserialized_person = Person::from_json_value(person_json).unwrap();
let deserialized_person = Person::from_json_value(&person_json).unwrap();
println!("Deserialized: {:?}", deserialized_person);

let person2_json = person2.to_json_value();
println!("Serialized: {:?}", person2_json.to_json_string());

let deserialized_person2 = Person2::from_json_value(person2_json).unwrap();
let deserialized_person2 = Person2::from_json_value(&person2_json).unwrap();
println!("Deserialized: {:?}", deserialized_person2);

let status = Status::Active;
let status_json = status.to_json_value();
println!("Serialized Enum: {:?}", status_json);

let deserialized_status = Status::from_json_value(status_json);
let deserialized_status = Status::from_json_value(&status_json);
println!("Deserialized Enum: {:?}", deserialized_status);
}
1 change: 1 addition & 0 deletions utils/sv2_serde_json/examples/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cleanup_commands":[],"version":"2","frame_builders":[{"type":"automatic","message_id":"setup_connection_success"},{"message_id":"setup_connection","type":"automatic"},{"type":"automatic","message_id":"open_standard_mining_channel"}],"role":"client","downstream":{"port":34254,"pub_key":"2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL","ip":"0.0.0.0"},"mining_messages":[{"id":"open_standard_mining_channel","message":{"request_id":89,"nominal_hash_rate":10,"max_target":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"user_identity":"","type":"OpenStandardMiningChannel"}}],"actions":[{"message_ids":["setup_connection"],"actiondoc":"","results":[{"type":"match_message_type","value":"0x01"}],"role":"client"},{"message_ids":["open_standard_mining_channel"],"role":"client","actiondoc":"","results":[{"type":"match_message_field","value":["MiningProtocol","OpenStandardMiningChannelSuccess",[["request_id",{"U32":89}],["extranonce_prefix",{"B032":[[32],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]]}]]]},{"type":"match_message_type","value":"0x20"},{"type":"match_message_type","value":"0x1f"}]}],"execution_commands":[],"doc":["What this test does:","1) launch SRI pool and wait for initialization","2) connect to the pool as a Downstream that uses noise","3) send SetupConnection to the pool","4) check that SetupConnectionSuccess is received","5) send OpenStandardMiningChannel with request id 89","6) check that NewExtendedJob is received","7) check that NewPrevHash is received","8) check that OpenStandardMiningChannelSuccess with request 89 is received"],"common_messages":[{"message":{"hardware_version":"","min_version":2,"flags":0,"type":"SetupConnection","endpoint_host":"","endpoint_port":0,"protocol":0,"vendor":"","max_version":2,"firmware":"","device_id":""},"id":"setup_connection"},{"message":{"used_version":2,"type":"SetupConnectionSuccess","flags":0},"id":"setup_connection_success"}],"setup_commands":[{"command":"cargo","conditions":{"WithConditions":{"warn_no_panic":false,"conditions":[{"output_string":"Listening for encrypted connection on: 0.0.0.0:34254","condition":true,"output_location":"StdOut"}],"timer_secs":60}},"args":["run","-p","pool","--","-c","./test/config/pool-config-sri-tp.toml"]}]}
160 changes: 141 additions & 19 deletions utils/sv2_serde_json/examples/test.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,148 @@
{
"pairs": [
"version": "2",
"doc": [
"What this test does:",
"1) launch SRI pool and wait for initialization",
"2) connect to the pool as a Downstream that uses noise",
"3) send SetupConnection to the pool",
"4) check that SetupConnectionSuccess is received",
"5) send OpenStandardMiningChannel with request id 89",
"6) check that NewExtendedJob is received",
"7) check that NewPrevHash is received",
"8) check that OpenStandardMiningChannelSuccess with request 89 is received"
],
"common_messages": [
{
"x0": 95.26235434764715,
"y0": -33.78221816487377,
"x1": 41.844453001935875,
"y1": -78.10213222087448
"message": {
"type": "SetupConnection",
"protocol": 0,
"min_version": 2,
"max_version": 2,
"flags": 0,
"endpoint_host": "",
"endpoint_port": 0,
"vendor": "",
"hardware_version": "",
"firmware": "",
"device_id": ""
},
"id": "setup_connection"
},
{
"x0": 115.42029308864215,
"y0": 1.20021873e-5,
"x1": 83.39640643072113,
"y1": 28.643090267505812
"message": {
"type": "SetupConnectionSuccess",
"flags": 0,
"used_version": 2
},
"id": "setup_connection_success"
}
],
"mining_messages": [
{
"message": {
"type": "OpenStandardMiningChannel",
"request_id": 89,
"user_identity": "",
"nominal_hash_rate": 10,
"max_target": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
},
"id": "open_standard_mining_channel"
}
],
"frame_builders": [
{
"type": "automatic",
"message_id": "setup_connection_success"
},
{
"type": "automatic",
"message_id": "setup_connection"
},
{
"sample": "string sample",
"nullable": null,
"isWorking": true,
"isNotWorking": false
"type": "automatic",
"message_id": "open_standard_mining_channel"
}
],
"actions": [
{
"message_ids": ["setup_connection"],
"role": "client",
"results": [
{
"type": "match_message_type",
"value": "0x01"
}
],
"actiondoc": ""
},
{
"message_ids": ["open_standard_mining_channel"],
"role": "client",
"results": [
{
"type": "match_message_field",
"value": [
"MiningProtocol",
"OpenStandardMiningChannelSuccess",
[
[
"request_id",
{"U32": 89}
],
[
"extranonce_prefix",
{"B032": [[32], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]]}
]
]
]
},
{
"type": "match_message_type",
"value": "0x20"
},
{
"type": "match_message_type",
"value": "0x1f"
}
],
"actiondoc": ""
}

],
"setup_commands": [
{
"command": "cargo",
"args": [
"run",
"-p",
"pool",
"--",
"-c",
"./test/config/pool-config-sri-tp.toml"
],
"conditions": {
"WithConditions": {
"conditions": [
{
"output_string": "Listening for encrypted connection on: 0.0.0.0:34254",
"output_location": "StdOut",
"condition": true
}
],
"timer_secs": 60,
"warn_no_panic": false
}
}
}
],
"utf8": {
"key1": "ࠄࠀࠆࠄࠀࠁࠃ",
"key2": "value2"
}
}
],
"execution_commands": [
],
"cleanup_commands": [
],
"role": "client",
"downstream": {
"ip": "0.0.0.0",
"port": 34254,
"pub_key": "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"
}
}
Loading

0 comments on commit 5aa5775

Please sign in to comment.