Skip to content

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

Conversation

manoranjith
Copy link

This PR covers step 4 described in #233.

Note: To be merged after #297.

Copy link
Contributor

@matthiasgeihs matthiasgeihs left a 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()
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Manoranjith added 4 commits January 19, 2022 11:56
- 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>
@manoranjith manoranjith force-pushed the 233-use-unmarshal-marshal-binary branch from f732500 to 5af1ef7 Compare January 19, 2022 06:26
@matthiasgeihs matthiasgeihs merged commit aafb18b into hyperledger-labs:main Jan 19, 2022
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.

2 participants