-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: runtime panic #2836
fix: runtime panic #2836
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
package debugapi | ||
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
"math/big" | ||
"net/http" | ||
|
@@ -114,7 +115,7 @@ func New(publicKey, pssPublicKey ecdsa.PublicKey, ethereumAddress common.Address | |
// Configure injects required dependencies and configuration parameters and | ||
// constructs HTTP routes that depend on them. It is intended and safe to call | ||
// this method only once. | ||
func (s *Service) Configure(overlay swarm.Address, p2p p2p.DebugService, pingpong pingpong.Interface, topologyDriver topology.Driver, lightNodes *lightnode.Container, storer storage.Storer, tags *tags.Tags, accounting accounting.Interface, pseudosettle settlement.Interface, swapEnabled bool, chequebookEnabled bool, swap swap.Interface, chequebook chequebook.Service, batchStore postage.Storer, post postage.Service, postageContract postagecontract.Interface, traverser traversal.Traverser) { | ||
func (s *Service) Configure(overlay swarm.Address, p2p p2p.DebugService, pingpong pingpong.Interface, topologyDriver topology.Driver, lightNodes *lightnode.Container, storer storage.Storer, tags *tags.Tags, accounting accounting.Interface, pseudosettle settlement.Interface, swapEnabled bool, chequebookEnabled bool, swap swap.Interface, chequebook chequebook.Service, batchStore postage.Storer, post postage.Service, postageContract postagecontract.Interface, traverser traversal.Traverser, chainEnabled bool) { | ||
s.p2p = p2p | ||
s.pingpong = pingpong | ||
s.topologyDriver = topologyDriver | ||
|
@@ -125,6 +126,9 @@ func (s *Service) Configure(overlay swarm.Address, p2p p2p.DebugService, pingpon | |
s.chequebook = chequebook | ||
s.swapEnabled = swapEnabled | ||
s.swap = swap | ||
if !chainEnabled { | ||
s.swap = new(noOpSwap) | ||
} | ||
s.lightNodes = lightNodes | ||
s.batchStore = batchStore | ||
s.pseudosettle = pseudosettle | ||
|
@@ -145,3 +149,54 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
|
||
h.ServeHTTP(w, r) | ||
} | ||
|
||
type noOpSwap struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I went through the APIs to see how they are handled. Seems like there are a few errors like ErrNoChequebook which are being handled. I wonder if we should retain the errors here instead of returning empty responses? If API expects to send No Chequebook error if there is no chequebook, then this would sort of break that no? |
||
} | ||
|
||
func (*noOpSwap) TotalSent(peer swarm.Address) (totalSent *big.Int, err error) { | ||
return big.NewInt(0), nil | ||
} | ||
|
||
// TotalReceived returns the total amount received from a peer | ||
func (*noOpSwap) TotalReceived(peer swarm.Address) (totalSent *big.Int, err error) { | ||
return big.NewInt(0), nil | ||
} | ||
|
||
// SettlementsSent returns sent settlements for each individual known peer | ||
func (*noOpSwap) SettlementsSent() (map[string]*big.Int, error) { | ||
return nil, nil | ||
} | ||
|
||
// SettlementsReceived returns received settlements for each individual known peer | ||
func (*noOpSwap) SettlementsReceived() (map[string]*big.Int, error) { | ||
return nil, nil | ||
} | ||
|
||
func (*noOpSwap) LastSentCheque(peer swarm.Address) (*chequebook.SignedCheque, error) { | ||
return nil, nil | ||
} | ||
|
||
// LastSentCheques returns the list of last sent cheques for all peers | ||
func (*noOpSwap) LastSentCheques() (map[string]*chequebook.SignedCheque, error) { | ||
return nil, nil | ||
} | ||
|
||
// LastReceivedCheque returns the last received cheque for the peer | ||
func (*noOpSwap) LastReceivedCheque(peer swarm.Address) (*chequebook.SignedCheque, error) { | ||
return nil, nil | ||
} | ||
|
||
// LastReceivedCheques returns the list of last received cheques for all peers | ||
func (*noOpSwap) LastReceivedCheques() (map[string]*chequebook.SignedCheque, error) { | ||
return nil, nil | ||
} | ||
|
||
// CashCheque sends a cashing transaction for the last cheque of the peer | ||
func (*noOpSwap) CashCheque(ctx context.Context, peer swarm.Address) (common.Hash, error) { | ||
return common.Hash{}, nil | ||
} | ||
|
||
// CashoutStatus gets the status of the latest cashout transaction for the peers chequebook | ||
func (*noOpSwap) CashoutStatus(ctx context.Context, peer swarm.Address) (*chequebook.CashoutStatus, error) { | ||
return nil, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extra parameter can be avoided by either initialising swap to
noOpSwap
before passing here or maybe checking if theswap == nil
.