From d6b0ac8af997e51da4b01aae959012e92e6070ca Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Wed, 6 Mar 2024 09:19:57 -0500 Subject: [PATCH] returning response errors if they exist from bfg -> popm (#24) --- api/protocol/protocol.go | 4 ++++ service/popm/popm.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/api/protocol/protocol.go b/api/protocol/protocol.go index 95d79a31..cb322525 100644 --- a/api/protocol/protocol.go +++ b/api/protocol/protocol.go @@ -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 diff --git a/service/popm/popm.go b/service/popm/popm.go index 3b2e37b8..3a393938 100644 --- a/service/popm/popm.go +++ b/service/popm/popm.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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)