Documentation
¶
Index ¶
- Variables
- type AccountingBook
- func (ab *AccountingBook) AddLeaf(ctx context.Context, leaf *Vertex) error
- func (ab *AccountingBook) AddTrustedNode(trustedNodePublicAddress string) error
- func (ab *AccountingBook) Address() string
- func (ab *AccountingBook) CalculateBalance(ctx context.Context, walletPubAddr string) (Balance, error)
- func (ab *AccountingBook) CreateGenesis(subject string, spc spice.Melange, data []byte, receiverPublicAddress string) (Vertex, error)
- func (ab *AccountingBook) CreateLeaf(ctx context.Context, trx *transaction.Transaction) (Vertex, error)
- func (ab *AccountingBook) DagLoaded() bool
- func (ab *AccountingBook) LoadDag(cancelF context.CancelCauseFunc, cVrx <-chan *Vertex)
- func (ab *AccountingBook) ReadDAGTransactionsByAddress(ctx context.Context, address string) ([]transaction.Transaction, error)
- func (ab *AccountingBook) ReadTransactionByHash(ctx context.Context, hash [32]byte) (transaction.Transaction, error)
- func (ab *AccountingBook) ReadVertex(ctx context.Context, h [32]byte) (Vertex, error)
- func (ab *AccountingBook) RemoveTrustedNode(trustedNodePublicAddress string) error
- func (ab *AccountingBook) StreamDAG(ctx context.Context) <-chan *Vertex
- type Balance
- type Config
- type Signer
- type Vertex
Constants ¶
This section is empty.
Variables ¶
var ( ErrGenesisRejected = errors.New("genesis vertex has been rejected") ErrBalanceCalculationUnexpectedFailure = errors.New("balance calculation unexpected failure") ErrLeafBallanceCalculationProcessStopped = errors.New("wallet balance calculation process stopped") ErrLeafValidationProcessStopped = errors.New("leaf validation process stopped") ErrNewLeafRejected = errors.New("new leaf rejected") ErrLeafRejected = errors.New("leaf rejected") ErrDagIsLoaded = errors.New("dag is already loaded") ErrDagIsNotLoaded = errors.New("dag is not loaded") ErrLeafAlreadyExists = errors.New("leaf already exists") ErrIssuerAddressBalanceNotfound = errors.New("issuer address balance not fund") ErrReceiverAddressBalanceNotfound = errors.New("receiver address balance not fund") ErrDoubleSpending = errors.New("double spending or insufficient funds") ErrCannotTransferFoundsViaOwnedNode = errors.New("issuer cannot transfer funds via owned node") ErrCannotTransferFoundsFromGenesisWallet = errors.New("issuer cannot be the genesis node") ErrVertexHashNotfound = errors.New("vertex hash not fund") ErrVertexAlreadyExists = errors.New("vertex already exists") ErrTrxInVertexAlreadyExists = errors.New("transaction in vertex already exists") ErrTrxIsEmpty = errors.New("transaction is empty") ErrTrxToVertexNotfound = errors.New("transaction mapping to vertex do not fund, transaction doesn't exist") ErrUnexpected = errors.New("unexpected failure") ErrTransferringFoundsFailure = errors.New("transferring spice failure") ErrEntityNotFound = errors.New("entity not fund") ErrBreak = errors.New("just break") ErrParentDoesNotExists = errors.New("parent doesn't exists") )
var ( ErrNotEnoughSpace = errors.New("not enough space in the replier buffer") ErrVertexRepetitionExceeded = errors.New("vertex repetition exceeded") )
Functions ¶
This section is empty.
Types ¶
type AccountingBook ¶
type AccountingBook struct {
// contains filtered or unexported fields
}
AccountingBook is an entity that represents the accounting process of all received transactions.
func NewAccountingBook ¶
func NewAccountingBook( ctx context.Context, cfg Config, verifier signatureVerifier, signer Signer, l logger.Logger, ) (*AccountingBook, error)
New creates new AccountingBook. New AccountingBook will start internally the garbage collection loop, to stop it from running cancel the context.
func (*AccountingBook) AddLeaf ¶
func (ab *AccountingBook) AddLeaf(ctx context.Context, leaf *Vertex) error
AddLeaf adds leaf known also as tip to the graph for future validation. Added leaf will be a subject of validation by another tip.
func (*AccountingBook) AddTrustedNode ¶
func (ab *AccountingBook) AddTrustedNode(trustedNodePublicAddress string) error
AddTrustedNode adds trusted node public address to the trusted nodes public address repository.
func (*AccountingBook) Address ¶
func (ab *AccountingBook) Address() string
Address returns signer public address that is a core cryptographic padlock for the DAG Vertices.
func (*AccountingBook) CalculateBalance ¶
func (ab *AccountingBook) CalculateBalance(ctx context.Context, walletPubAddr string) (Balance, error)
CalculateBalance traverses the graph starting from the recent accepted Vertex, and calculates the balance for the given address.
func (*AccountingBook) CreateGenesis ¶
func (ab *AccountingBook) CreateGenesis(subject string, spc spice.Melange, data []byte, receiverPublicAddress string) (Vertex, error)
CreateGenesis creates genesis vertex that will transfer spice to current node as a receiver.
func (*AccountingBook) CreateLeaf ¶
func (ab *AccountingBook) CreateLeaf(ctx context.Context, trx *transaction.Transaction) (Vertex, error)
CreateLeaf creates leaf vertex also known as a tip. All the graph validations before adding the leaf happens in that function, Created leaf will be a subject of validation by another tip.
func (*AccountingBook) DagLoaded ¶
func (ab *AccountingBook) DagLoaded() bool
DagLoaded returns true if dag is loaded or false otherwise.
func (*AccountingBook) LoadDag ¶
func (ab *AccountingBook) LoadDag(cancelF context.CancelCauseFunc, cVrx <-chan *Vertex)
LoadDag loads stream of Vertices in to the DAG.
func (*AccountingBook) ReadDAGTransactionsByAddress ¶
func (ab *AccountingBook) ReadDAGTransactionsByAddress(ctx context.Context, address string) ([]transaction.Transaction, error)
ReadDAGTransactionsByAddress reads all the transactions from DAG only, that given address appears in as issuer or receiver. This will not read transactions after DAG has been truncated.
func (*AccountingBook) ReadTransactionByHash ¶
func (ab *AccountingBook) ReadTransactionByHash(ctx context.Context, hash [32]byte) (transaction.Transaction, error)
ReadTransactionByHash reads transactions by hashes from DAG and DB.
func (*AccountingBook) ReadVertex ¶
ReadVertex reads vertex by its hash from the vertex if exists or returns error otherwise.
func (*AccountingBook) RemoveTrustedNode ¶
func (ab *AccountingBook) RemoveTrustedNode(trustedNodePublicAddress string) error
RemoveTrustedNode removes trusted node public address from trusted nodes public address repository.
type Balance ¶
type Balance struct {
AccountedAt time.Time `msgpack:"accounted_at"`
WalletPublicAddress string `msgpack:"wallet_public_address"`
Spice spice.Melange `msgpack:"spice"`
}
Balance holds the wallet balance.
type Config ¶
type Config struct {
TrustedNodesDBPath string `yaml:"trusted_nodes_db_path"`
TokensDBPath string `yaml:"tokens_db_path"`
TrxsToVerticesMapDBPath string `yaml:"trxs_to_vertices_map_db_path"`
VerticesDBPath string `yaml:"vertices_db_path"`
Truncate uint64 `yaml:"truncate_at_weight"`
}
Config contains configuration for the AccountingBook.
type Vertex ¶
type Vertex struct {
SignerPublicAddress string `msgpack:"signer_public_address"`
CreatedAt time.Time `msgpack:"created_at"`
Signature []byte `msgpack:"signature"`
Transaction transaction.Transaction `msgpack:"transaction"`
Hash [32]byte `msgpack:"hash"`
LeftParentHash [32]byte `msgpack:"left_parent_hash"`
RightParentHash [32]byte `msgpack:"right_parent_hash"`
Weight uint64 `msgpack:"weight"`
}
Vertex is a Direct Acyclic Graph vertex that creates a AccountingBook inner graph.
func NewVertex ¶
func NewVertex( trx transaction.Transaction, leftParentHash, rightParentHash [32]byte, weight uint64, signer Signer, ) (Vertex, error)
NewVertex creates new Vertex but first validates transaction legitimacy. It is assumed that the transaction is verified.