xtoken

package
v0.0.0-...-56f3d1a Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

XToken 系统合约主要功能分为两部分:创建ERC20标准的代币,和支持提案投票功能。

Documentation

Index

Constants

View Source
const (
	ProposalVoting = iota + 1 // 从1开始。
	ProposalSuccess
	ProposalFailure
	ProposalInvalid // 参与提案的总票数不足时,提案为此状态。
	ProposalStopped // 提案投票结束
)
View Source
const (
	NewToken        = "NewToken"
	TotalSupply     = "TotalSupply"
	BalanceOf       = "BalanceOf"
	Transfer        = "Transfer"
	TransferFrom    = "TransferFrom"
	Approve         = "Approve"
	Allowance       = "Allowance"
	AddSupply       = "AddSupply"
	Burn            = "Burn"
	QueryToken      = "QueryToken"
	QueryTokenOwner = "QueryTokenOwner"

	Propose            = "Propose"
	Vote               = "Vote"
	CheckVote          = "CheckVote"
	StopVote           = "StopVote"
	QueryProposal      = "QueryProposal"
	QueryProposalVotes = "QueryProposalVotes"
	QueryTopic         = "QueryTopic"

	AddAdmins   = "AddAdmins"
	DelAdmins   = "DelAdmins"
	QueryAdmins = "QueryAdmins"
	SetFee      = "SetFee"
	GetFee      = "GetFee"

	//Success 成功
	Success = 200
)
View Source
const (
	ConfigName = "engine.yaml"
)
View Source
const (
	XTokenContract = "XToken"
)

Variables

This section is empty.

Functions

func KeyOfAddress2TokenBalance

func KeyOfAddress2TokenBalance(tokenName, address string) string

func KeyOfAddressVotingProposal

func KeyOfAddressVotingProposal(tokenName, address string) string

func KeyOfAdmins

func KeyOfAdmins() string

func KeyOfAllowances

func KeyOfAllowances(tokenName, address string) string

func KeyOfFee

func KeyOfFee(method string) string

func KeyOfID2AddressAgreeVote

func KeyOfID2AddressAgreeVote(tokenName, topic, address string, id *big.Int) string

func KeyOfID2AddressAgreeVotePrefix

func KeyOfID2AddressAgreeVotePrefix(tokenName, topic string, id *big.Int) string

赞成票前缀

func KeyOfID2AddressOpposeVote

func KeyOfID2AddressOpposeVote(tokenName, topic, address string, id *big.Int) string

func KeyOfID2AddressOpposeVotePrefix

func KeyOfID2AddressOpposeVotePrefix(tokenName, topic string, id *big.Int) string

反对票前缀

func KeyOfID2AddressWaiveVote

func KeyOfID2AddressWaiveVote(tokenName, topic, address string, id *big.Int) string

func KeyOfID2AddressWaiveVotePrefix

func KeyOfID2AddressWaiveVotePrefix(tokenName, topic string, id *big.Int) string

弃权票前缀

func KeyOfLatestProposalID

func KeyOfLatestProposalID(tokenName, topic string) string

func KeyOfProposalID

func KeyOfProposalID(tokenName, topic string, id *big.Int) string

func KeyOfProposalResult

func KeyOfProposalResult(tokenName, topic string, id *big.Int) string

此数据为异步计票结果得key不是交易生成的,因此为非交易读写集生成的。

func KeyOfProposer2Proposal

func KeyOfProposer2Proposal(tokenName, address string) string

用户发起的还未结束的提案,存储数据为提案ID以及用户锁定的余额,同一时间只会有同一个提案。

func KeyOfToken

func KeyOfToken(tokenName string) string

func KeyOfToken2AddressBalance

func KeyOfToken2AddressBalance(tokenName, address string) string

func KeyOfTokenOwner

func KeyOfTokenOwner(tokenName string) string

func KeyOfTokenProposal

func KeyOfTokenProposal(tokenName string) string

func KeyOfTopicData

func KeyOfTopicData(tokenName, topic string) string

Types

type Balance

type Balance struct {
	BalanceTotal *big.Int `json:"balanceTotal"`
	Frozen       *big.Int `json:"frozen"`
}

type CheckVoteResult

type CheckVoteResult struct {
	Status      int      `json:"status,omitempty"`
	AgreeCount  *big.Int `json:"agreeCount"`
	OpposeCount *big.Int `json:"opposeCount"`
	WaiveCount  *big.Int `json:"waiveCount"`
}

type Context

type Context struct {
	// 基础上下文
	xcontext.BaseCtx

	BcName string

	Contract contract.Manager
	ChainCtx *common.ChainCtx
}

func NewXTokenCtx

func NewXTokenCtx(cctx *common.ChainCtx) (*Context, error)

type Contract

