btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.2k stars 2.36k forks source link

feat: Expose newFutureError for developer friendliness #2112

Closed devlzcode closed 7 months ago

devlzcode commented 8 months ago

Becuase the rpcclient.Response struct's fields are not exported we can not mirror the functionality of newFutureError ourselves. This is an issue especially when creating custom commands because we are forced to panic any errors in the *Async function. For example:

func SignRawTransactionWithKeyAsync(client *rpcclient.Client, tx *wire.MsgTx, privKeysWIF []string) FutureSignRawTransactionWithKeyResult {
    txHex := ""
    if tx != nil {
        buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
        if err := tx.Serialize(buf); err != nil {
            responseChan := make(chan *rpcclient.Response, 1)
            responseChan <- &rpcclient.Response{result: nil, err: err} // Can not compile because 'unknown field err in struct literal of type rpcclient.Response'
            return responseChan
        }
        txHex = hex.EncodeToString(buf.Bytes())
    }
    cmd := NewSignRawTransactionKeyCmd(txHex, &privKeysWIF)
    return client.SendCmd(cmd)
}
coveralls commented 7 months ago

Pull Request Test Coverage Report for Build 7663610047

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcclient/infrastructure.go 0 3 0.0%
<!-- Total: 0 3 0.0% -->
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.27%
peer/peer.go 3 74.6%
<!-- Total: 6 -->
Totals Coverage Status
Change from base Build 7635501416: 0.02%
Covered Lines: 29215
Relevant Lines: 51467

💛 - Coveralls