{"id":25406495,"url":"https://github.com/lostincompilation/stl-blockchain","last_synced_at":"2025-04-12T22:56:49.668Z","repository":{"id":159525288,"uuid":"589106579","full_name":"LostInCompilation/STL-Blockchain","owner":"LostInCompilation","description":"A STL container like implementation of a blockchain for C++.","archived":false,"fork":false,"pushed_at":"2023-01-18T23:20:50.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T22:56:49.313Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LostInCompilation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-15T04:15:18.000Z","updated_at":"2023-01-18T04:20:56.000Z","dependencies_parsed_at":"2023-05-21T00:45:26.074Z","dependency_job_id":null,"html_url":"https://github.com/LostInCompilation/STL-Blockchain","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/LostInCompilation%2FSTL-Blockchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LostInCompilation%2FSTL-Blockchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LostInCompilation%2FSTL-Blockchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LostInCompilation%2FSTL-Blockchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LostInCompilation","download_url":"https://codeload.github.com/LostInCompilation/STL-Blockchain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643050,"owners_count":21138353,"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":"2025-02-16T05:32:46.305Z","updated_at":"2025-04-12T22:56:49.663Z","avatar_url":"https://github.com/LostInCompilation.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blockchain C++ STL-Like Container\n\n## Usage\nInclude the `Blockchain.h` header. Requires C++20.\n\n```cpp\n#include \"Blockchain.h\"\n```\n\n#### Creating a Blockchain\n\nCreate a Blockchain with `std::string` Blocks and add the Genesis Block:\n```cpp\nBlockchain\u003cstd::string\u003e blockchain(\"Genesis\");\n```\n\n#### Pushing new blocks/transactions\n```cpp\nblockchain.push_back(\"Transaction 1\");\nblockchain.push_back(\"Transaction 2\");\nblockchain.push_back(\"Last transaction\");\n```\n\n#### Iterating the Blockchain and print the Hash of each Block/Transaction\n\n* Range-Based for loop:\n```cpp\nfor(auto\u0026 block : blockchain)\n    std::cout \u003c\u003c block.GetTransaction() \u003c\u003c \":\\t\" \u003c\u003c block.GetHash() \u003c\u003c std::endl;\n```\n\n* Indexed for loop:\n```cpp\nfor(int i = 0; i \u003c blockchain.size(); I++)\n    std::cout \u003c\u003c blockchain[i].GetTransaction() \u003c\u003c \":\\t\" \u003c\u003c blockchain[i].GetHash() \u003c\u003c std::endl;\n```\n\n* Iterators:\n```cpp\nfor (Blockchain\u003cstd::string\u003e::iterator iter = blockchain.begin(); iter != blockchain.end(); iter++) \n    std::cout \u003c\u003c iter-\u003eGetTransaction() \u003c\u003c \":\\t\" \u003c\u003c iter-\u003eGetHash() \u003c\u003c std::endl;\n```\n\n#### Checking the Blockchain\n* `Blockchain\u003c...\u003e::Check()` checks if the hashes are consistent:\n\n```cpp\nif(blockchain.Check())\n    std::cout \u003c\u003c \"Blockchain hashes checked. ALL GOOD\" \u003c\u003c std::endl;\n```\n\n* `Blockchain\u003c...\u003e::Revalidate()` checks if the hashes and transactions are consistent:\n\n```cpp\nif(blockchain.Revalidate())\n    std::cout \u003c\u003c \"Blockchain hashes and transactions revalidated. ALL GOOD\" \u003c\u003c std::endl;\n```\n\nIf a transaction or hash in the chain would be altered, the corresponding check/revalidate function would fail.\n\n## Using a custom Hash-Function\n\nThe Blockchain uses std::hash\u003c...\u003e by default. You can use a custom hash function for the chain. Your custom Hasher can return any data type as the hash and must overload the `()` operator:\n\n```cpp\ntemplate \u003ctypename T\u003e\nclass MyHashFunction\n{\npublic:\n    std::string operator()(T input)\n    {\n        // Here calculate your hash based on the input\n        // and return your calculated hash\n        return \"MyCalculatedHashFromInput\";\n    }\n};\n```\n\nTo use the custom Hasher, simply specify it as a template argument when creating the Blockchain:\n\n```cpp\nBlockchain\u003cstd::string, MyHashFunction\u003cstd::string\u003e\u003e customBlockchain(\"Genesis\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flostincompilation%2Fstl-blockchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flostincompilation%2Fstl-blockchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flostincompilation%2Fstl-blockchain/lists"}