money

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: AGPL-3.0, ISC Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const BoltBillStoreFileName = "bills.db"
View Source
const DustBillDeletionTimeout = 65536

Variables

View Source
var (
	ErrOwnerPredicateIsNil = errors.New("unit owner predicate is nil")
)

Functions

func CreateAndRun

func CreateAndRun(ctx context.Context, config *Config) error

func NewTxConverter

func NewTxConverter(systemId []byte) *txConverter

Types

type AddKeyRequest

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

type BalanceResponse

type BalanceResponse struct {
	Balance string `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"`
	OwnerPredicate []byte   `json:"OwnerPredicate"`
}

type BillStore

type BillStore interface {
	Do() BillStoreTx
	WithTransaction(func(tx BillStoreTx) error) error
}

BillStore type for creating BillStoreTx transactions

type BillStoreTx

type BillStoreTx interface {
	GetBlockNumber() (uint64, error)
	SetBlockNumber(blockNumber uint64) error
	GetBill(unitID []byte) (*Bill, error)
	GetBills(ownerCondition []byte) ([]*Bill, error)
	SetBill(bill *Bill) error
	RemoveBill(unitID []byte) error
	SetBillExpirationTime(blockNumber uint64, unitID []byte) error
	DeleteExpiredBills(blockNumber uint64) error
}

BillStoreTx type for managing units by their ID and owner condition

type Bills

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

type BlockHeightResponse

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

type BlockProcessor

type BlockProcessor struct {
	TxConverter block.TxConverter
	// contains filtered or unexported fields
}

func NewBlockProcessor

func NewBlockProcessor(store BillStore, txConverter block.TxConverter) *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) Do

func (s *BoltBillStore) Do() BillStoreTx

func (*BoltBillStore) WithTransaction

func (s *BoltBillStore) WithTransaction(fn func(txc BillStoreTx) error) error

type BoltBillStoreTx

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

func (*BoltBillStoreTx) DeleteExpiredBills

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

func (*BoltBillStoreTx) GetBill

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

func (*BoltBillStoreTx) GetBills

func (s *BoltBillStoreTx) GetBills(ownerPredicate []byte) ([]*Bill, error)

func (*BoltBillStoreTx) GetBlockNumber

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

func (*BoltBillStoreTx) RemoveBill

func (s *BoltBillStoreTx) RemoveBill(unitID []byte) error

func (*BoltBillStoreTx) SetBill

func (s *BoltBillStoreTx) SetBill(bill *Bill) error

func (*BoltBillStoreTx) SetBillExpirationTime

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

func (*BoltBillStoreTx) SetBlockNumber

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

type Config

type Config struct {
	ABMoneySystemIdentifier []byte
	AlphabillUrl            string
	ServerAddr              string
	DbFile                  string
	ListBillsPageLimit      int
}

type EmptyResponse

type EmptyResponse struct{}

type ErrorResponse

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

type GenericWalletBackendHttpServer

type GenericWalletBackendHttpServer struct {
	Handler RequestHandler
}

@BasePath /api/v1

type ListBillVM

type ListBillVM struct {
	Id       []byte `json:"id" swaggertype:"string" format:"base64" example:"AAAAAAgwv3UA1HfGO4qc1T3I3EOvqxfcrhMjJpr9Tn4="`
	Value    string `json:"value" example:"1000"`
	TxHash   []byte `json:"txHash" swaggertype:"string" format:"base64" example:"Q4ShCITC0ODXPR+j1Zl/teYcoU3/mAPy0x8uSsvQFM8="`
	IsDCBill bool   `json:"isDcBill" example:"false"`
}

type ListBillsResponse

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

type Pubkey

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

type RequestHandler

type RequestHandler struct {
	Service            WalletBackendService
	ListBillsPageLimit int
}

func (*RequestHandler) Router

func (s *RequestHandler) Router() *mux.Router

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) *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) GetBill

func (w *WalletBackend) GetBill(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(ctx context.Context) (uint64, error)

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

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
}

@BasePath /api/v1

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(ownerCondition []byte) ([]*Bill, error)
	GetBill(unitID []byte) (*Bill, error)
	GetMaxBlockNumber(ctx context.Context) (uint64, error)
}

@BasePath /api/v1

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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