wallets

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEndpoint = errs.Class("Wallets Endpoint")

ErrEndpoint is the wallets endpoint error class.

View Source
var ErrNoAvailableWallets = errs.New("no unclaimed wallets found")

ErrNoAvailableWallets represents the error that occurs when there are no deposit addresses that are unclaimed.

View Source
var ErrUpdateWallet = errs.New("could not update wallet by address")

ErrUpdateWallet represents the error that occurs when the db cannot update the row that has a certain address.

View Source
var ErrWalletsService = errs.Class("Wallets Service")

ErrWalletsService indicates about internal wallets service error.

Functions

func Generate

func Generate(ctx context.Context, keysname string, min, max int, mnemonic string) (map[common.Address]string, error)

Generate creates new HD wallet addresses.

Types

type Client

type Client struct {
	APIKey    string
	APISecret string
	Endpoint  string
}

Client is a REST client for wallet endpoints.

func NewClient

func NewClient(endpoint string, apiKey string, secret string) *Client

NewClient creates a new wallet client from HTTP endpoint address and secret.

func (*Client) AddWallets

func (w *Client) AddWallets(ctx context.Context, inserts []InsertWallet) error

AddWallets sends claimable generated addresses to the backend.

type DB

type DB interface {
	// Insert adds a new entry in the wallets table. Info can be an empty string.
	Insert(ctx context.Context, satellite string, address blockchain.Address, info string) (*Wallet, error)
	// InsertBatch adds a new db entry for each address. Entries is a slice of insert wallet data.
	InsertBatch(ctx context.Context, satellite string, entries []InsertWallet) error
	// Claim claims and returns the first unclaimed wallet address.
	Claim(ctx context.Context, satellite string) (*Wallet, error)
	// Get returns the information stored for a given address.
	Get(ctx context.Context, satellite string, address blockchain.Address) (*Wallet, error)
	// GetStats returns information about the wallets table.
	GetStats(ctx context.Context) (*Stats, error)
	// ListBySatellite returns accounts claimed by a certain satellite (address -> info).
	ListBySatellite(ctx context.Context, satellite string) (map[blockchain.Address]string, error)
}

DB is a wallets database that stores deposit address information.

architecture: Database

type Endpoint

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

Endpoint for interacting with the Wallets service.

architecture: Endpoint

func NewEndpoint

func NewEndpoint(log *zap.Logger, service *Service) *Endpoint

NewEndpoint creates new wallets endpoint instance.

func (*Endpoint) AddWallets

func (endpoint *Endpoint) AddWallets(w http.ResponseWriter, r *http.Request)

AddWallets saves newly generated wallets.

func (*Endpoint) Claim

func (endpoint *Endpoint) Claim(w http.ResponseWriter, r *http.Request)

Claim returns an available deposit address.

func (*Endpoint) Register

func (endpoint *Endpoint) Register(router *mux.Router)

Register registers endpoint methods on API server subroute.

type InsertWallet added in v1.0.2

type InsertWallet struct {
	Address blockchain.Address
	Info    string
}

InsertWallet gathers data needed to insert a wallet.

type Service

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

Service for querying and updating wallets information.

architecture: Service

func NewService

func NewService(log *zap.Logger, db DB) (*Service, error)

NewService initializes a wallets service instance.

func (*Service) Claim

func (service *Service) Claim(ctx context.Context, satellite string) (_ blockchain.Address, err error)

Claim claims the next unclaimed deposit address.

func (*Service) Get

func (service *Service) Get(ctx context.Context, satellite string, address blockchain.Address) (*Wallet, error)

Get returns information related to an address.

func (*Service) GetStats

func (service *Service) GetStats(ctx context.Context) (*Stats, error)

GetStats returns information about the wallets table.

func (*Service) ListBySatellite

func (service *Service) ListBySatellite(ctx context.Context, satellite string) (map[blockchain.Address]string, error)

ListBySatellite returns accounts claimed by a certain satellite. Returns map[address]info.

func (*Service) Register

func (service *Service) Register(ctx context.Context, satellite string, inserts []InsertWallet) error

Register inserts the addresses (key) and any associated info (value) to the persistent storage.

type Stats

type Stats struct {
	TotalCount     int
	ClaimedCount   int
	UnclaimedCount int
}

Stats represents the high level information about the wallets table.

type Wallet

type Wallet struct {
	Address   blockchain.Address
	Claimed   time.Time
	Satellite string
	Info      string
	CreatedAt time.Time
}

Wallet represents an entry in the wallets table.

Jump to

Keyboard shortcuts

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