backend

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: AGPL-3.0, ISC Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const BoltBillStoreFileName = "bills.db"

Variables

View Source
var (
	ErrKeyAlreadyExists = errors.New("key already exists")
	ErrPubKeyNotIndexed = errors.New("pubkey not indexed")
	ErrBillNotFound     = errors.New("bill does not exist")
)

Functions

This section is empty.

Types

type AddKeyRequest

type AddKeyRequest struct {
	Pubkey string `json:"pubkey"`
}

type BalanceResponse

type BalanceResponse struct {
	Balance uint64 `json:"balance"`
}

type Bill

type Bill struct {
	Id       []byte `json:"id"`
	Value    uint64 `json:"value"`
	TxHash   []byte `json:"txHash"`
	IsDCBill bool   `json:"isDcBill"`
	// OrderNumber insertion order of given bill in pubkey => list of bills bucket, needed for determistic paging
	OrderNumber uint64   `json:"orderNumber"`
	TxProof     *TxProof `json:"txProof"`
}

type BillStore

type BillStore interface {
	GetBlockNumber() (uint64, error)
	SetBlockNumber(blockNumber uint64) error
	GetBills(pubKey []byte) ([]*Bill, error)
	RemoveBill(pubKey []byte, id []byte) error
	ContainsBill(pubkey []byte, unitID []byte) (bool, error)
	GetBill(pubkey []byte, unitID []byte) (*Bill, error)
	SetBills(pubkey []byte, bills ...*Bill) error
	SetBillExpirationTime(blockNumber uint64, pubkey []byte, unitID []byte) error
	DeleteExpiredBills(blockNumber uint64) error
	GetKeys() ([]*Pubkey, error)
	GetKey(pubkey []byte) (*Pubkey, error)
	AddKey(key *Pubkey) error
}

type Bills

type Bills struct {
	Bills []*Bill `json:"bills"`
}

type BlockHeightResponse

type BlockHeightResponse struct {
	BlockHeight uint64 `json:"blockHeight"`
}

type BlockProcessor

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

func NewBlockProcessor

func NewBlockProcessor(store BillStore) *BlockProcessor

func (*BlockProcessor) ProcessBlock

func (p *BlockProcessor) ProcessBlock(b *block.Block) error

type BoltBillStore

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

func NewBoltBillStore

func NewBoltBillStore(dbFile string) (*BoltBillStore, error)

NewBoltBillStore creates new on-disk persistent storage for bills and proofs using bolt db. If the file does not exist then it will be created, however, parent directories must exist beforehand.

func (*BoltBillStore) AddKey

func (s *BoltBillStore) AddKey(k *Pubkey) error

func (*BoltBillStore) ContainsBill

func (s *BoltBillStore) ContainsBill(pubkey []byte, unitID []byte) (bool, error)

func (*BoltBillStore) DeleteExpiredBills

func (s *BoltBillStore) DeleteExpiredBills(blockNumber uint64) error

func (*BoltBillStore) GetBill

func (s *BoltBillStore) GetBill(pubkey []byte, unitID []byte) (*Bill, error)

func (*BoltBillStore) GetBills

func (s *BoltBillStore) GetBills(pubkey []byte) ([]*Bill, error)

func (*BoltBillStore) GetBlockNumber

func (s *BoltBillStore) GetBlockNumber() (uint64, error)

func (*BoltBillStore) GetKey

func (s *BoltBillStore) GetKey(pubkey []byte) (*Pubkey, error)

func (*BoltBillStore) GetKeys

func (s *BoltBillStore) GetKeys() ([]*Pubkey, error)

func (*BoltBillStore) RemoveBill

func (s *BoltBillStore) RemoveBill(pubkey []byte, unitID []byte) error

func (*BoltBillStore) SetBillExpirationTime

func (s *BoltBillStore) SetBillExpirationTime(blockNumber uint64, pubkey []byte, unitID []byte) error

func (*BoltBillStore) SetBills

