contracts

package
v0.0.3-powserver Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: GPL-3.0 Imports: 13 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MethodNameCreateConsensusGroup        = "CreateConsensusGroup"
	MethodNameCancelConsensusGroup        = "CancelConsensusGroup"
	MethodNameReCreateConsensusGroup      = "ReCreateConsensusGroup"
	VariableNameConsensusGroupInfo        = "consensusGroupInfo"
	VariableNameConditionRegisterOfPledge = "registerOfPledge"
	VariableNameConditionVoteOfKeepToken  = "voteOfKeepToken"
)
View Source
const (
	MethodNameMintage             = "Mintage"
	MethodNameMintageCancelPledge = "CancelPledge"
	VariableNameMintage           = "mintage"
)
View Source
const (
	MethodNamePledge             = "Pledge"
	MethodNameCancelPledge       = "CancelPledge"
	VariableNamePledgeInfo       = "pledgeInfo"
	VariableNamePledgeBeneficial = "pledgeBeneficial"
)
View Source
const (
	MethodNameRegister           = "Register"
	MethodNameCancelRegister     = "CancelRegister"
	MethodNameReward             = "Reward"
	MethodNameUpdateRegistration = "UpdateRegistration"
	VariableNameRegistration     = "registration"
	VariableNameHisName          = "hisName"
)
View Source
const (
	MethodNameVote         = "Vote"
	MethodNameCancelVote   = "CancelVote"
	VariableNameVoteStatus = "voteStatus"
)
View Source
const (
	RegisterGas               uint64 = 62200
	UpdateRegistrationGas     uint64 = 62200
	CancelRegisterGas         uint64 = 83200
	RewardGas                 uint64 = 238800
	VoteGas                   uint64 = 21000
	CancelVoteGas             uint64 = 62000
	PledgeGas                 uint64 = 21000
	CancelPledgeGas           uint64 = 103400
	CreateConsensusGroupGas   uint64 = 62200
	CancelConsensusGroupGas   uint64 = 83200
	ReCreateConsensusGroupGas uint64 = 62200
	MintageGas                uint64 = 83200
	MintageCancelPledgeGas    uint64 = 83200

	MaxRewardCount uint64 = 7776000
)

Variables

View Source
var (
	AddressRegister, _       = types.BytesToAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
	AddressVote, _           = types.BytesToAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2})
	AddressPledge, _         = types.BytesToAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3})
	AddressConsensusGroup, _ = types.BytesToAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4})
	AddressMintage, _        = types.BytesToAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5})
)
View Source
var (
	ContractsParamsTest = ContractsParams{
		MinPledgeHeight:                  1,
		CreateConsensusGroupPledgeHeight: 1,
		MintagePledgeHeight:              1,
		RewardHeightLimit:                1,
	}
	ContractsParamsMainNet = ContractsParams{
		MinPledgeHeight:                  3600 * 24 * 3,
		CreateConsensusGroupPledgeHeight: 3600 * 24 * 3,
		MintagePledgeHeight:              3600 * 24 * 30 * 3,
		RewardHeightLimit:                60 * 30,
	}
)
View Source
var (
	ABIConsensusGroup, _ = abi.JSONToABIContract(strings.NewReader(jsonConsensusGroup))
)
View Source
var (
	ABIMintage, _ = abi.JSONToABIContract(strings.NewReader(jsonMintage))
)
View Source
var (
	ABIPledge, _ = abi.JSONToABIContract(strings.NewReader(jsonPledge))
)
View Source
var (
	ABIRegister, _ = abi.JSONToABIContract(strings.NewReader(jsonRegister))
)
View Source
var (
	ABIVote, _ = abi.JSONToABIContract(strings.NewReader(jsonVote))
)
View Source
var SimpleCountingRuleList = map[ConditionCode]createConsensusGroupCondition{
	RegisterConditionOfPledge: &registerConditionOfPledge{},
	VoteConditionOfDefault:    &voteConditionOfDefault{},
	VoteConditionOfBalance:    &voteConditionOfKeepToken{},
}

