dpos

package
v0.0.0-...-2eef10d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

README

实现一个简易的DPOS算法

架构设计

  • 创建一个P2P连接池
  • BlockChain生成
  • 节点管理与投票
  • 选取节点生成区块
  • 区块上链

代码运行

go run main/dpos.go -l 3000 -secio

投票

go run main/vote.go -name aaa -v 30

Documentation

Index

Constants

View Source
const BPCount = 5
View Source
const DefaultVote = 10
View Source
const FileName = "config.ini"

Variables

View Source
var BlockChain []Block

Functions

func CaculateBlockHash

func CaculateBlockHash(block Block) string

func CaculateHash

func CaculateHash(s string) string

计算string的hash值

func HandleStream

func HandleStream(s net.Stream)

func IsBlockValid

func IsBlockValid(newBlock, oldBlock Block) bool

func MakeBasicHost

func MakeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error)

func PickWinner

func PickWinner() (bp string)

func Run

func Run()

func SavePeer

func SavePeer(name string)

Types

type Block

type Block struct {
	Index     int
	Timestamp string
	BPM       int
	Hash      string
	PrevHash  string
	// contains filtered or unexported fields
}

func GenerateBlock

func GenerateBlock(oldBlock Block, BPM int, address string) (Block, error)

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL