Skip to content
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

returning response errors if they exist from bfg -> popm #24

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ func (e Error) String() string {
return fmt.Sprintf("%v [%v:%v]", e.Message, e.Trace, e.Timestamp)
}

func (e Error) Error() string {
return e.String()
}

// RequestError wraps an error to create a protocol request error.
//
// Request errors are usually something caused by a client, e.g. validation or
Expand Down
36 changes: 36 additions & 0 deletions service/popm/popm.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func (m *Miner) bitcoinBalance(ctx context.Context, scriptHash []byte) (uint64,
return 0, 0, fmt.Errorf("not a BitcoinBalanceResponse %T", res)
}

if bResp.Error != nil {
return 0, 0, bResp.Error
}

return bResp.Confirmed, bResp.Unconfirmed, nil
}

Expand All @@ -168,6 +172,10 @@ func (m *Miner) bitcoinBroadcast(ctx context.Context, tx []byte) ([]byte, error)
return nil, fmt.Errorf("not a bitcoin broadcast response %T", res)
}

if bbResp.Error != nil {
return nil, bbResp.Error
}

return bbResp.TXID, nil
}

Expand All @@ -184,6 +192,10 @@ func (m *Miner) bitcoinHeight(ctx context.Context) (uint64, error) {
return 0, fmt.Errorf("not a BitcoinIfnoResponse")
}

if biResp.Error != nil {
return 0, biResp.Error
}

return biResp.Height, nil
}

Expand All @@ -202,6 +214,10 @@ func (m *Miner) bitcoinUTXOs(ctx context.Context, scriptHash []byte) ([]*bfgapi.
return nil, fmt.Errorf("not a buResp %T", res)
}

if buResp.Error != nil {
return nil, buResp.Error
}

return buResp.UTXOs, nil
}

Expand Down Expand Up @@ -372,6 +388,10 @@ func (m *Miner) L2Keystones(ctx context.Context, count uint64) (*bfgapi.L2Keysto
return nil, fmt.Errorf("not a L2KeystonesResponse: %T", res)
}

if kr.Error != nil {
return nil, kr.Error
}

return kr, nil
}

Expand All @@ -395,6 +415,10 @@ func (m *Miner) BitcoinBalance(ctx context.Context, scriptHash string) (*bfgapi.
return nil, fmt.Errorf("not a BitcoinBalanceResponse: %T", res)
}

if br.Error != nil {
return nil, br.Error
}

return br, nil
}

Expand All @@ -409,6 +433,10 @@ func (m *Miner) BitcoinInfo(ctx context.Context) (*bfgapi.BitcoinInfoResponse, e
return nil, fmt.Errorf("not a BitcoinInfoResponse: %T", res)
}

if ir.Error != nil {
return nil, ir.Error
}

return ir, nil
}

Expand All @@ -432,6 +460,10 @@ func (m *Miner) BitcoinUTXOs(ctx context.Context, scriptHash string) (*bfgapi.Bi
return nil, fmt.Errorf("not a BitcoinUTXOsResponse: %T", res)
}

if ir.Error != nil {
return nil, ir.Error
}

return ir, nil
}

Expand Down Expand Up @@ -542,6 +574,10 @@ func (m *Miner) checkForKeystones(ctx context.Context) error {
return fmt.Errorf("not an L2KeystonesResponse")
}

if ghkrResp.Error != nil {
return ghkrResp.Error
}

log.Tracef("Got response with %v keystones", len(ghkrResp.L2Keystones))

m.processReceivedKeystones(ctx, ghkrResp.L2Keystones)
Expand Down