wallet

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: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentType     = "Content-Type"
	ApplicationJson = "application/json"
	ApplicationCbor = "application/cbor"
	UserAgent       = "User-Agent"

	QueryParamOffsetKey   = "offsetKey"
	QueryParamLimit       = "limit"
	HeaderLink            = "Link"
	HeaderLinkValueFormat = `<%s>; rel="next"`
)

Variables

View Source
var (
	ErrTxProofNil            = errors.New("tx proof is nil")
	ErrInvalidValue          = errors.New("invalid value")
	ErrMissingDCTargetUnitID = errors.New("dc target unit id is missing")
	ErrInvalidTxHash         = errors.New("bill txHash is not equal to actual transaction hash")
	ErrInvalidTxType         = errors.New("invalid tx type")
)
View Source
var (
	// ErrInvalidRequest is returned when backend responded with 4nn status code, use errors.Is to check for it.
	ErrInvalidRequest = errors.New("invalid request")

	// ErrNotFound is returned when backend responded with 404 status code, use errors.Is to check for it.
	ErrNotFound = errors.New("not found")
)
View Source
var ErrRecordNotFound = errors.New("not found")
View Source
var SwaggerFiles embed.FS

Functions

func AddUint64 added in v0.2.0

func AddUint64(ns ...uint64) (sum uint64, overflow bool, err error)

AddUint64 adds a list of uint64s together, returning an error and a boolean indicator if the sum overflows uint64.

func CreateBuckets added in v0.2.0

func CreateBuckets(update func(fn func(*bolt.Tx) error) error, buckets ...[]byte) error

func DecodeResponse added in v0.2.1

func DecodeResponse(rsp *http.Response, successStatus int, data any, allowEmptyResponse bool) error

DecodeResponse when "rsp" StatusCode is equal to "successStatus" response body is decoded into "data". In case of some other response status body is expected to contain error response json struct.

func EncodeHex added in v0.2.0

func EncodeHex(value []byte) string

func EnsureSubBucket added in v0.2.0

func EnsureSubBucket(tx *bolt.Tx, parentBucket []byte, bucket []byte, allowAbsent bool) (*bolt.Bucket, error)

func ExtractOffsetMarker added in v0.2.0

func ExtractOffsetMarker(rsp *http.Response) (string, error)

func GetURL added in v0.2.0

func GetURL(url url.URL, pathElements ...string) *url.URL

func ParseHex added in v0.2.0

func ParseHex[T types.SystemID | types.UnitID | TxHash | []byte](value string, required bool) (T, error)

func ParseMaxResponseItems added in v0.2.0

func ParseMaxResponseItems(s string, maxValue int) (int, error)

parseMaxResponseItems parses input "s" as integer. When empty string or int over "maxValue" is sent in "maxValue" is returned. In case of invalid int or value smaller than 1 error is returned.

func SetLinkHeader added in v0.2.0

func SetLinkHeader(u *url.URL, w http.ResponseWriter, next string)

func SetPaginationParams added in v0.2.0

func SetPaginationParams(u *url.URL, offset string, limit int)

func SetQueryParam added in v0.2.0

func SetQueryParam(u *url.URL, key, val string)

func WriteBillsFile added in v0.2.0

func WriteBillsFile(path string, res []*BillProof) error

Types

type Bill added in v0.2.0

type Bill struct {
	Id                   []byte `json:"id,omitempty"`
	Value                uint64 `json:"value,omitempty,string"`
	TxHash               []byte `json:"txHash,omitempty"`
	DCTargetUnitID       []byte `json:"targetUnitId,omitempty"`
	DCTargetUnitBacklink []byte `json:"targetUnitBacklink,omitempty"`

	// fcb specific fields
	// LastAddFCTxHash last add fee credit tx hash
	LastAddFCTxHash []byte `json:"lastAddFcTxHash,omitempty"`
}

TODO used to be protobuf defined Bill struct used as import/export/download/upload unified schema across applications possibly can be removed as import/export/download/upoad feature was dropped

func (*Bill) GetID added in v0.2.0

func (x *Bill) GetID() []byte

func (*Bill) GetLastAddFCTxHash added in v0.2.0

func (x *Bill) GetLastAddFCTxHash() []byte

func (*Bill) GetTxHash added in v0.2.0

func (x *Bill) GetTxHash() []byte

func (*Bill) GetValue added in v0.2.0

func (x *Bill) GetValue() uint64

type BillProof added in v0.2.0

type BillProof struct {
	Bill    *Bill
	TxProof *Proof
}

func (*BillProof) GetID added in v0.2.0

func (bp *BillProof) GetID() []byte

type Bills added in v0.2.0

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

func ReadBillsFile added in v0.2.0

func ReadBillsFile(path string) (*Bills, error)

type Builder

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

func New

func New() *Builder

func (*Builder) Build

func (b *Builder) Build() *Wallet