Functions

func CalcReward

func CalcReward(db vmctxt_interface.VmDatabase, old *Registration, total bool) (uint64, uint64, *big.Int)

func CheckCreateConsensusGroupData

func CheckCreateConsensusGroupData(db vmctxt_interface.VmDatabase, param *ConsensusGroupInfo) error

func CheckToken

func CheckToken(param ParamMintage) error

func GetAddrFromVoteKey

func GetAddrFromVoteKey(key []byte) types.Address

func GetBeneficialFromPledgeKey

func GetBeneficialFromPledgeKey(key []byte) types.Address

func GetConsensusGroupKey

func GetConsensusGroupKey(gid types.Gid) []byte

func GetGidFromConsensusGroupKey

func GetGidFromConsensusGroupKey(key []byte) types.Gid

func GetGidFromCreateContractData

func GetGidFromCreateContractData(data []byte) types.Gid

func GetHisNameKey

func GetHisNameKey(addr types.Address, gid types.Gid) []byte

func GetMintageKey

func GetMintageKey(tokenId types.TokenTypeId) []byte

func GetNewContractData

func GetNewContractData(bytecode []byte, gid types.Gid) []byte

TODO following method belongs to vm

func GetPledgeBeneficialAmount

func GetPledgeBeneficialAmount(db StorageDatabase, beneficial types.Address) *big.Int

func GetPledgeBeneficialKey

func GetPledgeBeneficialKey(beneficial types.Address) []byte

func GetPledgeKey

func GetPledgeKey(addr types.Address, pledgeBeneficialKey []byte) []byte

func GetRegisterKey

func GetRegisterKey(name string, gid types.Gid) []byte

func GetRegisterMessageForSignature

func GetRegisterMessageForSignature(accountAddress types.Address, gid types.Gid) []byte

Sign certain tx data using private key of node address to prove ownership of node address

func GetTokenIdFromMintageKey

func GetTokenIdFromMintageKey(key []byte) types.TokenTypeId

func GetTokenMap

func GetTokenMap(db StorageDatabase) map[types.TokenTypeId]*TokenInfo

func GetVoteKey

func GetVoteKey(addr types.Address, gid types.Gid) []byte

func InitContractsConfig

func InitContractsConfig(isTestParam bool)

func IsExistGid

func IsExistGid(db vmctxt_interface.VmDatabase, gid types.Gid) bool

func IsPledgeKey

func IsPledgeKey(key []byte) bool

func IsRegisterKey

func IsRegisterKey(key []byte) bool

func IsUserAccount

func IsUserAccount(db vmctxt_interface.VmDatabase, addr types.Address) bool

func NewContractAddress

func NewContractAddress(accountAddress types.Address, accountBlockHeight uint64, prevBlockHash types.Hash, snapshotHash types.Hash) types.Address

func NewGid

func NewGid(accountAddress types.Address, accountBlockHeight uint64, prevBlockHash types.Hash, snapshotHash types.Hash) types.Gid

func NewTokenId

func NewTokenId(accountAddress types.Address, accountBlockHeight uint64, prevBlockHash types.Hash, snapshotHash types.Hash) types.TokenTypeId

func PackConsensusGroupConditionParam

func PackConsensusGroupConditionParam(conditionIdPrefix ConditionCode, conditionId uint8, params ...interface{}) ([]byte, error)

pack consensus group condition params by condition id

func PackMethodParam

func PackMethodParam(contractsAddr types.Address, methodName string, params ...interface{}) ([]byte, error)

pack method params to byte slice

Types

type ConditionCode

type ConditionCode uint8
const (
	RegisterConditionPrefix   ConditionCode = 10
	VoteConditionPrefix       ConditionCode = 20
	RegisterConditionOfPledge ConditionCode = 11
	VoteConditionOfDefault    ConditionCode = 21
	VoteConditionOfBalance    ConditionCode = 22
)

