package main
import (
“strconv”
“crypto/sha256”
“encoding/hex”
“time”
“math/rand”
“fmt”
)
//DPoS原理
//定义区块
type Block struct {
//高度
Index int
//时间戳
TimeStamp string
//交易信息
BPM int
//当前的哈希值
HashCode string
//上一个哈希值
PrevHash string
//区块验证者
//保存的是哪个节点对当前区块进行了挖矿
Validator string
}
//定义区块链
var Blockchain []Block
//生成block
func GenerateNextBlock(oldBlock Block,BPM int ,adds string) Block {
var newBlock Block
newBlock.Index = oldBlock.Index + 1
newBlock.PrevHash = oldBlock.HashCode
newBlock.BPM = BPM
newBlock.TimeStamp = time.Now().String()
newBlock.Validator = adds
newBlock.HashCode = GenerateHashValue(newBlock)<