token

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: ISC Imports: 16 Imported by: 0

README

Qitmeer Token

Prerequisites

For the convenience of our explanation, we take the private net as an example.

    ./qitmeer --privnet
    cd ./script

How to create a new token ?

    ./cli.sh createTokenRawTx new [CoinId] [CoinName] [TokenOwnersAddress] [UpLimit]
    ./cli.sh txSign fff2cefe258ca60ae5f5abec99b5d63e2a561c40d784ee50b04eddf8efc84b0d [RawTxHex]  
  • RawTxHex is results of the previous step.
  • fff2... is private key from testwallet
  • Please be careful not to use txSign in a formal scenario because it is not safe. Be sure to use qitmeer-wallet in formal cases.
    ./cli.sh sendRawTx [SignedRawTxHex]
    ./cli.sh generate 1
  • Finally, you can query the token status of the Qitmeer node.
    ./cli.sh tokeninfo

How to renew a token ?

    ./cli.sh createTokenRawTx renew [CoinId] [CoinName] [TokenOwnersAddress] [UpLimit]
    
    See above...
    ...

How to validate a token ?

    ./cli.sh createTokenRawTx validate [CoinId] 
    
    See above...
    ...

How to invalidate a token ?

    ./cli.sh createTokenRawTx invalidate [CoinId]
    
    See above...
    ...

Documentation

Index

Constants

View Source
const (
	// TokenMintScriptLen is the length of a TokenMint script
	// <OP_DATA_64> <signature> <OP_DATA_33> <public key>  <OP_DATA_2> <token_id> <OP_TOKEN_MINT>
	// 1 + 64 + 1 + 33 + 1 + 2 + 1 = 103
	TokenMintScriptLen = 103
	// TokenUnMintScriptLen is the length of a TokenUnMint script
	// <OP_DATA_64> <signature> <OP_DATA_33> <public key>  <OP_DATA_2> <token_id> <OP_TOKEN_UNMINT>
	// 1 + 64 + 1 + 33 + 1 + 2 + 1 = 103
	TokenUnMintScriptLen = 103

	// TokenIdSize is the length of a TokenId (two bytes uint16)
	TokenIdSize = 2
)
View Source
const MaxTokenNameLength = 6

Variables

This section is empty.

Functions

func CheckMintUpdate

func CheckMintUpdate(update *BalanceUpdate) error

func CheckTokenMint

func CheckTokenMint(tx *types.Transaction) (signature []byte, pubKey []byte, tokenId []byte, err error)

CheckTokenMint verifies the input if is a valid TOKEN_MINT transaction. The function return the signature, public key, tokenId and an error. The function ONLY check if the format is correct. for the returned signature, public key and token id. The callee MUST to do additional check for the returned values.

func CheckTokenUnMint

func CheckTokenUnMint(tx *types.Transaction) (signature []byte, pubKey []byte, tokenId []byte, err error)

CheckTokenUnMint verifies the input if is a valid TOKEN_UNMINT transaction. The function return the signature, public key, tokenId and an error. The function ONLY check if the format is correct. for the returned signature, public key and token id. The callee MUST to do additional check for the returned values.

func CheckUnMintUpdate

func CheckUnMintUpdate(update *BalanceUpdate) error

func DBPutTokenState

func DBPutTokenState(dbTx database.Tx, bid uint32, ts *TokenState) error

dbPutTokenState put a token balance record into the token state database. the key is the provided block hash

func DBRemoveTokenState

func DBRemoveTokenState(dbTx database.Tx, id uint32) error

func IsTokenMint

func IsTokenMint(tx *types.Transaction) bool

IsTokenMint returns true if the input transaction is a valid TOKEN_MINT NOTICE: the function DOES NOT check the signature and pubKey and tokenId.

func IsTokenUnMint

func IsTokenUnMint(tx *types.Transaction) bool

IsTokenUnMint returns true if the input transaction is a valid TOKEN_UlMINT NOTICE: the function DOES NOT check the signature and pubKey and tokenId.

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BalanceUpdate

type BalanceUpdate struct {
	*TokenUpdate
	MeerAmount  int64
	TokenAmount types.Amount
	// contains filtered or unexported fields
}

balanceUpdate specifies the type and update record of the values that change a token balance. for TOKON_MINT, the values should add on the meerlock and token balance for TOKEN_UNMINT, the values should subtract from the meerlock and token balance

func NewBalanceUpdate

func NewBalanceUpdate(tx *types.Transaction) (*BalanceUpdate, error)

func (*BalanceUpdate) CacheHash

func (bu *BalanceUpdate) CacheHash() *hash.Hash

func (*BalanceUpdate) CheckSanity

func (bu *BalanceUpdate) CheckSanity() error

func (*BalanceUpdate) Deserialize

func (bu *BalanceUpdate) Deserialize(data []byte) (int, error)

func (*BalanceUpdate) GetHash