type ConsensusGroupInfo

type ConsensusGroupInfo struct {
	Gid                    types.Gid         // Consensus group id
	NodeCount              uint8             // Active miner count
	Interval               int64             // Timestamp gap between two continuous block
	PerCount               int64             // Continuous block generation interval count
	RandCount              uint8             // Random miner count
	RandRank               uint8             // Chose random miner with a rank limit of vote
	CountingTokenId        types.TokenTypeId // Token id for selecting miner through vote
	RegisterConditionId    uint8
	RegisterConditionParam []byte
	VoteConditionId        uint8
	VoteConditionParam     []byte
	Owner                  types.Address
	PledgeAmount           *big.Int
	WithdrawHeight         uint64
}

func GetActiveConsensusGroupList

func GetActiveConsensusGroupList(db StorageDatabase) []*ConsensusGroupInfo

func GetConsensusGroup

func GetConsensusGroup(db StorageDatabase, gid types.Gid) *ConsensusGroupInfo

func (*ConsensusGroupInfo) IsActive

func (groupInfo *ConsensusGroupInfo) IsActive() bool

type ContractsParams

type ContractsParams struct {
	MinPledgeHeight                  uint64 // Minimum pledge height
	CreateConsensusGroupPledgeHeight uint64 // Pledge height for registering to be a super node of snapshot group and common delegate group
	MintagePledgeHeight              uint64 // Pledge height for mintage if choose to pledge instead of destroy vite token
	RewardHeightLimit                uint64 // Cannot get snapshot block reward of current few blocks, for latest snapshot block could be reverted
}

type MethodCancelConsensusGroup

type MethodCancelConsensusGroup struct{}

func (*MethodCancelConsensusGroup) DoReceive

func (p *MethodCancelConsensusGroup) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodCancelConsensusGroup) DoSend

func (p *MethodCancelConsensusGroup) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

Cancel consensus group and get pledge back. A canceled consensus group(no-active) will not generate contract blocks after cancel receive block is confirmed. Consensus group name is kept even if canceled.

func (*MethodCancelConsensusGroup) GetFee

func (p *MethodCancelConsensusGroup) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodCancelConsensusGroup) GetRefundData

func (p *MethodCancelConsensusGroup) GetRefundData() []byte

type MethodCancelPledge

type MethodCancelPledge struct{}

func (*MethodCancelPledge) DoReceive

func (p *MethodCancelPledge) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodCancelPledge) DoSend

func (p *MethodCancelPledge) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

cancel pledge ViteToken

func (*MethodCancelPledge) GetFee

func (p *MethodCancelPledge) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodCancelPledge) GetRefundData

func (p *MethodCancelPledge) GetRefundData() []byte

type MethodCancelRegister

type MethodCancelRegister struct {
}

func (*MethodCancelRegister) DoReceive

func (p *MethodCancelRegister) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodCancelRegister) DoSend

func (p *MethodCancelRegister) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

cancel register to become a super node of a consensus group after registered for 3 month, get 100w ViteToken back

func (*MethodCancelRegister) GetFee

func (p *MethodCancelRegister) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodCancelRegister) GetRefundData

func (p *MethodCancelRegister) GetRefundData() []byte

type MethodCancelVote

type MethodCancelVote struct {
}

func (*MethodCancelVote) DoReceive

func (p *MethodCancelVote) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodCancelVote) DoSend

func (p *MethodCancelVote) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

cancel vote for a super node of a consensus group

func (*MethodCancelVote) GetFee

func (p *MethodCancelVote) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodCancelVote) GetRefundData

func (p *MethodCancelVote) GetRefundData() []byte

type MethodCreateConsensusGroup

type MethodCreateConsensusGroup struct{}

func (*MethodCreateConsensusGroup) DoReceive

