client

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: ISC Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateServerSignature

func ValidateServerSignature(resp *http.Response, body []byte, serverPubkey []byte) error

Types

type AutoClient added in v2.1.0

type AutoClient struct {
	*Client
	// contains filtered or unexported fields
}

func New added in v2.1.0

func New(cfg Config, log slog.Logger) (*AutoClient, error)

func (*AutoClient) FeePercentage added in v2.1.0

func (c *AutoClient) FeePercentage(ctx context.Context) (float64, error)

func (*AutoClient) Process added in v2.1.0

func (c *AutoClient) Process(ctx context.Context, ticketHash *chainhash.Hash, feeTx *wire.MsgTx) error

Process begins processing a VSP fee payment for a ticket. If feeTx contains inputs, is used to pay the VSP fee. Otherwise, new inputs are selected and locked to prevent double spending the fee.

feeTx must not be nil, but may point to an empty transaction, and is modified with the inputs and the fee and change outputs before returning without an error. The fee transaction is also recorded as unpublised in the wallet, and the fee hash is associated with the ticket.

func (*AutoClient) ProcessManagedTickets added in v2.1.0

func (c *AutoClient) ProcessManagedTickets(ctx context.Context) error

ProcessManagedTickets discovers tickets which were previously registered with a VSP and begins syncing them in the background. This is used to recover VSP tracking after seed restores, and is only performed on unspent and unexpired tickets.

func (*AutoClient) ProcessTicket added in v2.1.0

func (c *AutoClient) ProcessTicket(ctx context.Context, hash *chainhash.Hash) error

ProcessTicket attempts to process a given ticket based on the hash provided.

func (*AutoClient) ProcessUnprocessedTickets added in v2.1.0

func (c *AutoClient) ProcessUnprocessedTickets(ctx context.Context)

ProcessUnprocessedTickets processes all tickets that don't currently have any association with a VSP.

func (*AutoClient) SetVoteChoice added in v2.1.0

func (c *AutoClient) SetVoteChoice(ctx context.Context, hash *chainhash.Hash,
	choices map[string]string, tspendPolicy map[string]string, treasuryPolicy map[string]string) error

SetVoteChoice takes the provided consensus, tspend and treasury key voting preferences, and checks if they match the status of the specified ticket from the connected VSP. The status provides the current voting preferences so we can just update from there if need be.

func (*AutoClient) TrackedTickets added in v2.1.0

func (c *AutoClient) TrackedTickets() []*TicketInfo

TrackedTickets returns information about all outstanding tickets tracked by a vsp.Client instance.

Currently this returns only info about tickets which fee hasn't been paid or confirmed at enough depth to be considered committed to.

type Client

type Client struct {
	http.Client
	URL    string
	PubKey []byte
	// Sign is a function which must be provided to an instance of Client so
	// that it can sign request bodies using the PrivKey of the specified
	// address.
	Sign func(context.Context, string, stdaddr.Address) ([]byte, error)
	Log  slog.Logger
}

func (*Client) FeeAddress

func (c *Client) FeeAddress(ctx context.Context, req types.FeeAddressRequest,
	commitmentAddr stdaddr.Address) (*types.FeeAddressResponse, error)

func (*Client) PayFee

func (c *Client) PayFee(ctx context.Context, req types.PayFeeRequest,
	commitmentAddr stdaddr.Address) (*types.PayFeeResponse, error)

func (*Client) SetVoteChoices

func (c *Client) SetVoteChoices(ctx context.Context, req types.SetVoteChoicesRequest,
	commitmentAddr stdaddr.Address) (*types.SetVoteChoicesResponse, error)

func (*Client) TicketStatus

func (c *Client) TicketStatus(ctx context.Context, req types.TicketStatusRequest,
	commitmentAddr stdaddr.Address) (*types.TicketStatusResponse, error)

func (*Client) VspInfo

func (c *Client) VspInfo(ctx context.Context) (*types.VspInfoResponse, error)

type Config added in v2.1.0

type Config struct {
	// URL specifies the base URL of the VSP
	URL string

	// PubKey specifies the VSP's base64 encoded public key
	PubKey string

	// Dialer specifies an optional dialer when connecting to the VSP.
	Dialer DialFunc

	// Wallet specifies a loaded wallet.
	Wallet Wallet

	// Default policy for fee payments unless another is provided by the
	// caller.
	Policy *Policy
}

