Capitalize Block.hash

This commit is contained in:
Ivan Kuznetsov 2017-08-16 12:33:15 +07:00
parent b97fb423a7
commit 53c83d4ad2
3 changed files with 4 additions and 4 deletions

View File

@ -12,7 +12,7 @@ type Block struct {
Timestamp int64 Timestamp int64
Data []byte Data []byte
PrevBlock []byte PrevBlock []byte
hash []byte Hash []byte
} }
// SetHash calculates and sets block hash // SetHash calculates and sets block hash
@ -28,7 +28,7 @@ func (b *Block) SetHash() {
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }
b.hash = h.Sum(nil) b.Hash = h.Sum(nil)
} }
// NewBlock creates and returns Block // NewBlock creates and returns Block

View File

@ -10,7 +10,7 @@ type Blockchain struct {
// AddBlock saves provided data as a block in the blockchain // AddBlock saves provided data as a block in the blockchain
func (bc *Blockchain) AddBlock(data string) { func (bc *Blockchain) AddBlock(data string) {
prevBlock := bc.blocks[len(bc.blocks)-1] prevBlock := bc.blocks[len(bc.blocks)-1]
newBlock := &Block{time.Now().Unix(), []byte(data), prevBlock.hash, []byte("")} newBlock := &Block{time.Now().Unix(), []byte(data), prevBlock.Hash, []byte("")}
newBlock.SetHash() newBlock.SetHash()
bc.blocks = append(bc.blocks, newBlock) bc.blocks = append(bc.blocks, newBlock)
} }

View File

@ -12,6 +12,6 @@ func main() {
for _, block := range bc.blocks { for _, block := range bc.blocks {
fmt.Printf("%s\n", block.Data) fmt.Printf("%s\n", block.Data)
fmt.Printf("%x\n", block.hash) fmt.Printf("%x\n", block.Hash)
} }
} }