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

Try both TX serialization formats in createrawtransaction #1502

Merged
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
9 changes: 7 additions & 2 deletions rpcclient/rawtransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ func (r FutureCreateRawTransactionResult) Receive() (*wire.MsgTx, error) {

// Deserialize the transaction and return it.
var msgTx wire.MsgTx
if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
return nil, err
// we try both the new and old encoding format
witnessErr := msgTx.Deserialize(bytes.NewReader(serializedTx))
if witnessErr != nil {
legacyErr := msgTx.DeserializeNoWitness(bytes.NewReader(serializedTx))
if legacyErr != nil {
return nil, legacyErr
}
Comment on lines -237 to +242
Copy link
Collaborator

Choose a reason for hiding this comment

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

If both return an error, would the call to msgTx.Deserialize(...) return something useful that isn't already covered by msgTx.DeserializeNoWitness(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure I understand what you mean. Is this about which error to return?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sort of, yeah. Although I also just looked at the code and it's fine to do it this way. Let's say both msgTx.Deserialize and msgTx.DeserializeNoWitness both return an error. In this case, we go down the if witnessErr != nil branch and eventually return (nil, legacyErr). But there is a witnessErr which is non-nil and I was wondering if it might make sense to return both error messages.
I just checked the code though and both just make calls to msg.BtcDecode so it should be fine.

}
return &msgTx, nil
}
Expand Down