func (*Builder) SetABClient

func (b *Builder) SetABClient(abc client.ABClient) *Builder

func (*Builder) SetABClientConf

func (b *Builder) SetABClientConf(abcConf client.AlphabillClientConfig) *Builder

type EmptyResponse added in v0.2.0

type EmptyResponse struct{}

type ErrorResponse added in v0.2.0

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

type InfoResponse added in v0.2.1

type InfoResponse struct {
	SystemID string `json:"system_id"` // hex encoded system identifier (without 0x prefix)
	Name     string `json:"name"`      // one of [money backend | tokens backend]
}

InfoResponse should be compatible with Node /info request

type Predicate added in v0.1.4

type Predicate []byte

type Proof added in v0.1.4

type Proof struct {
	TxRecord *types.TransactionRecord `json:"txRecord"`
	TxProof  *types.TxProof           `json:"txProof"`
	// contains filtered or unexported fields
}

Proof wrapper struct around TxRecord and TxProof

func NewTxProof added in v0.2.0

func NewTxProof(txIdx int, b *types.Block, hashAlgorithm crypto.Hash) (*Proof, error)

func (*Proof) ToGenericProof added in v0.2.0

func (p *Proof) ToGenericProof() *types.TxProof

type PubKey added in v0.1.4

type PubKey []byte

func DecodePubKeyHex added in v0.2.0

func DecodePubKeyHex(pubKey string) (PubKey, error)

func ParsePubKey added in v0.2.0

func ParsePubKey(pubkey string, required bool) (PubKey, error)

func (PubKey) Hash added in v0.2.0

func (pk PubKey) Hash() PubKeyHash

type PubKeyHash added in v0.2.0

type PubKeyHash []byte

type ResponseWriter added in v0.2.0

type ResponseWriter struct {
	LogErr func(a ...any)
}

func (*ResponseWriter) ErrorResponse added in v0.2.0

func (rw *ResponseWriter) ErrorResponse(w http.ResponseWriter, code int, err error)

func (*ResponseWriter) InvalidParamResponse added in v0.2.0

func (rw *ResponseWriter) InvalidParamResponse(w http.ResponseWriter, name string, err error)

func (*ResponseWriter) WriteCborResponse added in v0.2.0

func (rw *ResponseWriter) WriteCborResponse(w http.ResponseWriter, data any)

func (*ResponseWriter) WriteErrorResponse added in v0.2.0

func (rw *ResponseWriter) WriteErrorResponse(w http.ResponseWriter, err error)

func (*ResponseWriter) WriteResponse added in v0.2.0

func (rw *ResponseWriter) WriteResponse(w http.ResponseWriter, data any)

type SendOpts added in v0.1.1

type SendOpts struct {
	// RetryOnFullTxBuffer retries to send transaction when tx buffer is full
	RetryOnFullTxBuffer bool
}

type Transactions added in v0.2.0

type Transactions struct {
	Transactions []*types.TransactionOrder
	// contains filtered or unexported fields
}

type TxHash added in v0.1.4

type TxHash []byte

type TxHistoryRecord added in v0.2.0

type TxHistoryRecord struct {
	UnitID       types.UnitID
	TxHash       TxHash
	CounterParty []byte
	Timeout      uint64
	State        TxHistoryRecordState
	Kind         TxHistoryRecordKind
	// contains filtered or unexported fields
}

type TxHistoryRecordKind added in v0.2.0

type TxHistoryRecordKind byte
const (
	OUTGOING TxHistoryRecordKind = iota
	INCOMING
)

type TxHistoryRecordState added in v0.2.0

type TxHistoryRecordState byte
const (
	UNCONFIRMED TxHistoryRecordState = iota
	CONFIRMED
	FAILED
)

type TxProof added in v0.2.0

type TxProof = types.TxProof

TxProof type alias for block.TxProof, can be removed once block package is moved out of internal

type Wallet

type Wallet struct {
	AlphabillClient client.ABClient
}

Shutdown needs to be called to release resources used by wallet.

func (*Wallet) GetRoundNumber added in v0.2.0

func (w *Wallet) GetRoundNumber(ctx context.Context) (uint64, error)

GetRoundNumber queries the node for latest round number

func (*Wallet) SendTransaction

func (w *Wallet) SendTransaction(ctx context.Context, tx *types.TransactionOrder, opts *SendOpts) error

SendTransaction broadcasts transaction to configured node. Returns nil if transaction was successfully accepted by node, otherwise returns error.

func (*Wallet) Shutdown

func (w *Wallet) Shutdown()

Shutdown terminates connection to alphabill node and cancels any background goroutines.

Directories

Path Synopsis
evm
Package log implements a logger interface that is used for logging inside Alphabill Wallet SDK.
Package log implements a logger interface that is used for logging inside Alphabill Wallet SDK.

Jump to

Keyboard shortcuts

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