Skip to content

Commit

Permalink
returning response errors if they exist from bfg -> popm (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 authored Mar 6, 2024
1 parent d450b78 commit d6b0ac8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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

0 comments on commit d6b0ac8

Please sign in to comment.