{"id":18674072,"url":"https://github.com/nervosnetwork/moodyblues-client-rust","last_synced_at":"2025-04-12T01:32:05.921Z","repository":{"id":57640182,"uuid":"223398567","full_name":"nervosnetwork/moodyblues-client-rust","owner":"nervosnetwork","description":"Replay overlord","archived":false,"fork":false,"pushed_at":"2019-12-23T15:23:33.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T05:52:02.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nervosnetwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-22T12:28:11.000Z","updated_at":"2021-04-05T19:16:22.000Z","dependencies_parsed_at":"2022-08-30T08:00:21.957Z","dependency_job_id":null,"html_url":"https://github.com/nervosnetwork/moodyblues-client-rust","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nervosnetwork%2Fmoodyblues-client-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nervosnetwork%2Fmoodyblues-client-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nervosnetwork%2Fmoodyblues-client-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nervosnetwork%2Fmoodyblues-client-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nervosnetwork","download_url":"https://codeload.github.com/nervosnetwork/moodyblues-client-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027221,"owners_count":21035587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T09:17:24.486Z","updated_at":"2025-04-12T01:32:05.667Z","avatar_url":"https://github.com/nervosnetwork.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MoodyBlues SDK For Rust\n\n## Intro\n\nA tracer SDK for [Overlord][overlord] like consensus algorithm, helps you to debug \nor optimize the algorithm.\n\nThe consensus algorithm always plays with a distributed system, \ndebugging or optimizing is so hard. If we can record events to describe what happens \nwhen consensus state changes, and then replay with a visualization dashboard, \nthe debugging or optimizing would be easier.\n\n## Quick start\n\nLet's starts with a dead simple trace. This example shows how to use the sdk\nfor write the TracePoint in file with JSON format.\n\nCargo.toml\n\n```toml\n[dependencies]\nmoodyblues-sdk = { git = \"https://github.com/nervosnetwork/moodyblues-client-rust\" }\n```\n\n```rust\nuse std::fs::File;\nuse std::io::Write;\nuse std::sync::Mutex;\n\nuse serde_json::{json, to_string};\n\nuse moodyblues_sdk::event::{EventType, TraceEvent};\nuse moodyblues_sdk::point::{Metadata, TracePoint};\nuse moodyblues_sdk::trace;\nuse moodyblues_sdk::time::now;\n\nstruct ConsensusStateMachine {\n    epoch_id: u64,\n    round_id: u64,\n}\n\nimpl ConsensusStateMachine {\n    fn new_epoch(\u0026mut self, epoch_id: u64) {\n        self.epoch_id = \u0026self.epoch_id + 1;\n        self.round_id = 0;\n        // create a trace point mark as starts with epoch\n        trace::start_epoch(epoch_id);\n    }\n\n    fn new_round(\u0026mut self, round_id: u64) {\n        self.round_id = round_id;\n\n        // create a trace point mark as starts with round\n        trace::start_round(self.round_id, self.epoch_id);\n    }\n}\n\nstruct Consensus;\n\nimpl Consensus {\n    fn verify_signature(signature: String, hash: String) {\n        trace::custom(\n            \"verify_signature\".to_string(),\n            Some(json!({\n              \"hash\": hash,\n              \"signature\": signature\n            })),\n        )\n    }\n}\n\nstruct WriteReporter\u003cW: Write + Send + 'static\u003e {\n    reporter: Mutex\u003cW\u003e,\n}\n\nimpl\u003cW: Write + Send + 'static\u003e WriteReporter\u003cW\u003e {\n    fn new(writable: W) -\u003e Box\u003cWriteReporter\u003cW\u003e\u003e {\n        Box::new(WriteReporter {\n            reporter: Mutex::new(writable),\n        })\n    }\n}\n\nimpl\u003cW: Write + Send + 'static\u003e trace::Trace for WriteReporter\u003cW\u003e {\n    fn report(\u0026self, point: TracePoint) {\n        let mut file = self.reporter.lock().unwrap();\n        file.write_all(to_string(\u0026point).unwrap().as_bytes());\n    }\n\n    fn metadata(\u0026self) -\u003e Metadata {\n        // information of current node\n        Metadata {\n            address: \"0x0000000000000000000000000000000000000000\".to_string(),\n        }\n    }\n\n    fn now(\u0026self) -\u003e u64 {\n        // timestamp for each point\n        now()\n    }\n}\n\nfn main() {\n    trace::set_boxed_tracer(WriteReporter::new(File::create(\"log.log\").unwrap()));\n    trace::start_epoch(1);\n}\n```\n\n## Documentation\n\nTODO for now, jump to `trace.rs` for more information. The API may be frequent changes before the first release version.\n\n[overlord]: https://github.com/nervosnetwork/overlord","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnervosnetwork%2Fmoodyblues-client-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnervosnetwork%2Fmoodyblues-client-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnervosnetwork%2Fmoodyblues-client-rust/lists"}