ae4a05b2b8a4de21d9e6f26e9d7992f7f33e89689f3015f3fc8a3a3278815e28c

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: BSD-3-Clause Imports: 22 Imported by: 0

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
)
View Source
const (
	StatBaseInfo = uint8(iota)
	StatTransKey
	StatGuerdon
	StatBlockSizeLimit
	StatAvgBlockSize
	StatHashPower
	StatBlockInterval
	StatSyncInfo
	StatFirstBlockKey
	StatChangingConfig
	StatBroadcast
	StatHateRatio
	StatParentKey
	StatSyncTime
)

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
	// OpsDisableAdmin disable admin
	OpsDisableAdmin
)
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
	SyncOpsHateRatio
)

ops of sync

View Source
const (
	// BaseRelia base reliability
	BaseRelia = 1000
)
View Source
const (
	// MinerNum number of miner pre block
	MinerNum = 11
)

Variables

This section is empty.

Functions

func BlockOnTheChain added in v0.3.2

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

BlockOnTheChain return true if the block is on the chain

func CheckTransList added in v0.3.2

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 DeleteBlockReliability

func DeleteBlockReliability(chain uint64, key []byte)

DeleteBlockReliability delete reliability of block

func DeleteTransaction added in v0.3.5

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

DeleteTransaction delete Transaction

func Exit added in v0.3.9

func Exit()

Exit os exit

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 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 Init added in v0.4.1

func Init()

Init init,open reliability.db and create core app

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, index uint64, user []byte) bool

IsMiner check miner

func ProcessBlockOfChain added in v0.3.2

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 ReadTransactionData

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

ReadTransactionData read transaction data

func SaveBlockReliability

func SaveBlockReliability(chain uint64, key []byte, rb TReliability)

SaveBlockReliability save block reliability

func WriteBlock

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

WriteBlock write block data to database

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 (Address) Empty

func (a Address) Empty() bool

Empty Check where Address is empty

type AdminInfo

type AdminInfo struct {
	App   Hash
	Cost  uint64
	Index uint8
}

AdminInfo register as a admin

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
	Size          uint32
}

Block Block structure, full block data need +(Sign []byte) + (TransList []Hash)

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 uint64 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) SetInt

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

SetInt Storage uint64 data

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 GetParentBlockOfChain

func GetParentBlockOfChain(chain uint64) Hash

GetParentBlockOfChain get parent block of chain

func (Hash) Empty

func (h Hash) Empty() bool

Empty Check whether Hash is empty

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 Miner

type Miner struct {
	Miner [minerNum]Address
	Cost  [minerNum]uint64
}

Miner miner info

func GetMinerInfo

func GetMinerInfo(chain, index uint64) Miner

GetMinerInfo get miner info

type RegMiner

type RegMiner struct {
	Chain uint64
	Index uint64
}

RegMiner info of register miner

type StBlock

type StBlock struct {
	Block
	Key Hash

	TransList      []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) GetReliability

func (b *StBlock) GetReliability() TReliability

GetReliability get block reliability

func (*StBlock) GetSignData

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

GetSignData GetSignData

func (*StBlock) GetTransList

func (b *StBlock) GetTransList() []string

GetTransList GetTransList

func (*StBlock) Output

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

Output Output

func (*StBlock) SetSign

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

SetSign SetSign

func (*StBlock) SetTransList

func (b *StBlock) SetTransList(list []Hash)

SetTransList SetTransList

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) CreateRegisterMiner

func (t *StTrans) CreateRegisterMiner(chain, index, cost uint64)

CreateRegisterMiner RegisterMiner

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) SetSign

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

SetSign 设置签名信息

type TReliability

type TReliability struct {
	Key        Hash    `json:"key,omitempty"`
	Previous   Hash    `json:"previous,omitempty"`
	Parent     Hash    `json:"parent,omitempty"`
	LeftChild  Hash    `json:"left_child,omitempty"`
	RightChild Hash    `json:"right_child,omitempty"`
	Producer   Address `json:"producer,omitempty"`
	Time       uint64  `json:"time,omitempty"`
	Index      uint64  `json:"index,omitempty"`
	HashPower  uint64  `json:"hash_power,omitempty"`
	Miner      bool    `json:"miner,omitempty"`
	Ready      bool    `json:"ready,omitempty"`
}

TReliability Reliability of block

func ReadBlockReliability

func ReadBlockReliability(chain uint64, key []byte) (cl TReliability)

ReadBlockReliability get Reliability of block from db

func (TReliability) Cmp

func (r TReliability) Cmp(y TReliability) int

Cmp compares x and y and returns:

+1 if x >  y
-1 if x <  y
0  if x =  y

func (*TReliability) Recalculation

func (r *TReliability) Recalculation(chain uint64)

Recalculation recalculation

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 TransProc added in v0.4.1

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

TransProc transaction processer for miner

func NewTransProc added in v0.4.1

func NewTransProc(chain uint64, key []byte) *TransProc

NewTransProc new process for miner

func (*TransProc) Close added in v0.4.1

func (p *TransProc) Close()

Close close

func (*TransProc) ProcTrans added in v0.4.1

func (p *TransProc) ProcTrans(key []byte) uint64

ProcTrans process transaction,return size of transaction. return 0 when error

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

Jump to

Keyboard shortcuts

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