-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_data_types.go
43 lines (37 loc) · 894 Bytes
/
core_data_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package datatypes
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"sync"
"time"
)
type Block struct {
Index int `json:"index" `
Hash string `json:"hash"`
Timestamp time.Time `json:"created_at"`
PrevHash string `json:"previous_hash"`
Nounce int64 `json:"nounce"`
Transactions []Transaction `json:"transactions"`
}
type Transaction struct {
Sender string `json:"sender"`
Receiver string `json:"receiver"`
Signature string `json:"signature"`
Amount int64 `json:"amount"`
}
type BlockChain struct {
sync.RWMutex
BlkChain []Block
}
type CurrentTransactions struct {
sync.RWMutex
Transactions []Transaction
}
func (b *Block) SetHash() string {
hasher := sha256.New()
hasher.Write([]byte(fmt.Sprintf("%v", b)))
sha256Hash := hex.EncodeToString(hasher.Sum(nil))
b.Hash = sha256Hash
return sha256Hash
}