rpcserver

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: ISC, MIT Imports: 20 Imported by: 9

Documentation

Overview

Package rpcserver implements the RPC API and is used by the main package to start gRPC services.

Full documentation of the API implemented by this package is maintained in a language-agnostic document:

TODO Document gRPC API like dcrwallet once the API is stable

Index

Constants

View Source
const (
	// The most probable reason for a command timing out would be because a
	// deadlock has occurred in the main process.  We want to reply with an
	// error message in this case before dcrstakepool applies a client timeout.
	// The commands are basic map operations and copies and typically complete
	// within one millisecond.  It is possible for an abnormally long garbage
	// collection cycle to also trigger a timeout but the current allocation
	// pattern of stakepoold is not known to cause such conditions at this time.
	GRPCCommandTimeout = time.Millisecond * 100
)

Public API version constants

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func MsgTxFromHex

func MsgTxFromHex(txhex string) (*wire.MsgTx, error)

MsgTxFromHex returns a wire.MsgTx struct built from the transaction hex string

func StartStakepooldService

func StartStakepooldService(appContext *AppContext, server *grpc.Server)

StartStakepooldService creates an implementation of the StakepooldService and registers it.

func StartVersionService

func StartVersionService(server *grpc.Server)

StartVersionService creates an implementation of the VersionService and registers it with the gRPC server.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

Types

type AppContext

type AppContext struct {
	sync.RWMutex

	// locking required
	AddedLowFeeTicketsMSA   map[chainhash.Hash]string            // [ticket]multisigaddr
	IgnoredLowFeeTicketsMSA map[chainhash.Hash]string            // [ticket]multisigaddr
	LiveTicketsMSA          map[chainhash.Hash]string            // [ticket]multisigaddr
	UserVotingConfig        map[string]userdata.UserVotingConfig // [multisigaddr]

	// no locking required
	DataPath               string
	FeeAddrs               map[string]struct{}
	PoolFees               float64
	NewTicketsChan         chan NewTicketsForBlock
	NodeConnection         *rpcclient.Client
	Params                 *chaincfg.Params
	Wg                     sync.WaitGroup // wait group for go routine exits
	Quit                   chan struct{}
	SpentmissedTicketsChan chan SpentMissedTicketsForBlock
	UserData               *userdata.UserData
	VotingConfig           *VotingConfig
	WalletConnection       *Client
	WinningTicketsChan     chan WinningTicketsForBlock
	Testing                bool // enabled only for testing
}

func (*AppContext) AccountSyncAddressIndex

func (ctx *AppContext) AccountSyncAddressIndex(account string, branch uint32, index int) error

func (*AppContext) AddMissingTicket

func (ctx *AppContext) AddMissingTicket(ticketHash []byte) error

func (*AppContext) CreateMultisig

func (ctx *AppContext) CreateMultisig(addresses []string) (*wallettypes.CreateMultiSigResult, error)

CreateMultisig decodes the provided array of addresses, and then passes them to dcrwallet to create a 1-of-N multisig address.

func (*AppContext) EvaluateStakePoolTicket

func (ctx *AppContext) EvaluateStakePoolTicket(tx *wire.MsgTx, blockHeight int32) (bool, error)

EvaluateStakePoolTicket evaluates a voting service ticket to see if it's acceptable to the voting service. The ticket must pay out to the voting service cold wallet, and must have a sufficient fee.

func (*AppContext) GetStakeInfo

func (ctx *AppContext) GetStakeInfo() (*wallettypes.GetStakeInfoResult, error)

GetStakeInfo performs the rpc command GetStakeInfo.

func (*AppContext) GetTickets

func (ctx *AppContext) GetTickets(includeImmature bool) ([]*chainhash.Hash, error)

func (*AppContext) ImportMissingScripts

func (ctx *AppContext) ImportMissingScripts(scripts [][]byte, rescanHeight int) error

ImportMissingScripts accepts a list of redeem scripts and a rescan height. It will import all but one of the scripts without triggering a wallet rescan, and finally trigger a rescan from the provided height after importing the last one.

