Skip to content

Commit

Permalink
Run go fmt from Go 1.19 over the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Aug 3, 2022
1 parent 4a6cfc5 commit ed842ec
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 157 deletions.
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ func parseAndSetDebugLevels(debugLevel string) error {
// line options.
//
// The configuration proceeds as follows:
// 1) Start with a default config with sane settings
// 2) Pre-parse the command line to check for an alternative config file
// 3) Load configuration file overwriting defaults with any specified options
// 4) Parse CLI options and overwrite/add any specified options
// 1. Start with a default config with sane settings
// 2. Pre-parse the command line to check for an alternative config file
// 3. Load configuration file overwriting defaults with any specified options
// 4. Parse CLI options and overwrite/add any specified options
//
// The above results in dcrwallet functioning properly without any config
// settings while still allowing the user to override settings with config files
Expand Down
24 changes: 12 additions & 12 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ func Errorf(format string, args ...interface{}) error {
// args of similar type are passed, the final arg is recorded. The following
// types are recognized:
//
// errors.Op
// The operation, method, or RPC which was invoked.
// errors.Kind
// The class of error.
// string
// Description of the error condition. String types populate the
// Err field and overwrite, and are overwritten by, other arguments
// which implement the error interface.
// error
// The underlying error. If the error is an *Error, the Op and Kind
// will be promoted to the newly created error if not set to another
// value in the args.
// errors.Op
// The operation, method, or RPC which was invoked.
// errors.Kind
// The class of error.
// string
// Description of the error condition. String types populate the
// Err field and overwrite, and are overwritten by, other arguments
// which implement the error interface.
// error
// The underlying error. If the error is an *Error, the Op and Kind
// will be promoted to the newly created error if not set to another
// value in the args.
//
// If another *Error is passed as an argument and no other arguments differ from
// the wrapped error, instead of wrapping the error, the errors are collapsed
Expand Down
36 changes: 21 additions & 15 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2918,14 +2918,17 @@ func (s *Server) listLockUnspent(ctx context.Context, icmd interface{}) (interfa

// listReceivedByAccount handles a listreceivedbyaccount request by returning
// a slice of objects, each one containing:
// "account": the receiving account;
// "amount": total amount received by the account;
// "confirmations": number of confirmations of the most recent transaction.
//
// "account": the receiving account;
// "amount": total amount received by the account;
// "confirmations": number of confirmations of the most recent transaction.
//
// It takes two parameters:
// "minconf": minimum number of confirmations to consider a transaction -
// default: one;
// "includeempty": whether or not to include addresses that have no transactions -
// default: false.
//
// "minconf": minimum number of confirmations to consider a transaction -
// default: one;
// "includeempty": whether or not to include addresses that have no transactions -
// default: false.
func (s *Server) listReceivedByAccount(ctx context.Context, icmd interface{}) (interface{}, error) {
cmd := icmd.(*types.ListReceivedByAccountCmd)
w, ok := s.walletLoader.LoadedWallet()
Expand All @@ -2951,15 +2954,18 @@ func (s *Server) listReceivedByAccount(ctx context.Context, icmd interface{}) (i

// listReceivedByAddress handles a listreceivedbyaddress request by returning
// a slice of objects, each one containing:
// "account": the account of the receiving address;
// "address": the receiving address;
// "amount": total amount received by the address;
// "confirmations": number of confirmations of the most recent transaction.
//
// "account": the account of the receiving address;
// "address": the receiving address;
// "amount": total amount received by the address;
// "confirmations": number of confirmations of the most recent transaction.
//
// It takes two parameters:
// "minconf": minimum number of confirmations to consider a transaction -
// default: one;
// "includeempty": whether or not to include addresses that have no transactions -
// default: false.
//
// "minconf": minimum number of confirmations to consider a transaction -
// default: one;
// "includeempty": whether or not to include addresses that have no transactions -
// default: false.
func (s *Server) listReceivedByAddress(ctx context.Context, icmd interface{}) (interface{}, error) {
cmd := icmd.(*types.ListReceivedByAddressCmd)
w, ok := s.walletLoader.LoadedWallet()
Expand Down
2 changes: 1 addition & 1 deletion internal/rpc/jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func NewServer(opts *Options, activeNet *chaincfg.Params, walletLoader *loader.L
// httpBasicAuth returns the UTF-8 bytes of the HTTP Basic authentication
// string:
//
// "Basic " + base64(username + ":" + password)
// "Basic " + base64(username + ":" + password)
func httpBasicAuth(username, password string) []byte {
const header = "Basic "
base64 := base64.StdEncoding
Expand Down
4 changes: 2 additions & 2 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
// Full documentation of the API implemented by this package is maintained in a
// language-agnostic document:
//
// https://github.com/decred/dcrwallet/blob/master/rpc/documentation/api.md
// https://github.com/decred/dcrwallet/blob/master/rpc/documentation/api.md
//
// Any API changes must be performed according to the steps listed here:
//
// https://github.com/decred/dcrwallet/blob/master/rpc/documentation/serverchanges.md
// https://github.com/decred/dcrwallet/blob/master/rpc/documentation/serverchanges.md
package rpcserver

import (
Expand Down
11 changes: 6 additions & 5 deletions rpc/client/dcrd/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ func (r *RPC) ExistsLiveTickets(ctx context.Context, tickets []*chainhash.Hash)

// MempoolCount returns the count of a particular kind of transaction in mempool.
// Kind may be one of:
// "all"
// "regular"
// "tickets"
// "votes"
// "revocations"
//
// "all"
// "regular"
// "tickets"
// "votes"
// "revocations"
func (r *RPC) MempoolCount(ctx context.Context, kind string) (int, error) {
const op errors.Op = "dcrd.MempoolCount"
// This is rather inefficient, as only the count is needed, not all
Expand Down
26 changes: 13 additions & 13 deletions rpc/jsonrpc/types/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ this process. An overview specific to this package is provided here, however it
is also instructive to read the documentation for the dcrjson package
(https://pkg.go.dev/github.com/decred/dcrd/dcrjson/v4).
Marshalling and Unmarshalling
# Marshalling and Unmarshalling
The types in this package map to the required parts of the protocol as discussed
in the dcrjson documention
- Request Objects (type Request)
- Commands (type <Foo>Cmd)
- Notifications (type <Foo>Ntfn)
- Commands (type <Foo>Cmd)
- Notifications (type <Foo>Ntfn)
- Response Objects (type Response)
- Result (type <Foo>Result)
- Result (type <Foo>Result)
To simplify the marshalling of the requests and responses, the
dcrjson.MarshalCmd and dcrjson.MarshalResponse functions may be used. They
return the raw bytes ready to be sent across the wire.
Unmarshalling a received Request object is a two step process:
1) Unmarshal the raw bytes into a Request struct instance via json.Unmarshal
2) Use UnmarshalCmd on the Result field of the unmarshalled Request to create
a concrete command or notification instance with all struct fields set
accordingly
1. Unmarshal the raw bytes into a Request struct instance via json.Unmarshal
2. Use UnmarshalCmd on the Result field of the unmarshalled Request to create
a concrete command or notification instance with all struct fields set
accordingly
This approach is used since it provides the caller with access to the additional
fields in the request that are not part of the command such as the ID.
Unmarshalling a received Response object is also a two step process:
1) Unmarshal the raw bytes into a Response struct instance via json.Unmarshal
2) Depending on the ID, unmarshal the Result field of the unmarshalled
Response to create a concrete type instance
1. Unmarshal the raw bytes into a Response struct instance via json.Unmarshal
2. Depending on the ID, unmarshal the Result field of the unmarshalled
Response to create a concrete type instance
As above, this approach is used since it provides the caller with access to the
fields in the response such as the ID and Error.
Command Creation
# Command Creation
This package provides two approaches for creating a new command. This first,
and preferred, method is to use one of the New<Foo>Cmd functions. This allows
Expand All @@ -59,7 +59,7 @@ these checks are, obviously, run-time which means any mistakes won't be found
until the code is actually executed. However, it is quite useful for
user-supplied commands that are intentionally dynamic.
Help Generation
# Help Generation
To facilitate providing consistent help to users of the RPC server, the dcrjson
package exposes the GenerateHelp and function which uses reflection on commands
Expand Down
1 change: 0 additions & 1 deletion rpc/jsonrpc/types/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ type GetWalletFeeCmd struct{}

// NewGetWalletFeeCmd returns a new instance which can be used to issue a
// getwalletfee JSON-RPC command.
//
func NewGetWalletFeeCmd() *GetWalletFeeCmd {
return &GetWalletFeeCmd{}
}
Expand Down
1 change: 0 additions & 1 deletion wallet/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
/*
Package wallet provides ...
TODO: Flesh out this section
*/
package wallet
10 changes: 5 additions & 5 deletions wallet/drivers/bdb/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// wallet.OpenDB and wallet.CreateDB functions to be called with the following
// arguments:
//
// var filename string
// db, err := wallet.CreateDB("bdb", filename)
// if err != nil { /* handle error */ }
// db, err = wallet.OpenDB("bdb", filename)
// if err != nil { /* handle error */ }
// var filename string
// db, err := wallet.CreateDB("bdb", filename)
// if err != nil { /* handle error */ }
// db, err = wallet.OpenDB("bdb", filename)
// if err != nil { /* handle error */ }
package bdb

import _ "decred.org/dcrwallet/v2/wallet/internal/bdb" // Register bdb driver during init
2 changes: 1 addition & 1 deletion wallet/internal/bdb/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Package bdb implements an instance of walletdb that uses boltdb for the backing
datastore.
Usage
# Usage
This package is only a driver to the walletdb package and provides the database
type of "bdb". The only parameter the Open and Create functions take is the
Expand Down
33 changes: 16 additions & 17 deletions wallet/txrules/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@ Package txrules provides functions that are help establish whether or not
a transaction abides by non-consensus rules for things like the daemon and
stake pool.
Dust and Fee Per KB Calculation
# Dust and Fee Per KB Calculation
Please refer to mempool.go in dcrd for more information about the importance
of these function.
Pool Fees
# Pool Fees
The pool fee is calculated from the percentage given according to the
following formula:
ps(v+z)
f = --------------
s+v
ps(v+z)
f = --------------
s+v
where f = absolute pool fee as an amount
p = proportion (e.g. 0.5000 = 50.00%)
s = subsidy (adjusted two difficulty periods into the future)
v = price of the ticket
z = the ticket fees
where f = absolute pool fee as an amount
p = proportion (e.g. 0.5000 = 50.00%)
s = subsidy (adjusted two difficulty periods into the future)
v = price of the ticket
z = the ticket fees
This can be derived from the known relation that
ps = (f * (v+z)/(v+s)) obtained from the knowledge
that the outputs of the vote are the amounts
of the stake ticket plus subsidy (v+s) scaled by
the proportional input of the stake pool fee
f/(v+z).
This can be derived from the known relation that
ps = (f * (v+z)/(v+s)) obtained from the knowledge
that the outputs of the vote are the amounts
of the stake ticket plus subsidy (v+s) scaled by
the proportional input of the stake pool fee
f/(v+z).
f is then adjusted for the fact that at least one subsidy reduction is
likely to occur before it can vote on a block.
*/
package txrules
15 changes: 9 additions & 6 deletions wallet/udb/addressmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ func (m *Manager) CoinTypePrivKey(dbtx walletdb.ReadTx) (*hdkeychain.ExtendedKey
// of the same seed in multicurrency wallets. New (not restored) wallets are
// now created using the coin types assigned to Decred in SLIP0044:
//
// https://github.com/satoshilabs/slips/blob/master/slip-0044.md
// https://github.com/satoshilabs/slips/blob/master/slip-0044.md
//
// The address manager should be upgraded to the SLIP0044 coin type if it is
// currently using the legacy coin type and there are no used accounts or
Expand Down Expand Up @@ -1434,9 +1434,10 @@ func (m *Manager) LookupAccount(ns walletdb.ReadBucket, name string) (uint32, er

// UnlockedWithPassphrase returns nil when the wallet is currently unlocked with a
// matching passphrase and errors with the following codes otherwise:
// WatchingOnly: The wallet is watching-only and can never be unlocked
// Locked: The wallet is currently locked
// Passphrase: The wallet is unlocked but the provided passphrase is incorrect
//
// WatchingOnly: The wallet is watching-only and can never be unlocked
// Locked: The wallet is currently locked
// Passphrase: The wallet is unlocked but the provided passphrase is incorrect
func (m *Manager) UnlockedWithPassphrase(passphrase []byte) error {
defer m.mtx.RUnlock()
m.mtx.RLock()
Expand Down Expand Up @@ -2657,7 +2658,8 @@ func deriveCoinTypeKey(masterNode *hdkeychain.ExtendedKey, coinType uint32) (*hd
// hierarchy described by BIP0044 given the master node.
//
// In particular this is the hierarchical deterministic extended key path:
// m/44'/<coin type>'/<account>'
//
// m/44'/<coin type>'/<account>'
func deriveAccountKey(coinTypeKey *hdkeychain.ExtendedKey, account uint32) (*hdkeychain.ExtendedKey, error) {
// Enforce maximum account number.
if account > MaxAccountNum {
Expand All @@ -2675,7 +2677,8 @@ func deriveAccountKey(coinTypeKey *hdkeychain.ExtendedKey, account uint32) (*hdk
// accordingly.
//
// In particular this is the hierarchical deterministic extended key path:
// m/44'/<coin type>'/<account>'/<branch>
//
// m/44'/<coin type>'/<account>'/<branch>
//
// The branch is 0 for external addresses and 1 for internal addresses.
func checkBranchKeys(acctKey *hdkeychain.ExtendedKey) error {
Expand Down
10 changes: 6 additions & 4 deletions wallet/udb/stakedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ var (

// Key names for various database fields.
// sstxRecords
// key: sstx tx hash
// val: sstxRecord
//
// key: sstx tx hash
// val: sstxRecord
//
// ssgenRecords
// key: sstx tx hash
// val: serialized slice of ssgenRecords
//
// key: sstx tx hash
// val: serialized slice of ssgenRecords
var (
// Bucket names.
sstxRecordsBucketName = []byte("sstxrecords")
Expand Down
Loading

0 comments on commit ed842ec

Please sign in to comment.