go-blockchain, v1.4.1
Posted on

The library that implements models and algorithms of blockchain.
Extracted the Proof-of-Work implementation into a separate library github.com/thewizardplusplus/go-pow, enabling cancellable block generation, error handling and enhanced configuration options.
Change Log
The format is based on Keep a Changelog.
Added
- Extended PoW interface and functionality:
- Extended the
Prooferinterface to accommodate cancellable implementations with error handling. - The
ProofOfWorkimplementation now supports:- Limiting the number of hash attempts during mining.
- Choosing a random starting nonce from a specified range.
- Added the
ProofOfWork.HashEx()method — a cancellable version ofHash()that also returns an error. - Updated the
ProofOfWork.Validate()method to support extended validation logic.
- Extended the
- New functions and methods for block and blockchain creation — all of which:
- Accept a
context.Contextfor cancellation. - Return an error alongside the result.
- New functions and methods list:
NewBlockEx()NewGenesisBlockEx()NewBlockchainEx()Blockchain.AddBlockEx()
- Accept a
Changed
- Integration with the new PoW library:
- Functions
NewBlock(),NewGenesisBlock(),NewBlockchain()and methodsBlockchain.AddBlock(),ProofOfWork.Hash()now delegate to their*Ex()counterparts, which support cancellation and error handling.
- Functions
- Code improvements:
- Refactored the
parseHash()function for improved readability and robustness. - Introduced
buildChallenge()helper function to centralize PoW challenge construction. - Updated mocks to support the enhanced
Prooferinterface and the lastest version of the mockery tool.
- Refactored the
Deprecated
- The legacy methods
NewBlock(),NewGenesisBlock(),NewBlockchain(),Blockchain.AddBlock(), andProofOfWork.Hash()remain available for backward compatibility but lack cancellation support and proper error handling. Use the corresponding*Ex()methods instead.
Removed
- Nothing removed — backward compatibility is fully preserved in this release.
Fixed
- Fixed the documentation example for the
Blockchain.Merge()method.
CI / Internal
- Migrated to
go.modfor dependency management. - Replaced
github.com/pkg/errorswith the Go standard library’serrorspackage. - Switched to
golangci-lintfor static analysis. - Set up GitHub Actions for linting and testing.
Installation
$ go get github.com/thewizardplusplus/go-blockchain
Repository
Link: https://github.com/thewizardplusplus/go-blockchain/tree/v1.4.1.
Content: code.
License: MIT.