func (*AppContext) ImportNewScript

func (ctx *AppContext) ImportNewScript(script []byte) (int64, error)

ImportNewScript will import a redeem script into dcrwallet. No rescan is performed because we are importing a brand new script, it shouldn't have any associated history. Current block height is returned to indicate which height the new user has registered.

func (*AppContext) ListScripts

func (ctx *AppContext) ListScripts() ([][]byte, error)

func (*AppContext) NewTicketHandler

func (ctx *AppContext) NewTicketHandler()

func (*AppContext) ProcessWinningTickets

func (ctx *AppContext) ProcessWinningTickets(wt WinningTicketsForBlock)

ProcessWinningTickets is called every time a new block comes in to handle voting. The function requires ASAP processing for each vote and therefore it is not sequential and hard to read. This is unfortunate but a reality of speeding up code.

func (*AppContext) SpentmissedTicketHandler

func (ctx *AppContext) SpentmissedTicketHandler()

func (*AppContext) StakePoolUserInfo

func (ctx *AppContext) StakePoolUserInfo(multisigAddress string) (*wallettypes.StakePoolUserInfoResult, error)

func (*AppContext) UpdateTicketData

func (ctx *AppContext) UpdateTicketData(newAddedLowFeeTicketsMSA map[chainhash.Hash]string)

func (*AppContext) UpdateTicketDataFromMySQL

func (ctx *AppContext) UpdateTicketDataFromMySQL() error

func (*AppContext) UpdateUserData

func (ctx *AppContext) UpdateUserData(newUserVotingConfig map[string]userdata.UserVotingConfig)

func (*AppContext) UpdateUserDataFromMySQL

func (ctx *AppContext) UpdateUserDataFromMySQL() error

func (*AppContext) ValidateAddress

func (ctx *AppContext) ValidateAddress(address string) (*wallettypes.ValidateAddressWalletResult, error)

func (*AppContext) WalletInfo

func (ctx *AppContext) WalletInfo() (*wallettypes.WalletInfoResult, error)

func (*AppContext) WinningTicketHandler

func (ctx *AppContext) WinningTicketHandler()

type Client

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

Client holds the information related to an rpcclient and handles access to that client through a mutex.

It should be noted that this is a temporary fix to the problem that rpcclient does not return an error when autoreconnect is turned on but the client is disconnected. The permanent solution is to change the behaviour of rpccleint. TODO: Remove this file.

func NewClient

func NewClient(cfg *rpcclient.ConnConfig, ntfnHandlers *rpcclient.NotificationHandlers) (*Client, error)

New creates a new Client and starts the automatic reconnection handler. Returns an error if unable to construct a new rpcclient.

func (*Client) Connected

func (c *Client) Connected() <-chan struct{}

Connected returns a receiving copy of the current connected channel. If disconnected and the channel is not yet blocking, creates a new channel that will be closed on a successful reconnect.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected checks and returns whethere the client is currently connected.

func (*Client) RPCClient

func (c *Client) RPCClient() *rpcclient.Client

RPCClient allows access to the underlying rpcclient by providing a copy of its address.

func (*Client) Stop

func (c *Client) Stop()

Stop stops automatic reconnections.

type NewTicketsForBlock

type NewTicketsForBlock struct {
	BlockHash   *chainhash.Hash
	BlockHeight int64
	NewTickets  []*chainhash.Hash
}

type SpentMissedTicketsForBlock

type SpentMissedTicketsForBlock struct {
	BlockHash   *chainhash.Hash
	BlockHeight int64
	SmTickets   map[*chainhash.Hash]bool
}

type VotingConfig

type VotingConfig struct {
	VoteBits         uint16
	VoteVersion      uint32
	VoteBitsExtended string
}

VotingConfig contains global voting defaults.

type WinningTicketsForBlock

type WinningTicketsForBlock struct {
	BlockHash      *chainhash.Hash
	BlockHeight    int64
	WinningTickets []*chainhash.Hash
}

Jump to

Keyboard shortcuts

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