Documentation
¶
Overview ¶
Defines the state for factoid. By using the proper interfaces, the functionality of factoid can be imported into any framework.
Index ¶
- func GetChainId(parts []string) ([]byte, error)
- type AssetState
- func (fs *AssetState) AddTransaction(trans fct.ITransaction) error
- func (fs *AssetState) GetAssetChainID() []byte
- func (fs *AssetState) GetAssetName() []string
- func (fs *AssetState) GetBalance(address fct.IAddress) uint64
- func (fs *AssetState) GetDB() db.IFDatabase
- func (fs *AssetState) GetECBalance(address fct.IAddress) uint64
- func (fs *AssetState) GetTime() uint64
- func (fs *AssetState) GetTimeMilli() uint64
- func (fs *AssetState) GetWallet() wallet.ISCWallet
- func (fs *AssetState) LoadState() error
- func (fs *AssetState) SetAssetName([]string) error
- func (fs *AssetState) SetDB(database db.IFDatabase)
- func (fs *AssetState) SetWallet(w wallet.ISCWallet)
- func (fs *AssetState) UpdateBalance(address fct.IAddress, amount int64) error
- func (fs *AssetState) UpdateECBalance(address fct.IAddress, amount int64) error
- func (fs *AssetState) UpdateTransaction(trans fct.ITransaction) error
- func (fs *AssetState) UseECs(address fct.IAddress, amount uint64) error
- func (fs *AssetState) Validate(trans fct.ITransaction) error
- type IAssetState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChainId ¶
A Chain ID is constructed by taking the hash of each of the name components, then hashing the lot together. This way, there are nothing but theoretical-but-never-seen collisions between a ChainID and a single component name.
Types ¶
type AssetState ¶
type AssetState struct {
IAssetState
// contains filtered or unexported fields
}
func (*AssetState) AddTransaction ¶
func (fs *AssetState) AddTransaction(trans fct.ITransaction) error
Only add valid transactions to the current block.
func (*AssetState) GetAssetChainID ¶
func (fs *AssetState) GetAssetChainID() []byte
func (*AssetState) GetAssetName ¶
func (fs *AssetState) GetAssetName() []string
func (*AssetState) GetBalance ¶
func (fs *AssetState) GetBalance(address fct.IAddress) uint64
Any address that is not defined has a zero balance.
func (*AssetState) GetDB ¶
func (fs *AssetState) GetDB() db.IFDatabase
func (*AssetState) GetECBalance ¶
func (fs *AssetState) GetECBalance(address fct.IAddress) uint64
Any address that is not defined has a zero balance.
func (*AssetState) GetTime ¶
func (fs *AssetState) GetTime() uint64
func (*AssetState) GetTimeMilli ¶
func (fs *AssetState) GetTimeMilli() uint64
func (*AssetState) GetWallet ¶
func (fs *AssetState) GetWallet() wallet.ISCWallet
func (*AssetState) LoadState ¶
func (fs *AssetState) LoadState() error
This is the Baby of Asset tracking! We get the current height of our block and we go through each entry, unmarshalling it and building a "block". We then process that block.
We process transactions in our chain, and maintain a balance of our assets.
func (*AssetState) SetAssetName ¶
func (fs *AssetState) SetAssetName([]string) error
func (*AssetState) SetDB ¶
func (fs *AssetState) SetDB(database db.IFDatabase)
func (*AssetState) SetWallet ¶
func (fs *AssetState) SetWallet(w wallet.ISCWallet)
func (*AssetState) UpdateBalance ¶
func (fs *AssetState) UpdateBalance(address fct.IAddress, amount int64) error
Update balance throws an error if your update will drive the balance negative.
func (*AssetState) UpdateECBalance ¶
func (fs *AssetState) UpdateECBalance(address fct.IAddress, amount int64) error
Update ec balance throws an error if your update will drive the balance negative.
func (*AssetState) UpdateTransaction ¶
func (fs *AssetState) UpdateTransaction(trans fct.ITransaction) error
Assumes validation has already been done.
func (*AssetState) UseECs ¶
func (fs *AssetState) UseECs(address fct.IAddress, amount uint64) error
Use Entry Credits. Note Entry Credit balances are maintained as entry credits, not Factoids. But adding is done in Factoids, using done in Entry Credits. Using lowers the Entry Credit Balance.
func (*AssetState) Validate ¶
func (fs *AssetState) Validate(trans fct.ITransaction) error
Returns an error message about what is wrong with the transaction if it is invalid, otherwise you are good to go.
type IAssetState ¶
type IAssetState interface {
// The Asset Name is used to find the chain in Factom.
// This same code can be used to manage many different
// sorts of assets.
AssetName() ([]string, error)
ChainID() []byte
SetAssetName([]string) error
// Set the database for the Asset State. This is where
// we manage the balances for transactions in this asset.
SetDB(db.IFDatabase)
GetDB() db.IFDatabase
// Load the state of Asset (or catch up the state of the
// asset.
LoadState() error
// Get the wallet used to help manage the Asset State.
GetWallet() wallet.ISCWallet
SetWallet(wallet.ISCWallet)
// Update balance updates the balance for the asset address in
// the database. Note that we take an int64 to allow debits
// as well as credits. This is an interal function, and
// changing the local database in no way can compromise the
// balances of assets held in Factom.
UpdateBalance(address fct.IAddress, amount int64) error
// Return the Asset balance for an address
GetBalance(address fct.IAddress) uint64
// Time is something that can vary across multiple systems, and
// must be controlled in order to build reliable, repeatable
// tests. Therefore, no node should directly querry system
// time.
GetTimeMilli() uint64 // Count of milliseconds from Jan 1,1970
GetTime() uint64 // Count of seconds from Jan 1, 1970
// Validate transaction
// Return zero len string if the balance of an address covers each input
Validate(fct.ITransaction) error
// Update Transaction just updates the balance sheet with the
// addition of a transaction.
UpdateTransaction(fct.ITransaction) error
// Add a Transaction to the current block. The transaction is
// validated against the address balances, which must cover The
// inputs. Returns true if the transaction is added.
AddTransaction(fct.ITransaction) error
// Get the block height for this asset.
GetAssetHeight() uint32
}