{"id":23553365,"url":"https://github.com/geofmureithi/ubu-block","last_synced_at":"2025-04-28T13:47:50.216Z","repository":{"id":37075028,"uuid":"501115576","full_name":"geofmureithi/ubu-block","owner":"geofmureithi","description":"Blockchain for African countries election monitoring","archived":false,"fork":false,"pushed_at":"2022-06-20T12:08:02.000Z","size":56,"stargazers_count":11,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T10:11:26.481Z","etag":null,"topics":["blockchain","election-monitoring","election-results","rust","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geofmureithi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-06-08T05:42:18.000Z","updated_at":"2022-09-27T10:45:17.000Z","dependencies_parsed_at":"2022-06-24T19:32:42.497Z","dependency_job_id":null,"html_url":"https://github.com/geofmureithi/ubu-block","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi%2Fubu-block","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi%2Fubu-block/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi%2Fubu-block/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi%2Fubu-block/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geofmureithi","download_url":"https://codeload.github.com/geofmureithi/ubu-block/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251321951,"owners_count":21570825,"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":["blockchain","election-monitoring","election-results","rust","sqlite"],"created_at":"2024-12-26T11:14:55.079Z","updated_at":"2025-04-28T13:47:50.169Z","avatar_url":"https://github.com/geofmureithi.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ubu-block\n\nUchaguzi bila Ubaguzi Blockchain\n\n## Features\n\n1. Immutable: You can't make changes only append so no `fungua server` and other shenanigans.\n2. Distributed: No single point of data storage.\n3. Accessible: Runs on sqlite which is well supported in most platforms.\n4. Community driven: Dynamic number of signatories\n\n## Getting Started\n\n```\ngit clone \u003crepo\u003e ubu-block\ncd ubu-block\n```\n\nIf you want to run binaries without installing rust:\n\n1. Get the latest binary from the releases page.\n2. Replace `cargo run` with `ubu-block`\n3. Download the relevant files see `Setup initial files`\n\n### Setup initial files\n\n```\nmkdir data\n\n# Create the db files\ncp src/sql/empty.db data/blockchain.db\ncp src/sql/empty.db data/private.db\n\n```\n\n### Initialize a Blockchain\n\n```\ncargo run init --creator \"Njuguna Mureithi\"\n```\n\nYou should get:\n\n```\nINFO  ubu_block] Blockchain was successfully initialized!\n```\n\n### Add some blocks\n\nCurrently `ubu-block` has very limited dummy data, but this should change as soon as IEBC publishes the voter register\n\nFor testing purposes, I used limited data from previous by elections. See `src/sql/main_db.sql`\n\n```\ncargo run insert --station 022113056303301 --candidate 1 --votes 66\ncargo run insert --station 022113056303301 --candidate 2 --votes 21\n```\n\nYou should get:\n\n```\nINFO ubu_block] Block was added successfully!\n```\n\n### Validate our blockchain\n\n```\ncargo run validate\n```\n\nYou should get:\n\n```\nINFO ubu_block] Blockchain is valid!\n```\n\n### Querying\n\n```\ncargo run query -q \"Select\n  c.name as candidate,\n   SUM(votes) as votes,\n  ward_name as ward,\n  constituency_name as constituency,\n  county_name as county,\n  parties.title as party\nfrom\n  results\n  INNER JOIN stations ON stations.id = results.station_id\n  INNER JOIN candidates c ON c.id = results.candidate_id\n  INNER JOIN wards on stations.ward_code = wards.ward_code\n  INNER JOIN parties ON parties.id = c.party_id\n  INNER JOIN constituencies ON wards.constituency_code = constituencies.constituency_code\n  INNER JOIN counties ON constituencies.county_code = counties.county_code\nWHERE\n  position_type = 'Mp'  and constituency = 'Juja' GROUP BY candidate ;\"\n```\n\n**_NOTE:_** Currently each query has to return the following columns to work: candidate, votes, ward, constituency, county, party. This is just a temporary issue and should fixed in the next release\n\nYou should get:\n\n```\n+--------+--------------+----------+-----------+-------+-------+\n| county | constituency |   ward   | candidate | party | votes |\n+--------+--------------+----------+-----------+-------+-------+\n| Kiambu |     Juja     | Kalimoni |   Omosh   |  ODM  |  21   |\n+--------+--------------+----------+-----------+-------+-------+\n| Kiambu |     Juja     | Kalimoni |   Mwas    |  PNU  |  66   |\n+--------+--------------+----------+-----------+-------+-------+\n```\n\n### Trying to steal the election for Omosh\n\nSince immutability is one of our main goal, lets try to edit votes for `Omosh` and see if we can get away with it\n\nOpen `blockchain.db` with your favourite sqlite editor and run a query that updates the results:\n\n```sql\nUPDATE \"results\" SET \"votes\"= 71 WHERE _rowid_ =1\n```\n\nRunning `query` again we get:\n\n```\n+--------+--------------+----------+-----------+-------+-------+\n| county | constituency |   ward   | candidate | party | votes |\n+--------+--------------+----------+-----------+-------+-------+\n| Kiambu |     Juja     | Kalimoni |   Omosh   |  ODM  |  71   |\n+--------+--------------+----------+-----------+-------+-------+\n| Kiambu |     Juja     | Kalimoni |   Mwas    |  PNU  |  66   |\n+--------+--------------+----------+-----------+-------+-------+\n```\n\nWow congrats to Omosh!\n\n\n\u003cimg src=\"https://user-images.githubusercontent.com/42699812/174386545-799c9869-705d-4c67-b46c-76fca2283c49.jpg\" height=60%\u003e\n\n\n\nHold on, Hold on\n\n\u003cimg src=\"https://user-images.githubusercontent.com/42699812/174367033-167be582-77d6-49ba-95d5-ff847616903f.jpg\" width=\"50%\"\u003e\n\n\nThere is a petition, lets try validating our blockchain\n\n```\ncargo run validate\n\nthread 'main' panicked at 'Could not verify block, found 0e70cebe0ab3bd8c3606a08d26483d092534eea4ccdb7816fc2692aee5ed3109, block: Block {... CandidateResult { station_id: 22113056303301, candidate_id: 1, votes: 71 }]......', src/db.rs:189:17\n\n```\n\nHow about that? No `fungua servers` and everything is public and sql friendly\n\n## Free Public Servers\n\nBelow are the servers you are using for free, it may change along the time. If you are not close to one of these, your network may be slow.\n| Location | Vendor | Specification |\n| --------- | ------------- | ------------------ |\n| France | Vultr | 1 VCPU / 1GB RAM |\n\n**_NOTE:_** This will be accessible when `p2p` is ready (hopefully in the next release).\n\n## Roadmap\n\nv 0.3\n\n- [ ] Http API\n- [ ] Mobile and Web apps\n\nv 0.2\n\n- [ ] P2p - ability to add nodes\n- [ ] Fill regional data\n- [ ] Views to simplify quering\n- [ ] Setup triggers to `Before Insert` to prevent adding unmatching data\n- [ ] Rigourous testing\n- [ ] Tabling of sql results\n\nv 0.1\n\n- [x] Clap\n- [x] Database, sqlite\n- [x] Blockchain\n- [x] CI/CD\n\n## References\n\n[Do you need a blockchain?](https://eprint.iacr.org/2017/375.pdf)\n\n[Daisy](https://github.com/ivoras/daisy)\n\n## Credits\n[Free Stock Images from Pexels](https://www.pexels.com/) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeofmureithi%2Fubu-block","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeofmureithi%2Fubu-block","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeofmureithi%2Fubu-block/lists"}