type DialFunc added in v2.1.0

type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

type Policy added in v2.1.0

type Policy struct {
	MaxFee     dcrutil.Amount
	ChangeAcct uint32 // to derive fee addresses
	FeeAcct    uint32 // to pay fees from, if inputs are not provided to Process
}

type State added in v2.1.0

type State uint32
const (
	Unprocessed State
	FeePublished

	TicketSpent
)

type TicketInfo added in v2.1.0

type TicketInfo struct {
	TicketHash     chainhash.Hash
	CommitmentAddr stdaddr.StakeAddress
	VotingAddr     stdaddr.StakeAddress
	State          State
	Fee            dcrutil.Amount
	FeeHash        chainhash.Hash
}

TicketInfo stores per-ticket info tracked by a VSP Client instance.

type Wallet added in v2.1.0

type Wallet interface {
	Spender(ctx context.Context, out *wire.OutPoint) (*wire.MsgTx, uint32, error)
	MainChainTip(ctx context.Context) (hash chainhash.Hash, height int32)
	ChainParams() *chaincfg.Params
	TxBlock(ctx context.Context, hash *chainhash.Hash) (chainhash.Hash, int32, error)
	DumpWIFPrivateKey(ctx context.Context, addr stdaddr.Address) (string, error)
	VSPFeeHashForTicket(ctx context.Context, ticketHash *chainhash.Hash) (chainhash.Hash, error)
	UpdateVspTicketFeeToStarted(ctx context.Context, ticketHash, feeHash *chainhash.Hash, host string, pubkey []byte) error
	GetTransactionsByHashes(ctx context.Context, txHashes []*chainhash.Hash) (txs []*wire.MsgTx, notFound []*wire.InvVect, err error)
	ReserveOutputsForAmount(ctx context.Context, account uint32, amount dcrutil.Amount, minconf int32) ([]wallet.Input, error)
	UnlockOutpoint(txHash *chainhash.Hash, index uint32)
	NewChangeAddress(ctx context.Context, account uint32) (stdaddr.Address, error)
	RelayFee() dcrutil.Amount
	SignTransaction(ctx context.Context, tx *wire.MsgTx, hashType txscript.SigHashType, additionalPrevScripts map[wire.OutPoint][]byte,
		additionalKeysByAddress map[string]*dcrutil.WIF, p2shRedeemScriptsByAddress map[string][]byte) ([]wallet.SignatureError, error)
	SetPublished(ctx context.Context, hash *chainhash.Hash, published bool) error
	AddTransaction(ctx context.Context, tx *wire.MsgTx, blockHash *chainhash.Hash) error
	UpdateVspTicketFeeToPaid(ctx context.Context, ticketHash, feeHash *chainhash.Hash, host string, pubkey []byte) error
	UpdateVspTicketFeeToErrored(ctx context.Context, ticketHash *chainhash.Hash, host string, pubkey []byte) error
	AgendaChoices(ctx context.Context, ticketHash *chainhash.Hash) (choices wallet.AgendaChoices, voteBits uint16, err error)
	TSpendPolicyForTicket(ticketHash *chainhash.Hash) map[string]string
	TreasuryKeyPolicyForTicket(ticketHash *chainhash.Hash) map[string]string
	AbandonTransaction(ctx context.Context, hash *chainhash.Hash) error
	TxConfirms(ctx context.Context, hash *chainhash.Hash) (int32, error)
	ForUnspentUnexpiredTickets(ctx context.Context, f func(hash *chainhash.Hash) error) error
	IsVSPTicketConfirmed(ctx context.Context, ticketHash *chainhash.Hash) (bool, error)
	UpdateVspTicketFeeToConfirmed(ctx context.Context, ticketHash, feeHash *chainhash.Hash, host string, pubkey []byte) error
	VSPTicketInfo(ctx context.Context, ticketHash *chainhash.Hash) (*wallet.VSPTicket, error)
	SignMessage(ctx context.Context, msg string, addr stdaddr.Address) (sig []byte, err error)
}

Jump to

Keyboard shortcuts

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