garritfra
6 years ago
4 changed files with 74 additions and 2 deletions
@ -0,0 +1,24 @@
|
||||
{ |
||||
// Use IntelliSense to learn about possible attributes. |
||||
// Hover to view descriptions of existing attributes. |
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
||||
"version": "0.2.0", |
||||
"configurations": [ |
||||
{ |
||||
"name": "Launch Package", |
||||
"type": "go", |
||||
"request": "launch", |
||||
"mode": "debug", |
||||
"program": "${workspaceFolder}" |
||||
}, |
||||
{ |
||||
"name": "Launch", |
||||
"type": "go", |
||||
"request": "launch", |
||||
"mode": "auto", |
||||
"program": "${fileDirname}", |
||||
"env": {}, |
||||
"args": [] |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,6 @@
|
||||
package main |
||||
|
||||
type Block struct { |
||||
hash []byte |
||||
previousHash []byte |
||||
} |
@ -0,0 +1,35 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"crypto/sha256" |
||||
"fmt" |
||||
) |
||||
|
||||
// Blockchain struct
|
||||
type Blockchain struct { |
||||
blocks []Block |
||||
} |
||||
|
||||
func (bc *Blockchain) addBlock(block Block) { |
||||
bc.blocks = append(bc.blocks, block) |
||||
} |
||||
|
||||
func newBlockchain() Blockchain { |
||||
|
||||
blockchain := Blockchain{blocks: make([]Block, 0)} |
||||
|
||||
genesisBlock := generateGenesisBlock() |
||||
blockchain.addBlock(genesisBlock) |
||||
|
||||
return blockchain |
||||
} |
||||
|
||||
func generateGenesisBlock() Block { |
||||
block := new(Block) |
||||
hasher := sha256.New() |
||||
s := fmt.Sprintf("%v", block) |
||||
sum := hasher.Sum([]byte(s)) |
||||
block.hash = sum |
||||
|
||||
return *block |
||||
} |
Loading…
Reference in new issue