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

feat: Expose newFutureError for developer friendliness #2112

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

devlzcode
Copy link
Contributor

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)
}

Copy link
Contributor Author

@devlzcode devlzcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7663610047

Details

  • -3 of 3 (0.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 56.765%

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

💛 - Coveralls

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🧥

@Roasbeef Roasbeef merged commit 9ea2eea into btcsuite:master Feb 27, 2024
3 checks passed
@devlzcode devlzcode deleted the expose-newfutureerror branch February 28, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants