zff0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: BSD-3-Clause Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TimeMillisecond = 1
	TimeSecond      = 1000 * TimeMillisecond
	TimeMinute      = 60 * TimeSecond
	TimeHour        = 60 * TimeMinute
	TimeDay         = 24 * TimeHour
	TimeYear        = 31558150 * TimeSecond
	TimeMonth       = TimeYear / 12
)

time

View Source
const (
	// HashLen the byte length of Hash
	HashLen = 32
	// AddressLen the byte length of Address
	AddressLen = 24
	// AdminNum admin number, DPOS vote
	AdminNum = 23
)
View Source
const (
	StatBaseInfo = uint8(iota)
	StatTransKey
	StatGuerdon
	StatBlockSizeLimit
	StatAvgBlockSize
	StatHashPower
	StatBlockInterval
	StatSyncInfo
	StatFirstBlockKey
	StatChangingConfig
	StatBroadcast
	StatParentKey
	StatUser
	StatAdmin
	StatTotalVotes
	StatLastRewarID
	StatTotalCoins
)

Key of the running state

View Source
const (
	// OpsTransfer pTransfer
	OpsTransfer = uint8(iota)
	// OpsMove Move out of coin, move from this chain to adjacent chains
	OpsMove
	// OpsNewChain create new chain
	OpsNewChain
	// OpsNewApp create new app
	OpsNewApp
	// OpsRunApp run app
	OpsRunApp
	// OpsUpdateAppLife update app life
	OpsUpdateAppLife
	// OpsRegisterMiner Registered as a miner
	OpsRegisterMiner
	// OpsRegisterAdmin Registered as a admin
	OpsRegisterAdmin
	// OpsVote vote admin
	OpsVote
	// OpsUnvote unvote
	OpsUnvote
	// OpsReportError error block
	OpsReportError
	// OpsConfig config
	OpsConfig
)
View Source
const (
	EncBinary = uint8(iota)
	EncJSON
	EncGob
)

encoding type

View Source
const (
	// AppFlagRun the app can be call
	AppFlagRun = uint8(1 << iota)
	// AppFlagImport the app code can be included
	AppFlagImport
	// AppFlagPlublc App funds address uses the plublc address, except for app, others have no right to operate the address.
	AppFlagPlublc
	// AppFlagGzipCompress gzip compress
	AppFlagGzipCompress
)
View Source
const (
	SyncOpsMoveCoin = iota
	SyncOpsNewChain
	SyncOpsMiner
	SyncOpsBroadcast
	SyncOpsBroadcastAck
)

ops of sync

View Source
const MaxGuerdon = maxGuerdon

MaxGuerdon MaxGuerdon

Variables

This section is empty.

Functions

func BlockOnTheChain

func BlockOnTheChain(chain uint64, key []byte) bool

BlockOnTheChain return true if the block is on the chain

func CheckTransList

func CheckTransList(chain uint64, factory func(uint64) Hash) (err error)

CheckTransList check trans list for mine

func CheckTransaction

func CheckTransaction(chain uint64, tKey []byte) (err error)

CheckTransaction check trans for mine

func CreateAppFromSourceCode

func CreateAppFromSourceCode(fileName string, flag byte) ([]byte, uint64)

CreateAppFromSourceCode create app

func CreateBiosTrans

func CreateBiosTrans(chain uint64)

CreateBiosTrans CreateBiosTrans

func DecodeOpsDataOfTrans

func DecodeOpsDataOfTrans(ops uint8, data []byte) map[string]interface{}

DecodeOpsDataOfTrans decode ops data

func DeleteBlock

func DeleteBlock(chain uint64, key []byte) error

DeleteBlock delete block

func DeleteTransaction

func DeleteTransaction(chain uint64, key []byte) error

DeleteTransaction delete Transaction

func GetBlockInterval

func GetBlockInterval(chain uint64) uint64

GetBlockInterval get the interval time of between blocks