type Contract struct {
	Admins map[string]bool  // 创世配置的或者节点配置文件写的,如果通过交易设置admin,此字段会作废。
	Fees   map[string]int64 // 创世配置的或者节点配置文件写的,如果通过交易设置fee,此字段会作废。
	// contains filtered or unexported fields
}

func NewContract

func NewContract(admins map[string]bool, fee map[string]int64, ctx *Context) *Contract

func (*Contract) AddAdmins

func (c *Contract) AddAdmins(ctx contract.KContext) (*contract.Response, error)

func (*Contract) AddSupply

func (c *Contract) AddSupply(ctx contract.KContext) (*contract.Response, error)

func (*Contract) Allowance

func (c *Contract) Allowance(ctx contract.KContext) (*contract.Response, error)

func (*Contract) Approve

func (c *Contract) Approve(ctx contract.KContext) (*contract.Response, error)

Approve 授权接口

func (*Contract) BalanceOf

func (c *Contract) BalanceOf(ctx contract.KContext) (*contract.Response, error)

func (*Contract) Burn

func (c *Contract) Burn(ctx contract.KContext) (*contract.Response, error)

func (*Contract) CheckVote

func (c *Contract) CheckVote(ctx contract.KContext) (*contract.Response, error)

投票人数数量少于5k可以使用此接口

func (*Contract) DelAdmins

func (c *Contract) DelAdmins(ctx contract.KContext) (*contract.Response, error)

func (*Contract) GetFee

func (c *Contract) GetFee(ctx contract.KContext) (*contract.Response, error)

func (*Contract) HasVoted

func (c *Contract) HasVoted(ctx contract.KContext, token, topic string, pID *big.Int) (bool, error)

HasVoted check initiator voted, true: voted

func (*Contract) NewToken

func (c *Contract) NewToken(ctx contract.KContext) (*contract.Response, error)

func (*Contract) Propose

func (c *Contract) Propose(ctx contract.KContext) (*contract.Response, error)

func (*Contract) QueryAdmins

func (c *Contract) QueryAdmins(ctx contract.KContext) (*contract.Response, error)

func (*Contract) QueryProposal

func (c *Contract) QueryProposal(ctx contract.KContext) (*contract.Response, error)

func (*Contract) QueryProposalVotes

func (c *Contract) QueryProposalVotes(ctx contract.KContext) (*contract.Response, error)

func (*Contract) QueryToken

func (c *Contract) QueryToken(ctx contract.KContext) (*contract.Response, error)

func (*Contract) QueryTokenOwner

func (c *Contract) QueryTokenOwner(ctx contract.KContext) (*contract.Response, error)

func (*Contract) SetFee

func (c *Contract) SetFee(ctx contract.KContext) (*contract.Response, error)

func (*Contract) StopVote

func (c *Contract) StopVote(ctx contract.KContext) (*contract.Response, error)

StopVote stop a proposal without returning vote result.

func (*Contract) TotalSupply

func (c *Contract) TotalSupply(ctx contract.KContext) (*contract.Response, error)

func (*Contract) Transfer

func (c *Contract) Transfer(ctx contract.KContext) (*contract.Response, error)

func (*Contract) TransferFrom

func (c *Contract) TransferFrom(ctx contract.KContext) (*contract.Response, error)

func (*Contract) Vote

func (c *Contract) Vote(ctx contract.KContext) (*contract.Response, error)

type GenesisProposal

type GenesisProposal struct {
	// 发起提案者账户余额限制。
	ProposeMinToken *big.Int `json:"proposeMinToken"`
	// 提案有效的总投票金额,有效不意味着通过,总投票金额小于此数据时,提案不生效。
	ProposalEffectiveAmount *big.Int    `json:"proposalEffectiveAmount"`
	InitialData             []*Proposal `json:"initialData"`
}

type Manager

type Manager struct {
	Ctx *Context
}

func NewManager

func NewManager(ctx *Context) (*Manager, error)

type Proposal

type Proposal struct {
	Topic    string   `json:"topic"` // 同一个 token 下唯一
	ID       *big.Int `json:"id"`    // 同一个 topic 下唯一
	Proposer string   `json:"proposer"`
	Data     string   `json:"data"`
	Status   int      `json:"status"`
}

type XToken

type XToken struct {
	Name                  string              `json:"name"`
	TotalSupply           *big.Int            `json:"totalSupply"`
	AddSupplyEnabled      bool                `json:"addSupplyEnabled"`
	BurnEnabled           bool                `json:"burnEnabled"`
	Decimal               uint64              `json:"decimal"`
	InitialAllocation     map[string]*big.Int `json:"initialAllocation"`
	ConvertibleProportion *big.Int            `json:"convertibleProportion"`
	GenesisProposal       *GenesisProposal    `json:"genesisProposal"`
}

type XTokenConfig

type XTokenConfig struct {
	XTokenAdmins       map[string]bool
	XTokenFee          map[string]int64
	XTokenContractName string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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