An open API service indexing awesome lists of open source software.

https://github.com/pvlbzn/blockchan

Blockchain implementation
https://github.com/pvlbzn/blockchan

blockchain cryptography

Last synced: 2 months ago
JSON representation

Blockchain implementation

Awesome Lists containing this project

README

          

# Blockchain Implementation

Code prior to this [point](https://github.com/pvlbzn/blockchan/tree/a22d842dbaad3232bbb9758d0e2697749618dbea)
was written at my housewarming party knowing little about blockchain. Later commits contains refactoring
on a sober mind.

### Architecture

Blocks are chosen to be stored as files in a file system rather than in memory (runtime) data structure.
Files are less abstract and more concrete so that one can see the content of a block straight away.

Blocks are stored in `blocks` directory and they are named `{0..n}.block`. `0.block` is a genesis block
and should not be changed.

A number of transactions in a block is currently from 1 to n.

### `block` Package

Block package implements core block chain logic: `Block`, `Transaction` and their methods.

```Go
// Create a new block
b, err := block.NewBlock()
if err != nil {
// handle it
}

// Add a transaction into the block
b.AddTransaction(block.NewTransaction("from", "to", amount))

// "perform" transaction
b.Write()

status, err := block.ValidateChain()
if err != nil {
// handle it
}

fmt.Println(status) // Should be true
```

To parse some block out of the file into runtime memory layout (data structure) one should
use `func Read(n int) (*Block, error)` function. It will parse `n`th block into `Block`
structure.

### Future Hackaton Plan

* Web server/interface to blockchain
* Transaction queue
* Transaction processing
* Public API
* Form a cryptocurrency on top of blockchain
* Nonce
* Rules
* Parallel mining software
* Find a hash to transaction
* Send a hash to public API