func GetBlockSizeLimit

func GetBlockSizeLimit(chain uint64) uint64

GetBlockSizeLimit get the limit size of block

func GetBlockTime

func GetBlockTime(chain uint64) uint64

GetBlockTime get block time

func GetHashPowerLimit

func GetHashPowerLimit(chain uint64) uint64

GetHashPowerLimit ge hash power limit

func GetLastBlockIndex

func GetLastBlockIndex(chain uint64) uint64

GetLastBlockIndex get the index of last block

func GetTheBlockKey

func GetTheBlockKey(chain, index uint64) []byte

GetTheBlockKey get block key,if index==0,return last key

func GetUserCoin

func GetUserCoin(chain uint64, addr []byte) uint64

GetUserCoin get user coin number

func InitDefaultDbMgr added in v0.5.11

func InitDefaultDbMgr(addrType, address string, number int)

InitDefaultDbMgr init default db proxy, not write data to database

func IsAdmin

func IsAdmin(chain uint64, user []byte) bool

IsAdmin is admin

func IsExistBlock

func IsExistBlock(chain uint64, key []byte) bool

IsExistBlock Determine whether block exists

func IsExistTransaction

func IsExistTransaction(chain uint64, key []byte) bool

IsExistTransaction Determine whether transaction exists

func IsMiner

func IsMiner(chain uint64, user []byte) bool

IsMiner check miner

func ProcessBlockOfChain

func ProcessBlockOfChain(chain uint64, key []byte) (err error)

ProcessBlockOfChain process block

func ReadBlockData

func ReadBlockData(chain uint64, key []byte) []byte

ReadBlockData read block data

func ReadTransList

func ReadTransList(chain uint64, key []byte) []byte

ReadTransList read trans list from db

func ReadTransactionData

func ReadTransactionData(chain uint64, key []byte) []byte

ReadTransactionData read transaction data

func TransListExist

func TransListExist(chain uint64, key []byte) bool

TransListExist return true when transList exist

func TransListToBytes

func TransListToBytes(in []Hash) []byte

TransListToBytes transList to bytes

func WriteBlock

func WriteBlock(chain uint64, data []byte) error

WriteBlock write block data to database

func WriteTransList

func WriteTransList(chain uint64, transList []Hash) error

WriteTransList write transList to db

func WriteTransaction

func WriteTransaction(chain uint64, data []byte) error

WriteTransaction write transaction data to database

Types

type Address

type Address [AddressLen]byte

Address the wallet address

func GetAdminList

func GetAdminList(chain uint64) []Address

GetAdminList get admin list

func (*Address) Decode

func (a *Address) Decode(hexStr string)

Decode decode hex string

func (Address) Empty

func (a Address) Empty() bool

Empty Check where Address is empty

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON marshal by base64

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) error

UnmarshalJSON UnmarshalJSON

type AdminInfo

type AdminInfo struct {
	Deposit uint64
	Votes   uint64
}

AdminInfo vote info

func GetAdminInfo

func GetAdminInfo(chain uint64, addr Address) AdminInfo

GetAdminInfo get admin info

type AppInfo

type AppInfo struct {
	Account Address `json:"account,omitempty"`
	LineSum uint64  `json:"line_sum,omitempty"`
	Life    uint64  `json:"life,omitempty"`
	Flag    uint8   `json:"flag"`
}

AppInfo App info in database

func GetAppInfoOfChain

func GetAppInfoOfChain(chain uint64, name []byte) *AppInfo

GetAppInfoOfChain get app information

type BaseInfo

type BaseInfo struct {
	Key           Hash
	Time          uint64
	Chain         uint64
	ID            uint64
	BaseOpsEnergy uint64
	Producer      Address
	ParentID      uint64
	LeftChildID   uint64
	RightChildID  uint64
}

BaseInfo stat info of last block

func GetChainInfo

func GetChainInfo(chain uint64) *BaseInfo