func (bu *BalanceUpdate) GetHash() *hash.Hash

func (*BalanceUpdate) Serialize

func (bu *BalanceUpdate) Serialize() ([]byte, error)

type ITokenUpdate

type ITokenUpdate interface {
	GetType() types.TxType
	GetHash() *hash.Hash
	Serialize() ([]byte, error)
	Deserialize(data []byte) (int, error)
	CheckSanity() error
}

func NewTokenUpdate

func NewTokenUpdate(tu *TokenUpdate) ITokenUpdate

func NewUpdateFromTx

func NewUpdateFromTx(tx *types.Transaction) (ITokenUpdate, error)

type TokenBalance

type TokenBalance struct {
	Balance    int64
	LockedMeer int64
}

TokenBalance specifies the token balance and the locked meer amount

type TokenBalancesMap

type TokenBalancesMap map[types.CoinID]TokenBalance

func (*TokenBalancesMap) Copy

func (tb *TokenBalancesMap) Copy() *TokenBalancesMap

func (*TokenBalancesMap) String

func (tb *TokenBalancesMap) String() string

func (*TokenBalancesMap) Update

func (tbs *TokenBalancesMap) Update(update *BalanceUpdate) error

func (*TokenBalancesMap) Updates

func (tbs *TokenBalancesMap) Updates(updates []BalanceUpdate) error

type TokenFeeConfig

type TokenFeeConfig struct {
	Type  types.FeeType
	Value int64
}

func NewTokenFeeConfig

func NewTokenFeeConfig(data int64) *TokenFeeConfig

func (*TokenFeeConfig) GetData

func (tf *TokenFeeConfig) GetData() int64

type TokenState

type TokenState struct {
	PrevStateID uint32
	Types       TokenTypesMap
	Balances    TokenBalancesMap
	Updates     []ITokenUpdate
}

tokenState specifies the token balance of the current block. the updates are written in the same order as the tx in the block, which is used to verify the correctness of the token balance

func BuildGenesisTokenState

func BuildGenesisTokenState() *TokenState

TODO: You can customize the initial value

func DBFetchTokenState

func DBFetchTokenState(dbTx database.Tx, bid uint32) (*TokenState, error)

dbFetchTokenState fetch the token balance record from the token state database. the key is the input block hash.

func (*TokenState) CheckFees

func (ts *TokenState) CheckFees(fees types.AmountMap) error

func (*TokenState) Commit

func (ts *TokenState) Commit() error

func (*TokenState) Deserialize

func (ts *TokenState) Deserialize(data []byte) (int, error)

Deserialize function will deserializes token state from the byte slice

func (*TokenState) Serialize

func (ts *TokenState) Serialize() ([]byte, error)

Serialize function will serialize the token state into byte slice

func (*TokenState) Update

func (ts *TokenState) Update() error

type TokenType

type TokenType struct {
	Id      types.CoinID
	Owners  []byte
	UpLimit uint64
	Enable  bool
	Name    string
	FeeCfg  TokenFeeConfig
}

func (*TokenType) Deserialize

func (tt *TokenType) Deserialize(data []byte) (int, error)

func (*TokenType) GetAddress

func (tt *TokenType) GetAddress() types.Address

func (*TokenType) Serialize

func (tt *TokenType) Serialize() ([]byte, error)

type TokenTypesMap

type TokenTypesMap map[types.CoinID]TokenType

func (*TokenTypesMap) Ids

func (ttm *TokenTypesMap) Ids() []string

func (*TokenTypesMap) Update

func (ttm *TokenTypesMap) Update(update *TypeUpdate) error

type TokenUpdate

type TokenUpdate struct {
	Typ types.TxType
}

func (*TokenUpdate) Deserialize

func (tu *TokenUpdate) Deserialize(data []byte) (int, error)

func (*TokenUpdate) GetType

func (tu *TokenUpdate) GetType() types.TxType

func (*TokenUpdate) Serialize

func (tu *TokenUpdate) Serialize() ([]byte, error)

type TypeUpdate

type TypeUpdate struct {
	*TokenUpdate
	Tt TokenType
	// contains filtered or unexported fields
}

func NewTypeUpdateFromTx

func NewTypeUpdateFromTx(tx *types.Transaction) (*TypeUpdate, error)

func (*TypeUpdate) CacheHash

func (tu *TypeUpdate) CacheHash() *hash.Hash

func (*TypeUpdate) CheckSanity

func (tu *TypeUpdate) CheckSanity() error

func (*TypeUpdate) Deserialize

func (tu *TypeUpdate) Deserialize(data []byte) (int, error)

func (*TypeUpdate) GetHash

func (tu *TypeUpdate) GetHash() *hash.Hash

func (*TypeUpdate) Serialize

func (tu *TypeUpdate) Serialize() ([]byte, error)

Jump to

Keyboard shortcuts

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