Documentation ¶
Index ¶
- Constants
- func BalanceKey(account string) string
- func StakeContractAddr() string
- func ToDelegationKey(delegatorAddress, validatorAddress string) []byte
- func ToDelegationPrefix(delegatorAddress string) []byte
- func ToEpochKey(epochID string) []byte
- func ToNodeIDKey(addr string) []byte
- func ToReverseNodeIDKey(nodeID string) []byte
- func ToUnbondingDelegationKey(epochID uint64, delegatorAddress, validatorAddress string) []byte
- func ToUnbondingDelegationPrefix(epochID uint64) []byte
- func ToValidatorKey(validatorAddress string) []byte
- func ToValidatorPrefix() []byte
- type Collections
- type DPoSERC20Contract
- type DPoSRuntime
- func (r *DPoSRuntime) Allowance(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (r *DPoSRuntime) Approve(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
- func (r *DPoSRuntime) BalanceOf(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (r *DPoSRuntime) Burn(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
- func (r *DPoSRuntime) Decimals(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (r *DPoSRuntime) Mint(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
- func (r *DPoSRuntime) Owner(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
- func (r *DPoSRuntime) Total(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
- func (r *DPoSRuntime) Transfer(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (r *DPoSRuntime) TransferFrom(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (r *DPoSRuntime) TransferOwnership(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- type DPoSStakeContract
- type DPoSStakeRuntime
- func (s *DPoSStakeRuntime) Delegate(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) GetAllCandidates(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) GetDelegationsByAddress(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) GetNodeID(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) GetUserDelegationByValidator(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) GetValidatorByAddress(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadCompleteUnBoundingEpochNumber(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadEpochBlockNumber(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadEpochByID(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadEpochValidatorNumber(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadLatestEpoch(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadMinSelfDelegation(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) ReadSystemContractAddr(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) SetNodeID(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) UnDelegate(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) UpdateEpochBlockNumber(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) UpdateEpochValidatorNumber(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
- func (s *DPoSStakeRuntime) UpdateMinSelfDelegation(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
Constants ¶
const ( // Balance:map[Account]Value KeyBalanceFormat = "B/%s" // map[sender][to]Value KeyApproveFormat = "A/%s/%s" // The Key of total Supply KeyTotalSupply = "TS" // The Key of Decimals,value:uint32 KeyDecimals = "DEC" // The Key of owner for contract,value:string KeyOwner = "OWN" )
const ( KeyNodeIDFormat = "N/%s" KeyRevNodeFormat = "NR/%s" KeyValidatorFormat = "V/%s" KeyDelegationFormat = "D/%s/%s" KeyEpochFormat = "E/%s" KeyUnbondingDelegationFormat = "U/%s/%s/%s" KeyCurrentEpoch = "CE" KeyMinSelfDelegation = "MSD" KeyCompletionUnbondingEpochNumber = "UEN" // 这个 number 不能改动,若改动,会遇到 unbonding entry 数组中 completionEpochID 不同的情况 KeyEpochValidatorNumber = "EVN" KeyEpochBlockNumber = "EBN" ErrorGetValueByKey = "get value error, key: %s has not been set or value not exists" )
Variables ¶
This section is empty.
Functions ¶
func BalanceKey ¶
func StakeContractAddr ¶
func StakeContractAddr() string
StakeContractAddr - convert stake contract name string to address: base58.Encode(sha256(stake_contract_name))
func ToDelegationKey ¶
ToDelegationKey - Key: D + "/" + DelegatorAddress + "/" + ValidatorAddress
func ToDelegationPrefix ¶
ToDelegationPrefix - Key: D + "/" + DelegatorAddress
func ToReverseNodeIDKey ¶
ToReverseNodeIDKey - Key:NR + "/" + NodeID
func ToUnbondingDelegationKey ¶
ToUnbondingDelegationKey - Key:U + "/" + BigEndian(EpochID) + "/" + DelegatorAddress + "/" + ValidatorAddress
func ToUnbondingDelegationPrefix ¶
ToUnbondingDelegationPrefix - Key:U + "/" + BigEndian(EpochID)
func ToValidatorKey ¶
ToValidatorKey - Key: V + "/" + ValidatorAddress
Types ¶
type Collections ¶
type Collections []string
SelfDelegation array for sort
func (Collections) Len ¶
func (s Collections) Len() int
func (Collections) Less ¶
func (s Collections) Less(i, j int) bool
func (Collections) Swap ¶
func (s Collections) Swap(i, j int)
type DPoSERC20Contract ¶
type DPoSERC20Contract struct {
// contains filtered or unexported fields
}
func NewDPoSERC20Contract ¶
func NewDPoSERC20Contract(log protocol.Logger) *DPoSERC20Contract
func (*DPoSERC20Contract) GetMethod ¶
func (c *DPoSERC20Contract) GetMethod(methodName string) common.ContractFunc
type DPoSRuntime ¶
type DPoSRuntime struct {
// contains filtered or unexported fields
}
[DPoS]
func (*DPoSRuntime) Allowance ¶
func (r *DPoSRuntime) Allowance(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
Allowance params["from"]:${from} params["to"]:${to} return value of approve
func (*DPoSRuntime) Approve ¶
func (r *DPoSRuntime) Approve(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
Approve It is equal with approve(spender string, value uint64) error; for ETH params["to"]:${to} params["value"]:${value} return token value for ${sender} to ${to}
func (*DPoSRuntime) BalanceOf ¶
func (r *DPoSRuntime) BalanceOf(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
BalanceOf return balance(token) of owner params["owner"]:${owner} return balance of ${owner}
func (*DPoSRuntime) Burn ¶
func (r *DPoSRuntime) Burn(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
Burn 交易的发送者燃烧一定数量的代币,最多可燃烧殆尽 params["value"]:${value} return balance of sender after burn
func (*DPoSRuntime) Decimals ¶
func (r *DPoSRuntime) Decimals(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
Decimals return decimals of DPoS
func (*DPoSRuntime) Mint ¶
func (r *DPoSRuntime) Mint(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
Mint 增发 params["to"]:${to} params["value"]:${value} return newest token of ${to} after mint
func (*DPoSRuntime) Owner ¶
func (r *DPoSRuntime) Owner(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
Owner return owner of DPoS
func (*DPoSRuntime) Total ¶
func (r *DPoSRuntime) Total(txSimContext protocol.TxSimContext, params map[string][]byte) (result []byte, err error)
Total return total supply of tokens
func (*DPoSRuntime) Transfer ¶
func (r *DPoSRuntime) Transfer(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
Transfer It is equal with transfer(to string, value uint64) for ETH params["to"]:${to} params["value"]:${value} return token value of ${sender} after transfer
func (*DPoSRuntime) TransferFrom ¶
func (r *DPoSRuntime) TransferFrom(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
TransferFrom 交易的发送者,从from的账号中转移指定数目的token给to账户 该操作需要approve,即from已经提前允许当前用户允许转移操作 params["from"]:${from} params["to"]:${to} params["value"]:${value} return token value of ${from} after transfer
func (*DPoSRuntime) TransferOwnership ¶
func (r *DPoSRuntime) TransferOwnership(txSimContext protocol.TxSimContext, params map[string][]byte) ([]byte, error)
TransferOwnership 转移拥有者给其他账户 params["to"]:${to} return new owner
type DPoSStakeContract ¶
type DPoSStakeContract struct {
// contains filtered or unexported fields
}
main implement here
func NewDPoSStakeContract ¶
func NewDPoSStakeContract(log protocol.Logger) *DPoSStakeContract
func (*DPoSStakeContract) GetMethod ¶
func (d *DPoSStakeContract) GetMethod(methodName string) common.ContractFunc
type DPoSStakeRuntime ¶
type DPoSStakeRuntime struct {
// contains filtered or unexported fields
}
func NewDPoSStakeRuntime ¶
func NewDPoSStakeRuntime(log protocol.Logger) *DPoSStakeRuntime
新建 stake Runtime
func (*DPoSStakeRuntime) Delegate ¶
func (s *DPoSStakeRuntime) Delegate(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
* Delegate(to string, amount string) (delegation, error) // 创建抵押,更新验证人,如果MsgSender是给自己,即给自己抵押,则创建验证人 @params["to"] 抵押的目标验证人 @params["amount"] 抵押数量,乘上erc20合约 decimal 的结果值,比如用户认知的1USD,系统内是 1 * 10 ^ 18 return Delegation
func (*DPoSStakeRuntime) GetAllCandidates ¶
func (s *DPoSStakeRuntime) GetAllCandidates(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
GetAllValidator() []ValidatorAddress // 返回所有满足最低抵押条件验证人候选人 return ValidatorVector
func (*DPoSStakeRuntime) GetDelegationsByAddress ¶
func (s *DPoSStakeRuntime) GetDelegationsByAddress( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
GetDelegationsByAddress() []Delegation // 返回所有 Delegation @params["address"] return DelegationInfo
func (*DPoSStakeRuntime) GetNodeID ¶
func (s *DPoSStakeRuntime) GetNodeID(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
GetNodeID - 系统节点自身身份查询
func (*DPoSStakeRuntime) GetUserDelegationByValidator ¶
func (s *DPoSStakeRuntime) GetUserDelegationByValidator( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
GetUserDelegationByValidator() Delegation // 返回所有 Delegation @params["validator_address"] return Delegation
func (*DPoSStakeRuntime) GetValidatorByAddress ¶
func (s *DPoSStakeRuntime) GetValidatorByAddress( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
GetValidatorByAddress() Validator // 返回所有满足最低抵押条件验证人 @params["address"] return Validator
func (*DPoSStakeRuntime) ReadCompleteUnBoundingEpochNumber ¶
func (s *DPoSStakeRuntime) ReadCompleteUnBoundingEpochNumber( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadEpochBlockNumber() string // 读取世代的出块数量 return string
func (*DPoSStakeRuntime) ReadEpochBlockNumber ¶
func (s *DPoSStakeRuntime) ReadEpochBlockNumber( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadEpochBlockNumber() string // 读取世代的出块数量 return string
func (*DPoSStakeRuntime) ReadEpochByID ¶
func (s *DPoSStakeRuntime) ReadEpochByID(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadEpochByID() []ValidatorAddress // 读取指定ID的世代数据 @params["epoch_id"] 查询的世代ID return Epoch
func (*DPoSStakeRuntime) ReadEpochValidatorNumber ¶
func (s *DPoSStakeRuntime) ReadEpochValidatorNumber( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadEpochValidatorNumber() string // 读取每个世代验证人数量 return string
func (*DPoSStakeRuntime) ReadLatestEpoch ¶
func (s *DPoSStakeRuntime) ReadLatestEpoch(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadEpochByID() []ValidatorAddress // 读取当前世代数据 return Epoch
func (*DPoSStakeRuntime) ReadMinSelfDelegation ¶
func (s *DPoSStakeRuntime) ReadMinSelfDelegation( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadMinSelfDelegation() string // 读取验证人最少抵押token数量 return string
func (*DPoSStakeRuntime) ReadSystemContractAddr ¶
func (s *DPoSStakeRuntime) ReadSystemContractAddr( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
ReadSystemContractAddr() string // 读取stake系统合约的地址 return string
func (*DPoSStakeRuntime) SetNodeID ¶
func (s *DPoSStakeRuntime) SetNodeID(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
SetNodeID - 系统加入节点绑定自身身份
func (*DPoSStakeRuntime) UnDelegate ¶
func (s *DPoSStakeRuntime) UnDelegate(context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
Undelegation(from string, amount string) bool // 解除抵押,更新验证人 @params["from"] 解质押的验证人 @params["amount"] 解质押数量,1 * 10 ^ 18 return UnbondingDelegation
func (*DPoSStakeRuntime) UpdateEpochBlockNumber ¶
func (s *DPoSStakeRuntime) UpdateEpochBlockNumber( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
UpdateEpochBlockNumber() bool // 更新世代的出块数量 @params["epoch_block_number"] return nil
func (*DPoSStakeRuntime) UpdateEpochValidatorNumber ¶
func (s *DPoSStakeRuntime) UpdateEpochValidatorNumber( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
更新每个世代验证人数量,不能大于当前所有验证人数量 UpdateEpochValidatorNumber() string @params["epoch_validator_number"] return string
func (*DPoSStakeRuntime) UpdateMinSelfDelegation ¶
func (s *DPoSStakeRuntime) UpdateMinSelfDelegation( context protocol.TxSimContext, params map[string][]byte) ([]byte, error)
更新验证人最少抵押token数量,当提高最少抵押门槛时,原先的 validator 状态不会更新,validator 需要尽块增加抵押 UpdateMinSelfDelegation() string @params["min_self_delegation"] return string