func (s *BoltBillStore) SetBills(pubkey []byte, bills ...*Bill) error

func (*BoltBillStore) SetBlockNumber

func (s *BoltBillStore) SetBlockNumber(blockNumber uint64) error

type EmptyResponse

type EmptyResponse struct{}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

type ListBillVM

type ListBillVM struct {
	Id       []byte `json:"id"`
	Value    uint64 `json:"value"`
	TxHash   []byte `json:"txHash"`
	IsDCBill bool   `json:"isDCBill"`
}

type ListBillsResponse

type ListBillsResponse struct {
	Total int           `json:"total"`
	Bills []*ListBillVM `json:"bills"`
}

type Pubkey

type Pubkey struct {
	Pubkey     []byte            `json:"pubkey"`
	PubkeyHash *wallet.KeyHashes `json:"pubkeyHash"`
}

func NewPubkey

func NewPubkey(pubkey []byte) *Pubkey

NewPubkey creates a new hashed Pubkey

type RequestHandler

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

type TxConverter

type TxConverter struct {
}

func (*TxConverter) ConvertTx

type TxProof

type TxProof struct {
	BlockNumber uint64                `json:"blockNumber"`
	Tx          *txsystem.Transaction `json:"tx"`
	Proof       *block.BlockProof     `json:"proof"`
}

type WalletBackend

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

func New

func New(wallet *wallet.Wallet, store BillStore, verifiers map[string]abcrypto.Verifier) *WalletBackend

New creates a new wallet backend service which can be started by calling the Start or StartProcess method. Shutdown method should be called to close resources used by the service.

func (*WalletBackend) AddKey

func (w *WalletBackend) AddKey(pubkey []byte) error

AddKey adds new public key to list of tracked keys. Returns ErrKeyAlreadyExists error if key already exists.

func (*WalletBackend) GetBill

func (w *WalletBackend) GetBill(pubkey []byte, unitID []byte) (*Bill, error)

GetBill returns most recently seen bill with given unit id.

func (*WalletBackend) GetBills

func (w *WalletBackend) GetBills(pubkey []byte) ([]*Bill, error)

GetBills returns all bills for given public key.

func (*WalletBackend) GetMaxBlockNumber

func (w *WalletBackend) GetMaxBlockNumber() (uint64, error)

GetMaxBlockNumber returns max block number known to the connected AB node.

func (*WalletBackend) SetBills

func (w *WalletBackend) SetBills(pubkey []byte, bills *block.Bills) error

SetBill adds new bill to the index. Bill most have a valid block proof. Overwrites existing bill, if one exists. Returns error if given pubkey is not indexed.

func (*WalletBackend) Shutdown

func (w *WalletBackend) Shutdown()

Shutdown terminates wallet backend service.

func (*WalletBackend) Start

func (w *WalletBackend) Start(ctx context.Context) error

Start starts downloading blocks and indexing bills by their owner's public key. Blocks forever or until alphabill connection is terminated.

func (*WalletBackend) StartProcess

func (w *WalletBackend) StartProcess(ctx context.Context)

StartProcess calls Start in a retry loop, can be canceled by cancelling context or calling Shutdown method.

type WalletBackendHttpServer

type WalletBackendHttpServer struct {
	Handler RequestHandler
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(addr string, listBillsPageLimit int, service WalletBackendService) *WalletBackendHttpServer

func (*WalletBackendHttpServer) Shutdown

func (s *WalletBackendHttpServer) Shutdown(ctx context.Context) error

func (*WalletBackendHttpServer) Start

func (s *WalletBackendHttpServer) Start() error

type WalletBackendService

type WalletBackendService interface {
	GetBills(pubkey []byte) ([]*Bill, error)
	GetBill(pubkey []byte, unitID []byte) (*Bill, error)
	SetBills(pubkey []byte, bills *block.Bills) error
	AddKey(pubkey []byte) error
	GetMaxBlockNumber() (uint64, error)
}

Jump to

Keyboard shortcuts

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