Skip to content

Commit

Permalink
all: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jul 22, 2024
1 parent b965b13 commit df5a1d7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
29 changes: 17 additions & 12 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ type Client struct {
n *consensus.Network // for ConsensusTipState
}

func (c *Client) getNetwork() (*consensus.Network, error) {
if c.n == nil {
var err error
c.n, err = c.ConsensusNetwork()
if err != nil {
return nil, err
}
}
return c.n, nil
}

// State returns information about the current state of the walletd daemon.
func (c *Client) State() (resp StateResponse, err error) {
err = c.c.GET("/state", &resp)
Expand All @@ -36,6 +47,8 @@ func (c *Client) TxpoolTransactions() (txns []types.Transaction, v2txns []types.
return resp.Transactions, resp.V2Transactions, err
}

// TxpoolParents returns the parents of a transaction that are currently in the
// transaction pool.
func (c *Client) TxpoolParents(txn types.Transaction) (resp []types.Transaction, err error) {
err = c.c.POST("/txpool/parents", txn, &resp)
return
Expand All @@ -61,22 +74,14 @@ func (c *Client) ConsensusTip() (resp types.ChainIndex, err error) {
return
}

// ConsensusIndex returns the consensus index at the specified height.
func (c *Client) ConsensusIndex(height uint64) (resp types.ChainIndex, err error) {
err = c.c.GET(fmt.Sprintf("/consensus/index/%d", height), &resp)
return
}

func (c *Client) getNetwork() (*consensus.Network, error) {
if c.n == nil {
var err error
c.n, err = c.ConsensusNetwork()
if err != nil {
return nil, err
}
}
return c.n, nil
}

// ConsensusUpdates returns at most n consensus updates that have occurred since
// the specified index
func (c *Client) ConsensusUpdates(index types.ChainIndex, limit int) ([]chain.RevertUpdate, []chain.ApplyUpdate, error) {
// index.String() is a short-hand representation. We need the full text
indexBuf, err := index.MarshalText()
Expand All @@ -85,7 +90,7 @@ func (c *Client) ConsensusUpdates(index types.ChainIndex, limit int) ([]chain.Re
}

var resp ConsensusUpdatesResponse
if err = c.c.GET(fmt.Sprintf("/consensus/updates/%s?limit=%d", indexBuf, limit), &resp); err != nil {
if err := c.c.GET(fmt.Sprintf("/consensus/updates/%s?limit=%d", indexBuf, limit), &resp); err != nil {
return nil, nil, err
}

Expand Down
1 change: 1 addition & 0 deletions api/opts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api

// A ServerOption is a functional option type for configuring the API server.
type ServerOption func(*server)

// WithChainManager sets the chain manager used by the server.
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ type (
Password string `yaml:"password,omitempty"`
}

// Syncer contains the configuration for the p2p syncer.
Syncer struct {
Address string `yaml:"address,omitempty"`
Peers []string `yaml:"peers,omitempty"`
EnableUPNP bool `yaml:"enableUPnP,omitempty"`
Bootstrap bool `yaml:"bootstrap,omitempty"`
}

// A RemoteConsensus contains the configuration for connecting to a remote
// consensus database.
RemoteConsensus struct {
Address string `yaml:"address,omitempty"`
Password string `yaml:"password,omitempty"`
Expand Down
7 changes: 3 additions & 4 deletions internal/remote/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type (

// UpdatesSince returns any consensus updates since the given index, up to a
// maximum of max updates.
func (cm *ChainManager) UpdatesSince(index types.ChainIndex, max int) ([]chain.RevertUpdate, []chain.ApplyUpdate, error) {
return cm.client.ConsensusUpdates(index, max)
func (cm *ChainManager) UpdatesSince(index types.ChainIndex, limit int) ([]chain.RevertUpdate, []chain.ApplyUpdate, error) {
return cm.client.ConsensusUpdates(index, limit)
}

// BestIndex returns the chain index for the given height, or false if the height
Expand All @@ -51,7 +51,6 @@ func (cm *ChainManager) Tip() types.ChainIndex {
cm.mu.Lock()
defer cm.mu.Unlock()
return cm.state.Index

}

// TipState returns the current state of the consensus set.
Expand Down Expand Up @@ -123,7 +122,6 @@ func (cm *ChainManager) updateState() error {
cm.fee = fee
cm.mu.Unlock()
return nil

}

// OnReorg registers a callback to be called when a reorganization occurs.
Expand All @@ -147,6 +145,7 @@ func (cm *ChainManager) OnReorg(fn func(types.ChainIndex)) (cancel func()) {
}
}

// NewChainManager creates a new ChainManager.
func NewChainManager(client *api.Client, log *zap.Logger, opts ...ChainManagerOption) (*ChainManager, error) {
cm := &ChainManager{
client: client,
Expand Down
2 changes: 2 additions & 0 deletions internal/remote/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package remote

import "time"

// ChainManagerOption is a functional option type for configuring a ChainManager.
type ChainManagerOption func(*ChainManager)

// WithRefreshInterval sets the polling interval used by the chain manager.
func WithRefreshInterval(interval time.Duration) ChainManagerOption {
return func(cm *ChainManager) {
cm.refreshInterval = interval
Expand Down
3 changes: 3 additions & 0 deletions internal/remote/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.uber.org/zap"
)

// A Syncer is a syncer.Syncer that uses a remote API to broadcast transactions.
type Syncer struct {
client *api.Client
log *zap.Logger
Expand Down Expand Up @@ -41,6 +42,8 @@ func (s *Syncer) BroadcastTransactionSet(txns []types.Transaction) {
}
}

// BroadcastV2TransactionSet broadcasts a set of v2 transactions using the remote
// API
func (s *Syncer) BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction) {
if err := s.client.TxpoolBroadcast(nil, txns); err != nil {
s.log.Error("failed to broadcast v2 transaction set", zap.Error(err))
Expand Down

0 comments on commit df5a1d7

Please sign in to comment.