-
Notifications
You must be signed in to change notification settings - Fork 18
Use UnmarshalBinary and MarshalBinary for converting to/from Binary form #298
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
Use UnmarshalBinary and MarshalBinary for converting to/from Binary form #298
Conversation
9d1b150
to
f732500
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but still need to rebase first.
@@ -197,15 +195,15 @@ func ToEthState(s *channel.State) adjudicator.ChannelState { | |||
if len(outcome.Assets) != len(outcome.Balances) || len(s.Balances) != len(outcome.Balances) { | |||
log.Panic("invalid allocation dimensions") | |||
} | |||
appData := new(bytes.Buffer) | |||
if err := perunio.Encode(appData, s.Data); err != nil { | |||
appData, err := s.Data.MarshalBinary() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are in the Ethereum backend here, we could actually handle marshalling in a non-generic way. But I guess for now it is fine like this.
Wallet: hdWallet, | ||
AddressInWallet: acc.Address(), | ||
Backend: new(ethwallet.Backend), | ||
AddressMarshalled: addrMarshalled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think renaming was actually necessary here, but OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be interested to know why do you think so ?
I did a rename here, because Address
type has both Encode
and MarshalBinary
methods defined on it. And we have switched from using Encode
to MarshalBinary
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Address
type does not have an Encode
function anymore.
- Because encoding functions convert data to/from formats that can be send/received over the wire. - But, here, we only want to convert it to binary form. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
- Because encoding functions convert data to/from formats that can be send/received over the wire. - But, here, we only want to convert it to binary form. - Also, rename the variables in test setup to convey that these are marshalled values and not encoded ones. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
- For converting data to/from binary form, in order to make a deep copy of it. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
- Nonce share, by itself is a byte array. - Hence, it can be directly hashed without encoding. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
f732500
to
5af1ef7
Compare
This PR covers step 4 described in #233.
Note: To be merged after #297.