func (p *MethodCreateConsensusGroup) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodCreateConsensusGroup) DoSend

func (p *MethodCreateConsensusGroup) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

func (*MethodCreateConsensusGroup) GetFee

func (p *MethodCreateConsensusGroup) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodCreateConsensusGroup) GetRefundData

func (p *MethodCreateConsensusGroup) GetRefundData() []byte

type MethodMintage

type MethodMintage struct{}

func (*MethodMintage) DoReceive

func (p *MethodMintage) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodMintage) DoSend

func (p *MethodMintage) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

func (*MethodMintage) GetFee

func (p *MethodMintage) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodMintage) GetRefundData

func (p *MethodMintage) GetRefundData() []byte

type MethodMintageCancelPledge

type MethodMintageCancelPledge struct{}

func (*MethodMintageCancelPledge) DoReceive

func (p *MethodMintageCancelPledge) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodMintageCancelPledge) DoSend

func (p *MethodMintageCancelPledge) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

func (*MethodMintageCancelPledge) GetFee

func (p *MethodMintageCancelPledge) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodMintageCancelPledge) GetRefundData

func (p *MethodMintageCancelPledge) GetRefundData() []byte

type MethodPledge

type MethodPledge struct{}

func (*MethodPledge) DoReceive

func (p *MethodPledge) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodPledge) DoSend

func (p *MethodPledge) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

pledge ViteToken for a beneficial to get quota

func (*MethodPledge) GetFee

func (p *MethodPledge) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodPledge) GetRefundData

func (p *MethodPledge) GetRefundData() []byte

type MethodReCreateConsensusGroup

type MethodReCreateConsensusGroup struct{}

func (*MethodReCreateConsensusGroup) DoReceive

func (p *MethodReCreateConsensusGroup) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodReCreateConsensusGroup) DoSend

func (p *MethodReCreateConsensusGroup) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

Pledge again for a canceled consensus group. A consensus group will start generate contract blocks after recreate receive block is confirmed.

func (*MethodReCreateConsensusGroup) GetFee

func (p *MethodReCreateConsensusGroup) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodReCreateConsensusGroup) GetRefundData

func (p *MethodReCreateConsensusGroup) GetRefundData() []byte

type MethodRegister

type MethodRegister struct {
}

func (*MethodRegister) DoReceive

func (p *MethodRegister) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodRegister) DoSend

func (p *MethodRegister) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

register to become a super node of a consensus group, lock 1 million ViteToken for 3 month

func (*MethodRegister) GetFee

func (p *MethodRegister) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodRegister) GetRefundData

func (p *MethodRegister) GetRefundData() []byte

type MethodReward

type MethodReward struct {
}

func (*MethodReward) DoReceive

func (p *MethodReward) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodReward) DoSend

func (p *MethodReward) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

get reward of generating snapshot block

func (*MethodReward) GetFee

func (p *MethodReward) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodReward) GetRefundData

func (p *MethodReward) GetRefundData() []byte

type MethodUpdateRegistration

type MethodUpdateRegistration struct {
}

func (*MethodUpdateRegistration) DoReceive

func (p *MethodUpdateRegistration) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodUpdateRegistration) DoSend

func (p *MethodUpdateRegistration) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

update registration info

func (*MethodUpdateRegistration) GetFee

func (p *MethodUpdateRegistration) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodUpdateRegistration) GetRefundData

func (p *MethodUpdateRegistration) GetRefundData() []byte

type MethodVote

type MethodVote struct {
}

func (*MethodVote) DoReceive

func (p *MethodVote) DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error

func (*MethodVote) DoSend

func (p *MethodVote) DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)

vote for a super node of a consensus group

func (*MethodVote) GetFee

func (p *MethodVote) GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)

func (*MethodVote) GetRefundData

func (p *MethodVote) GetRefundData() []byte

type NodeConfig

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

type ParamCancelPledge

