From ba77d39f35e74e94e5711d212ca6f6bea2eba6f3 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Fri, 7 Aug 2020 15:40:48 +0100 Subject: [PATCH] Comment exported methods --- database/addressindex.go | 4 ++++ database/database.go | 5 +++++ rpc/dcrd.go | 9 +++++++++ rpc/dcrwallet.go | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/database/addressindex.go b/database/addressindex.go index 8e399f8..c363efe 100644 --- a/database/addressindex.go +++ b/database/addressindex.go @@ -6,6 +6,8 @@ import ( bolt "go.etcd.io/bbolt" ) +// GetLastAddressIndex retrieves the last index used to derive a new fee +// address from the fee xpub key. func (vdb *VspDatabase) GetLastAddressIndex() (uint32, error) { var idx uint32 err := vdb.db.View(func(tx *bolt.Tx) error { @@ -24,6 +26,8 @@ func (vdb *VspDatabase) GetLastAddressIndex() (uint32, error) { return idx, err } +// SetLastAddressIndex updates the last index used to derive a new fee address +// from the fee xpub key. func (vdb *VspDatabase) SetLastAddressIndex(idx uint32) error { err := vdb.db.Update(func(tx *bolt.Tx) error { vspBkt := tx.Bucket(vspBktK) diff --git a/database/database.go b/database/database.go index 14a8e33..a7912d0 100644 --- a/database/database.go +++ b/database/database.go @@ -193,6 +193,7 @@ func (vdb *VspDatabase) Close() { } } +// KeyPair retrieves the keypair used to sign API responses from the database. func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error) { var seed []byte err := vdb.db.View(func(tx *bolt.Tx) error { @@ -227,6 +228,8 @@ func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error) return signKey, pubKey, err } +// GetFeeXPub retrieves the extended pubkey used for generating fee addresses +// from the database. func (vdb *VspDatabase) GetFeeXPub() (string, error) { var feeXPub string err := vdb.db.View(func(tx *bolt.Tx) error { @@ -245,6 +248,8 @@ func (vdb *VspDatabase) GetFeeXPub() (string, error) { return feeXPub, err } +// GetCookieSecret retrieves the generated cookie store secret key from the +// database. func (vdb *VspDatabase) GetCookieSecret() ([]byte, error) { var cookieSecret []byte err := vdb.db.View(func(tx *bolt.Tx) error { diff --git a/rpc/dcrd.go b/rpc/dcrd.go index 49f4474..7b45c17 100644 --- a/rpc/dcrd.go +++ b/rpc/dcrd.go @@ -102,6 +102,8 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (* return &DcrdRPC{c, ctx}, nil } +// GetRawTransaction uses getrawtransaction RPC to retrieve details about the +// transaction with the provided hash. func (c *DcrdRPC) GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, error) { verbose := 1 var resp dcrdtypes.TxRawResult @@ -112,6 +114,8 @@ func (c *DcrdRPC) GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, erro return &resp, nil } +// SendRawTransaction uses sendrawtransaction RPC to broadcast a transaction to +// the network. It ignores errors caused by duplicate transactions. func (c *DcrdRPC) SendRawTransaction(txHex string) error { allowHighFees := false err := c.Call(c.ctx, "sendrawtransaction", nil, txHex, allowHighFees) @@ -149,10 +153,13 @@ func (c *DcrdRPC) SendRawTransaction(txHex string) error { return nil } +// NotifyBlocks uses notifyblocks RPC to request new block notifications from dcrd. func (c *DcrdRPC) NotifyBlocks() error { return c.Call(c.ctx, "notifyblocks", nil) } +// GetBestBlockHeader uses getbestblockhash RPC, followed by getblockheader RPC, +// to retrieve the header of the best block known to the dcrd instance. func (c *DcrdRPC) GetBestBlockHeader() (*dcrdtypes.GetBlockHeaderVerboseResult, error) { var bestBlockHash string err := c.Call(c.ctx, "getbestblockhash", &bestBlockHash) @@ -169,6 +176,8 @@ func (c *DcrdRPC) GetBestBlockHeader() (*dcrdtypes.GetBlockHeaderVerboseResult, return &blockHeader, nil } +// ExistsLiveTicket uses existslivetickets RPC to check if the provided ticket +// hash is a live ticket known to the dcrd instance. func (c *DcrdRPC) ExistsLiveTicket(ticketHash string) (bool, error) { var exists string err := c.Call(c.ctx, "existslivetickets", &exists, []string{ticketHash}) diff --git a/rpc/dcrwallet.go b/rpc/dcrwallet.go index b5de45e..f401d31 100644 --- a/rpc/dcrwallet.go +++ b/rpc/dcrwallet.go @@ -135,6 +135,8 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) return walletClients, failedConnections } +// WalletInfo uses walletinfo RPC to retrieve information about how the +// dcrwallet instance is configured. func (c *WalletRPC) WalletInfo() (*wallettypes.WalletInfoResult, error) { var walletInfo wallettypes.WalletInfoResult err := c.Call(c.ctx, "walletinfo", &walletInfo) @@ -144,6 +146,8 @@ func (c *WalletRPC) WalletInfo() (*wallettypes.WalletInfoResult, error) { return &walletInfo, nil } +// AddTicketForVoting uses importprivkey RPC, followed by addtransaction RPC, to +// add a new ticket to a voting wallet. func (c *WalletRPC) AddTicketForVoting(votingWIF, blockHash, txHex string) error { label := "imported" rescan := false @@ -161,10 +165,14 @@ func (c *WalletRPC) AddTicketForVoting(votingWIF, blockHash, txHex string) error return nil } +// SetVoteChoice uses setvotechoice RPC to set the vote choice on the given +// agenda, for the given ticket. func (c *WalletRPC) SetVoteChoice(agenda, choice, ticketHash string) error { return c.Call(c.ctx, "setvotechoice", nil, agenda, choice, ticketHash) } +// GetBestBlockHeight uses getbestblock RPC to query the height of the best +// block known by the dcrwallet instance. func (c *WalletRPC) GetBestBlockHeight() (int64, error) { var block dcrdtypes.GetBestBlockResult err := c.Call(c.ctx, "getbestblock", &block) @@ -174,6 +182,8 @@ func (c *WalletRPC) GetBestBlockHeight() (int64, error) { return block.Height, nil } +// TicketInfo uses ticketinfo RPC to retrieve a detailed list of all tickets +// known by this dcrwallet instance. func (c *WalletRPC) TicketInfo() (map[string]*wallettypes.TicketInfoResult, error) { var result []*wallettypes.TicketInfoResult err := c.Call(c.ctx, "ticketinfo", &result) @@ -191,6 +201,8 @@ func (c *WalletRPC) TicketInfo() (map[string]*wallettypes.TicketInfoResult, erro return tickets, err } +// RescanFrom uses rescanwallet RPC to trigger the wallet to perform a rescan +// from the specified block height. func (c *WalletRPC) RescanFrom(fromHeight int64) error { return c.Call(c.ctx, "rescanwallet", nil, fromHeight) }