accountant

package
v0.0.0-...-864a747 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGenesisRejected                       = errors.New("genesis vertex has been rejected")
	ErrBalanceCalculationUnexpectedFailure   = errors.New("balance calculation unexpected failure")
	ErrBalanceUnavailable                    = errors.New("balance unavailable")
	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")
)
View Source
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

func (ab *AccountingBook) ReadVertex(ctx context.Context, h [32]byte) (Vertex, error)

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.

func (*AccountingBook) StreamDAG

func (ab *AccountingBook) StreamDAG(ctx context.Context) <-chan *Vertex

StreamDAG provides tow channels to subscribe to a stream of vertices. First streams verticies and second one streams possible errors.

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.

func NewBalance

func NewBalance(walletPubAddr string, s spice.Melange) Balance

NewBalance creates a new balance entity.

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 Signer

type Signer interface {
	Sign(message []byte) (digest [32]byte, signature []byte)
	Address() string
}

Signer signs the given message and has a public address.

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.

Jump to

Keyboard shortcuts

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