type ParamCancelPledge struct {
	Beneficial types.Address
	Amount     *big.Int
}

type ParamCancelRegister

type ParamCancelRegister struct {
	Gid  types.Gid
	Name string
}

type ParamMintage

type ParamMintage struct {
	TokenId     types.TokenTypeId
	TokenName   string
	TokenSymbol string
	TotalSupply *big.Int
	Decimals    uint8
}

type ParamRegister

type ParamRegister struct {
	Gid      types.Gid
	Name     string
	NodeAddr types.Address
}

type ParamReward

type ParamReward struct {
	Gid            types.Gid
	Name           string
	BeneficialAddr types.Address
}

type ParamVote

type ParamVote struct {
	Gid      types.Gid
	NodeName string
}

type PledgeInfo

type PledgeInfo struct {
	Amount         *big.Int
	WithdrawHeight uint64
	BeneficialAddr types.Address
}

func GetPledgeInfoList

func GetPledgeInfoList(db StorageDatabase, addr types.Address) ([]*PledgeInfo, *big.Int)

type PrecompiledContractMethod

type PrecompiledContractMethod interface {
	GetFee(context contractsContext, block *vm_context.VmAccountBlock) (*big.Int, error)
	// calc and use quota, check tx data
	DoSend(context contractsContext, block *vm_context.VmAccountBlock, quotaLeft uint64) (uint64, error)
	// check status, update state
	DoReceive(context contractsContext, block *vm_context.VmAccountBlock, sendBlock *ledger.AccountBlock) error
	// refund data at receive error
	GetRefundData() []byte
}

type Registration

type Registration struct {
	Name           string
	NodeAddr       types.Address
	PledgeAddr     types.Address
	Amount         *big.Int
	WithdrawHeight uint64
	RewardHeight   uint64
	CancelHeight   uint64
	HisAddrList    []types.Address
}

func GetCandidateList

func GetCandidateList(db StorageDatabase, gid types.Gid) []*Registration

func GetRegistration

func GetRegistration(db StorageDatabase, name string, gid types.Gid) *Registration

func GetRegistrationList

func GetRegistrationList(db StorageDatabase, gid types.Gid, pledgeAddr types.Address) []*Registration

func (*Registration) IsActive

func (r *Registration) IsActive() bool

type StorageDatabase

type StorageDatabase interface {
	GetStorage(addr *types.Address, key []byte) []byte
	NewStorageIterator(addr *types.Address, prefix []byte) vmctxt_interface.StorageIterator
}

type TokenInfo

type TokenInfo struct {
	TokenName      string        `json:"tokenName"`
	TokenSymbol    string        `json:"tokenSymbol"`
	TotalSupply    *big.Int      `json:"totalSupply"`
	Decimals       uint8         `json:"decimals"`
	Owner          types.Address `json:"owner"`
	PledgeAmount   *big.Int      `json:"pledgeAmount"`
	WithdrawHeight uint64        `json:"withdrawHeight"`
}

func GetTokenById

func GetTokenById(db StorageDatabase, tokenId types.TokenTypeId) *TokenInfo

type VariableConditionRegisterOfPledge

type VariableConditionRegisterOfPledge struct {
	PledgeAmount *big.Int
	PledgeToken  types.TokenTypeId
	PledgeHeight uint64
}

type VariableConditionVoteOfKeepToken

type VariableConditionVoteOfKeepToken struct {
	KeepAmount *big.Int
	KeepToken  types.TokenTypeId
}

type VariablePledgeBeneficial

type VariablePledgeBeneficial struct {
	Amount *big.Int
}

type VoteInfo

type VoteInfo struct {
	VoterAddr types.Address
	NodeName  string
}

func GetVote

func GetVote(db StorageDatabase, gid types.Gid, addr types.Address) *VoteInfo

func GetVoteList

func GetVoteList(db StorageDatabase, gid types.Gid) []*VoteInfo

Jump to

Keyboard shortcuts

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