coins

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseVersion types.CoinVersion = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

func NewBus

func NewBus(coins *Coins) *Bus

func (*Bus) GetCoin

func (b *Bus) GetCoin(id types.CoinID) *bus.Coin

func (*Bus) SubCoinReserve

func (b *Bus) SubCoinReserve(id types.CoinID, amount *big.Int)

func (*Bus) SubCoinVolume

func (b *Bus) SubCoinVolume(id types.CoinID, amount *big.Int)

type Coins

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

Coins represents coins state in blockchain.

When a coin is created with a CreateCoinTx transaction, such model is created:

Model {
 id
 info
 symbolInfo

 Name
 Crr
 MaxSupply
 Version - is the version of the coin
 Symbol - is the base symbol of the coin
}

Also, SymbolInfo is created:

SymbolInfo {
 OwnerAddress
}

It is a structure that retains the owner of the ticker (not the coin). coin.symbolInfo is saved in the symbolsInfoList map, in which the key is the symbol, and the value is the owner of the coin, and upon commit is written to the db by this key: mainPrefix + symbolPrefix + symbol + infoPrefix.

Also, you need to save all coins for a particular ticker. That is, you need to associate the ticker with all the coins that refer to it. For this, there is a map symbolsList, in which the key is the ticker, and the value is an array of ids of coins that belong to this ticker (just with a different version). When you commit, this array is saved to db by this key: mainPrefix + symbolPrefix + symbol.

The coin model is saved at: mainPrefix + id.

When a coin is re-created with a RecreateCoinTx transaction, the state retrieves an array of coins that refer to this ticker (getBySymbol). Finds the current current version there, changes it to the new version. And the new coin is assigned version 0. The new coin is also added to symbolsList [ticker].

When changing the owner with a ChangeOwnerTx transaction, the state gets the current owner getSymbolInfo (ticker) and changes the owner there and saves it back.

func NewCoins

func NewCoins(stateBus *bus.Bus, iavl tree.MTree) (*Coins, error)

func (*Coins) AddReserve

func (c *Coins) AddReserve(id types.CoinID, amount *big.Int)

func (*Coins) AddVolume

func (c *Coins) AddVolume(id types.CoinID, amount *big.Int)

func (*Coins) ChangeOwner added in v1.2.0

func (c *Coins) ChangeOwner(symbol types.CoinSymbol, owner types.Address)

func (*Coins) Commit

func (c *Coins) Commit() error

func (*Coins) Create

func (c *Coins) Create(id types.CoinID, symbol types.CoinSymbol, name string,
	volume *big.Int, crr uint32, reserve *big.Int, maxSupply *big.Int, owner *types.Address,
)

func (*Coins) Exists

func (c *Coins) Exists(id types.CoinID) bool

func (*Coins) ExistsBySymbol added in v1.2.0

func (c *Coins) ExistsBySymbol(symbol types.CoinSymbol) bool

func (*Coins) Export

func (c *Coins) Export(state *types.AppState)

func (*Coins) GetCoin

func (c *Coins) GetCoin(id types.CoinID) *Model

func (*Coins) GetCoinBySymbol added in v1.2.0

func (c *Coins) GetCoinBySymbol(symbol types.CoinSymbol, version types.CoinVersion) *Model

func (*Coins) GetSymbolInfo added in v1.2.0

func (c *Coins) GetSymbolInfo(symbol types.CoinSymbol) *SymbolInfo

func (*Coins) Recreate added in v1.2.0

func (c *Coins) Recreate(newID types.CoinID, name string, symbol types.CoinSymbol,
	volume *big.Int, crr uint32, reserve *big.Int, maxSupply *big.Int,
)

func (*Coins) SubReserve

func (c *Coins) SubReserve(id types.CoinID, amount *big.Int)

func (*Coins) SubVolume

func (c *Coins) SubVolume(id types.CoinID, amount *big.Int)

type Info

type Info struct {
	Volume  *big.Int
	Reserve *big.Int
	// contains filtered or unexported fields
}

type Model

type Model struct {
	CName      string
	CCrr       uint32
	CMaxSupply *big.Int
	CVersion   types.CoinVersion
	CSymbol    types.CoinSymbol
	// contains filtered or unexported fields
}

func (*Model) AddReserve

func (m *Model) AddReserve(amount *big.Int)

func (*Model) AddVolume

func (m *Model) AddVolume(amount *big.Int)

func (*Model) CheckReserveUnderflow

func (m *Model) CheckReserveUnderflow(delta *big.Int) error

func (Model) Crr

func (m Model) Crr() uint32

func (Model) GetFullSymbol added in v1.2.0

func (m Model) GetFullSymbol() string

func (Model) ID added in v1.2.0

func (m Model) ID() types.CoinID

func (Model) IsCreated added in v1.2.0

func (m Model) IsCreated() bool

func (Model) IsDirty

func (m Model) IsDirty() bool

func (Model) IsInfoDirty

func (m Model) IsInfoDirty() bool

func (Model) IsSymbolInfoDirty added in v1.2.0

func (m Model) IsSymbolInfoDirty() bool

func (Model) MaxSupply

func (m Model) MaxSupply() *big.Int

func (Model) Name

func (m Model) Name() string

func (Model) Reserve

func (m Model) Reserve() *big.Int

func (*Model) SetReserve

func (m *Model) SetReserve(reserve *big.Int)

func (*Model) SetVolume

func (m *Model) SetVolume(volume *big.Int)

func (*Model) SubReserve

func (m *Model) SubReserve(amount *big.Int)

func (*Model) SubVolume

func (m *Model) SubVolume(amount *big.Int)

func (Model) Symbol

func (m Model) Symbol() types.CoinSymbol

func (Model) Version added in v1.2.0

func (m Model) Version() uint16

func (Model) Volume

func (m Model) Volume() *big.Int

type RCoins added in v1.2.0

type RCoins interface {
	Export(state *types.AppState)
	Exists(id types.CoinID) bool
	ExistsBySymbol(symbol types.CoinSymbol) bool
	SubReserve(symbol types.CoinID, amount *big.Int)
	GetCoin(id types.CoinID) *Model
	GetCoinBySymbol(symbol types.CoinSymbol, version types.CoinVersion) *Model
	GetSymbolInfo(symbol types.CoinSymbol) *SymbolInfo
}

type SymbolInfo added in v1.2.0

type SymbolInfo struct {
	COwnerAddress *types.Address
	// contains filtered or unexported fields
}

func (SymbolInfo) OwnerAddress added in v1.2.0

func (i SymbolInfo) OwnerAddress() *types.Address

Jump to

Keyboard shortcuts

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