GetChainInfo get chain info

type Block

type Block struct {
	//signLen	  uint8
	//sign	      []byte
	Time          uint64
	Previous      Hash
	Parent        Hash
	LeftChild     Hash
	RightChild    Hash
	TransListHash Hash
	Producer      Address
	Chain         uint64
	Index         uint64
	Nonce         uint64
}

Block Block structure

type BlockInfo

type BlockInfo struct {
	Parent       Hash
	LeftChild    Hash
	RightChild   Hash
	Index        uint64
	ParentID     uint64
	LeftChildID  uint64
	RightChildID uint64
	Time         uint64
	Producer     Address
}

BlockInfo the block info in database

type BroadcastInfo

type BroadcastInfo struct {
	BlockKey Hash
	App      Hash
	LFlag    byte
	RFlag    byte
}

BroadcastInfo broadcase info

type DB

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

DB Type definition of a database.

func (*DB) Get

func (d *DB) Get(key []byte) ([]byte, uint64)

Get Read data from database

func (*DB) GetInt

func (d *DB) GetInt(key []byte) uint64

GetInt read data from database

func (*DB) GetValue

func (d *DB) GetValue(key []byte, value interface{}) bool

GetValue read data from database

func (*DB) Set

func (d *DB) Set(key, value []byte, life uint64)

Set Storage data. the record will be deleted when life=0 or value=nil

func (*DB) SetValue

func (d *DB) SetValue(key []byte, value interface{}, life uint64)

SetValue Storage data

type DBNWProxyMgr added in v0.5.11

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

DBNWProxyMgr db server, proxy and cache, not write data to database

func NewDbProxyMgr added in v0.5.11

func NewDbProxyMgr(addrType, address string, number int) *DBNWProxyMgr

NewDbProxyMgr new db proxy manager

type DependItem

type DependItem struct {
	Alias   [4]byte
	AppName Hash
}

DependItem App's dependency information

type Hash

type Hash [HashLen]byte

Hash The KEY of the block of transaction

func GetHashOfTransList

func GetHashOfTransList(transList []Hash) Hash

GetHashOfTransList get hash of transaction list

func GetParentBlockOfChain

func GetParentBlockOfChain(chain uint64) Hash

GetParentBlockOfChain get parent block of chain

func ParseTransList

func ParseTransList(data []byte) []Hash

ParseTransList parse transaction list

func (Hash) Empty

func (h Hash) Empty() bool

Empty Check whether Hash is empty

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

MarshalJSON marshal by base64

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(b []byte) error

UnmarshalJSON UnmarshalJSON

type Log

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

Log Type definition of a log. Log data can be read on other chains. Unable to overwrite the existing data.

func (*Log) Read

func (l *Log) Read(chain uint64, key []byte) []byte

Read Read log

func (*Log) Write

func (l *Log) Write(key, value []byte) bool

Write Write log,if exist the key,return false.the key and value can't be nil.

type RewardInfo

type RewardInfo struct {
	Admins [AdminNum]Address
	Votes  [AdminNum]uint64
	Reward uint64
}

RewardInfo reward

func GetVoteReward

func GetVoteReward(chain, day uint64) RewardInfo

GetVoteReward get reward info

type StBlock

type StBlock struct {
	Block
	Key            Hash
	HashpowerLimit uint64
	// contains filtered or unexported fields
}

StBlock StBlock

func DecodeBlock

func DecodeBlock(data []byte) *StBlock

DecodeBlock decode data and check sign, check hash

func NewBlock

func NewBlock(chain uint64, producer Address) *StBlock

NewBlock new block

  1. NewBlock
  2. SetTransList
  3. update StBlock.Size,PreCheckSum,HashPower,Parent...
  4. GetSignData
  5. SetSign
  6. Output

func (*StBlock) GetSignData

func (b *StBlock) GetSignData() []byte

GetSignData GetSignData

func (*StBlock) Output

