backend

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoParent = TokenTypeID(make([]byte, crypto.SHA256.Size()))
)

Functions

func Run

func Run(ctx context.Context, cfg Configuration) error

Run starts the tokens backend - syncing blocks to local storage and launching HTTP server to query it. Run blocks until ctx is cancelled or some unrecoverable error happens, it always returns non-nil error.

Types

type ABClient

type ABClient interface {
	SendTransaction(ctx context.Context, tx *types.TransactionOrder) error
	GetBlocks(ctx context.Context, blockNumber, blockCount uint64) (*alphabill.GetBlocksResponse, error)
	GetRoundNumber(ctx context.Context) (uint64, error)
}

type Configuration

type Configuration interface {
	Client() (ABClient, error)
	Storage() (Storage, error)
	BatchSize() int
	HttpServer(http.Handler) http.Server
	Listener() net.Listener
	Logger() *slog.Logger
	SystemID() types.SystemID
	APIAddr() string
}

func NewConfig

func NewConfig(systemID types.SystemID, apiAddr, abURL, boltDB string, observe Observability) Configuration

NewConfig returns Configuration suitable for using as Run parameter.

  • apiAddr: address on which to expose REST API;
  • abURL: AlphaBill backend from where to sync blocks;
  • boltDB: filename (with full path) of the bolt db to use as storage;
  • logger: logger implementation.

type FeeCreditBill

type FeeCreditBill struct {
	Id     []byte            `json:"id"`
	Value  uint64            `json:"value,string"`
	TxHash []byte            `json:"txHash"`
	Locked wallet.LockReason `json:"locked,string"`
}

func (*FeeCreditBill) GetID

func (f *FeeCreditBill) GetID() []byte

func (*FeeCreditBill) GetTxHash

func (f *FeeCreditBill) GetTxHash() []byte

func (*FeeCreditBill) GetValue

func (f *FeeCreditBill) GetValue() uint64

func (*FeeCreditBill) ToGenericBill

func (f *FeeCreditBill) ToGenericBill() *wallet.Bill

type Kind

type Kind byte
const (
	Any Kind = 1 << iota
	Fungible
	NonFungible
)

func (Kind) String

func (kind Kind) String() string

type Observability

type Observability interface {
	Tracer(name string, options ...trace.TracerOption) trace.Tracer
	TracerProvider() trace.TracerProvider
	Logger() *slog.Logger
}

type Storage

type Storage interface {
	Close() error
	GetBlockNumber() (uint64, error)
	SetBlockNumber(blockNumber uint64) error

	SaveTokenTypeCreator(id TokenTypeID, kind Kind, creator sdk.PubKey) error
	SaveTokenType(data *TokenUnitType, proof *sdk.Proof) error
	GetTokenType(id TokenTypeID) (*TokenUnitType, error)
	QueryTokenType(kind Kind, creator sdk.PubKey, startKey TokenTypeID, count int) ([]*TokenUnitType, TokenTypeID, error)

	SaveToken(data *TokenUnit, proof *sdk.Proof) error
	RemoveToken(id TokenID) error
	GetToken(id TokenID) (*TokenUnit, error)
	QueryTokens(kind Kind, owner sdk.Predicate, startKey TokenID, count int) ([]*TokenUnit, TokenID, error)

	GetTxProof(unitID types.UnitID, txHash sdk.TxHash) (*sdk.Proof, error)

	GetFeeCreditBill(unitID types.UnitID) (*FeeCreditBill, error)
	SetFeeCreditBill(fcb *FeeCreditBill, proof *sdk.Proof) error
}

type TokenID

type TokenID = types.UnitID

type TokenTypeID

type TokenTypeID = types.UnitID

type TokenUnit

type TokenUnit struct {
	// common
	ID       TokenID          `json:"id"`
	Symbol   string           `json:"symbol"`
	TypeID   TokenTypeID      `json:"typeId"`
	TypeName string           `json:"typeName"`
	Owner    wallet.Predicate `json:"owner"`
	Locked   uint64           `json:"locked"`
	// fungible only
	Amount   uint64 `json:"amount,omitempty,string"`
	Decimals uint32 `json:"decimals,omitempty"`
	Burned   bool   `json:"burned,omitempty"`
	// nft only
	NftName                string           `json:"nftName,omitempty"`
	NftURI                 string           `json:"nftUri,omitempty"`
	NftData                []byte           `json:"nftData,omitempty"`
	NftDataUpdatePredicate wallet.Predicate `json:"nftDataUpdatePredicate,omitempty"`
	// meta
	Kind   Kind          `json:"kind"`
	TxHash wallet.TxHash `json:"txHash"`
}

func (*TokenUnit) IsLocked

func (tu *TokenUnit) IsLocked() bool

func (*TokenUnit) WriteSSE

func (tu *TokenUnit) WriteSSE(w io.Writer) error

type TokenUnitType

type TokenUnitType struct {
	// common
	ID                       TokenTypeID      `json:"id"`
	ParentTypeID             TokenTypeID      `json:"parentTypeId"`
	Symbol                   string           `json:"symbol"`
	Name                     string           `json:"name,omitempty"`
	Icon                     *tokens.Icon     `json:"icon,omitempty"`
	SubTypeCreationPredicate wallet.Predicate `json:"subTypeCreationPredicate,omitempty"`
	TokenCreationPredicate   wallet.Predicate `json:"tokenCreationPredicate,omitempty"`
	InvariantPredicate       wallet.Predicate `json:"invariantPredicate,omitempty"`
	// fungible only
	DecimalPlaces uint32 `json:"decimalPlaces,omitempty"`
	// nft only
	NftDataUpdatePredicate wallet.Predicate `json:"nftDataUpdatePredicate,omitempty"`
	// meta
	Kind   Kind          `json:"kind"`
	TxHash wallet.TxHash `json:"txHash"`
}

Jump to

Keyboard shortcuts

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