backend

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: AGPL-3.0 Imports: 35 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
	Storage() (Storage, error)
	BatchSize() int
	HttpServer(http.Handler) http.Server
	Listener() net.Listener
	Logger() log.Logger
	SystemID() []byte
	APIAddr() string
}

func NewConfig

func NewConfig(apiAddr, abURL, boltDB string, logger log.Logger, systemID []byte) 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 added in v0.2.0

type FeeCreditBill struct {
	Id              []byte `json:"id"`
	Value           uint64 `json:"value,string"`
	TxHash          []byte `json:"txHash"`
	LastAddFCTxHash []byte `json:"lastAddFcTxHash"`
}

func (*FeeCreditBill) GetID added in v0.2.0

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

func (*FeeCreditBill) GetLastAddFCTxHash added in v0.2.0

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

func (*FeeCreditBill) GetTxHash added in v0.2.0

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

func (*FeeCreditBill) GetValue added in v0.2.0

func (f *FeeCreditBill) GetValue() uint64

func (*FeeCreditBill) ToGenericBill added in v0.2.0

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 RoundNumberResponse

type RoundNumberResponse struct {
	RoundNumber uint64 `json:"roundNumber,string"`
}

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

	GetClosedFeeCredit(fcbID types.UnitID) (*types.TransactionRecord, error)
	SetClosedFeeCredit(fcbID types.UnitID, txr *types.TransactionRecord) 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"`
	// 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) WriteSSE added in v0.1.4

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