func (b *StBlock) Output() []byte

Output Output

func (*StBlock) SetSign

func (b *StBlock) SetSign(sign []byte) error

SetSign SetSign

type StTrans

type StTrans struct {
	TransactionHead
	Sign []byte
	Data []byte
	Key  []byte
}

StTrans 交易的结构体

func DecodeTrans

func DecodeTrans(data []byte) *StTrans

DecodeTrans decode transaction data

func NewTransaction

func NewTransaction(chain uint64, user Address) *StTrans

NewTransaction create a new transaction struct

  1. NewTransaction
  2. Create*:CreateTransfer,CreateMove...
  3. update energy,time...
  4. GetSignData
  5. SetSign
  6. Output

func (*StTrans) CreateMove

func (t *StTrans) CreateMove(dstChain, value uint64)

CreateMove 转出货币到其他相邻链

func (*StTrans) CreateNewApp

func (t *StTrans) CreateNewApp(code []byte, lineNum uint64)

CreateNewApp new app

func (*StTrans) CreateNewChain

func (t *StTrans) CreateNewChain(chain, value uint64)

CreateNewChain 创建新链

func (*StTrans) CreateRunApp

func (t *StTrans) CreateRunApp(app Hash, cost uint64, data []byte)

CreateRunApp run app

func (*StTrans) CreateTransfer

func (t *StTrans) CreateTransfer(payee Address, value uint64)

CreateTransfer 创建转账交易

func (*StTrans) CreateUpdateAppLife

func (t *StTrans) CreateUpdateAppLife(app Hash, life uint64)

CreateUpdateAppLife update app life

func (*StTrans) GetSignData

func (t *StTrans) GetSignData() []byte

GetSignData 提取数据用于签名

func (*StTrans) Output

func (t *StTrans) Output() []byte

Output 输出数据,可以发布

func (*StTrans) RegisterAdmin

func (t *StTrans) RegisterAdmin(cost uint64)

RegisterAdmin RegisterAdmin(candidates)

func (*StTrans) RegisterMiner

func (t *StTrans) RegisterMiner(chain, cost uint64, peer []byte)

RegisterMiner RegisterMiner

func (*StTrans) SetSign

func (t *StTrans) SetSign(in []byte) error

SetSign 设置签名信息

func (*StTrans) VoteAdmin

func (t *StTrans) VoteAdmin(cost uint64, admin []byte)

VoteAdmin VoteAdmin

type StatSwitch

type StatSwitch struct {
	SWMiningCount bool
	SWTransferOut bool
	SWTransferIn  bool
	SWAPPRun      bool
	SWMove        bool
}

StatSwitch define switch of govm status

var Switch StatSwitch = StatSwitch{
	true, true, true, true, true,
}

Switch switch of status

type TransInfo

type TransInfo struct {
	User    Address
	Ops     uint8
	BlockID uint64
	Cost    uint64
}

TransInfo the transaction info

func GetTransInfo

func GetTransInfo(chain uint64, key []byte) TransInfo

GetTransInfo get info of transaction

type Transaction

type Transaction struct {
	TransactionHead
	// contains filtered or unexported fields
}

Transaction the transaction data

type TransactionHead

type TransactionHead struct {
	//signLen uint8
	//sing  []byte
	Time   uint64
	User   Address
	Chain  uint64
	Energy uint64
	Cost   uint64
	Ops    uint8
}

TransactionHead transaction = sign + head + data

type UpdateInfo

type UpdateInfo struct {
	Name Hash
	Life uint64
}

UpdateInfo Information of update app life

type VoteInfo

type VoteInfo struct {
	Admin    Address
	Cost     uint64
	StartDay uint64
}

VoteInfo vote info

func GetVoteInfo

func GetVoteInfo(chain uint64, addr Address) VoteInfo

GetVoteInfo get vote info

Directories

Path Synopsis
test_data

Jump to

Keyboard shortcuts

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