{"id":15289099,"url":"https://github.com/settorka/blockchain-transaction-calc","last_synced_at":"2025-03-24T05:43:09.889Z","repository":{"id":247660728,"uuid":"826488131","full_name":"settorka/blockchain-transaction-calc","owner":"settorka","description":"Idempotent calculator for processing blockchain transactions concurrently","archived":false,"fork":false,"pushed_at":"2024-07-09T20:10:50.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T11:30:22.588Z","etag":null,"topics":["blockchain","concurrency","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/settorka.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-07-09T19:58:44.000Z","updated_at":"2024-08-02T14:50:45.000Z","dependencies_parsed_at":"2024-07-10T00:40:49.595Z","dependency_job_id":"76d132a5-5271-4d21-9f8e-daa0340d44ec","html_url":"https://github.com/settorka/blockchain-transaction-calc","commit_stats":null,"previous_names":["settor21/blockchain-transaction-calc","settorka/blockchain-transaction-calc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/settorka%2Fblockchain-transaction-calc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/settorka%2Fblockchain-transaction-calc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/settorka%2Fblockchain-transaction-calc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/settorka%2Fblockchain-transaction-calc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/settorka","download_url":"https://codeload.github.com/settorka/blockchain-transaction-calc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245217791,"owners_count":20579297,"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","concurrency","scala"],"created_at":"2024-09-30T15:59:16.635Z","updated_at":"2025-03-24T05:43:09.865Z","avatar_url":"https://github.com/settorka.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Blockchain Transaction Calc\n\n### Overview\n\nThe calculator in Scala manages transactions involving accounts identified by addresses. Here are the key functionalities:\n\n#### addAmount Function\n\nThis function adds a specified amount to an account identified by its address.\nIf the address exists, it updates the existing amount; if not, it creates a new entry.\n\n#### subtractAmount Function\n\nThis function subtracts a specified amount from an account identified by its address and returns an Either type:\n\n- Right(accounts) if successful and the resulting amount is non-negative.\n- Left(TransactionError) if there is an issue, such as insufficient funds or attempting to subtract from a non-existing account.\n\n### Implementation Details\n\n#### Functional Approach\n\nFunctions are implemented functionally in Scala using immutable data structures like Map for thread safety and clarity.\n\n#### Error Handling\n\nError scenarios are managed using Scala's Exception and Either types to ensure clear error messages and prevent crashes.\n\n#### Scala Features Used\n\n- **Case Classes:** TransactionError is defined as a case class for immutable error handling.\n- **Pattern Matching:** Used extensively in subtractAmount for handling different scenarios.\n- **Immutable Collections:** Scala's immutable Map ensures data integrity.\n\n### Function Testing\n\nUnit tests validate addAmount and subtractAmount from the Calculator object with specific objectives:\n\n- **addAmount Function Tests:** Ensure correct addition and creation of entries.\n- **subtractAmount Function Tests:** Validate accurate subtraction and error handling for insufficient funds or non-existing accounts.\n- **Edge Cases Handled:** Tests for scenarios like non-existing addresses and insufficient funds.\n\n### Production Capacity Planning\n\nAn integration test evaluates the calculator's performance under production conditions with concurrent transactions to simulate multiple hits from a frontend applicaiton:\n\n- **Design Choice:** Utilizes Scala's concurrency features for scalability and efficiency.\n- **Optimized Resource Utilization:** Multithreading to handle simultaneous transactions effectively.\n- **Realistic Load Simulation:** Mimics API hits across distributed nodes.\n\n### Production Testing\n\nComponents include:\n\n- **RandomDataGenerator:** Generates random addresses and amounts.\n- **MultithreadedCompute:** Executes concurrent computations across multiple threads.\n- **IntegrationTest:** Validates performance under load using Scala's asynchronous capabilities.\n\n### Running Instructions\n\nInstall:\n\n**sbt** https://www.scala-sbt.org/1.x/docs/Setup.html\n**scala** https://www.scala-lang.org/download/\n\n```shell\n# Clone this repository\n# Navigate to project folder in terminal and execute:\n$ sbt clean compile\n# Sample use of application\n$ sbt run\n#Functional and production tests for application\n$ sbt \"*testOnly UnitTests.scala\"\n$ sbt \"*testOnly IntegrationTest.scala\"\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsettorka%2Fblockchain-transaction-calc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsettorka%2Fblockchain-transaction-calc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsettorka%2Fblockchain-transaction-calc/lists"}