Skip to content

Introduce ContractAddress newtype instead of scheme enum#200

Merged
ordian merged 5 commits into
paritytech:masterfrom
coblox:split-up-fn
Aug 21, 2019
Merged

Introduce ContractAddress newtype instead of scheme enum#200
ordian merged 5 commits into
paritytech:masterfrom
coblox:split-up-fn

Conversation

@thomaseizinger

Copy link
Copy Markdown
Contributor

Not all variants of scheme used all the parameters of the previous contract_address function, yet they still needed to be passed.

I took a shot at redesigning the interface of this crate to allow for the most convenient usage.

Let me know what you think!

The two methods from_sender_salt_and_code and from_sender_and_code both return a tuple with the computed hash. I don't know how these methods are actually being used, so I don't know if we actually need that return value. It seems a bit odd to me because it looks like the hash is an implementation detail of how to compute the address and should be hidden inside the function.

Not all variants of scheme used all the parameters of the previous
`contract_address` function, yet they still needed to be passed.
@parity-cla-bot

Copy link
Copy Markdown

It looks like @thomaseizinger hasn't signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io

Once you've signed, please reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@thomaseizinger

Copy link
Copy Markdown
Contributor Author

[clabot:check]

@parity-cla-bot

Copy link
Copy Markdown

It looks like @thomaseizinger signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@ordian

ordian commented Aug 14, 2019

Copy link
Copy Markdown
Contributor

The two methods from_sender_salt_and_code and from_sender_and_code both return a tuple with the computed hash. I don't know how these methods are actually being used, so I don't know if we actually need that return value. It seems a bit odd to me because it looks like the hash is an implementation detail of how to compute the address and should be hidden inside the function.

Yes, the code hash is used, although it looks weird.

Not all variants of scheme used all the parameters of the previous contract_address function, yet they still needed to be passed.
I took a shot at redesigning the interface of this crate to allow for the most convenient usage.

Thanks, the usage is indeed seems more convenient now. But we have code that passes the enum around, so we need to keep it.

@thomaseizinger

Copy link
Copy Markdown
Contributor Author

Yes, the code hash is used, although it looks weird.

The code that is passed is hashed as the first step in the function. If the hash is needed outside of that function as-well, I'd propose to change the signature of these functions to accept the hash directly instead of the code, then we can remove the awkward tuple return value and the calling code gets to still have the code_hash.

Would that change work for you?

Thanks, the usage is indeed seems more convenient now. But we have code that passes the enum around, so we need to keep it.

What are your thoughts on this PR then? Should I add the scheme back and provide a 4th method?

In the spirit of providing a useful, general-purpose crate for computing contract addresses for Ethereum, I feel like the need to pass around a creation-scheme is fairly application specific and does not really need to be in this crate? 😬

@ordian

ordian commented Aug 15, 2019

Copy link
Copy Markdown
Contributor

The code that is passed is hashed as the first step in the function. If the hash is needed outside of that function as-well, I'd propose to change the signature of these functions to accept the hash directly instead of the code, then we can remove the awkward tuple return value and the calling code gets to still have the code_hash.
Would that change work for you?

Yes, sounds reasonable.

What are your thoughts on this PR then? Should I add the scheme back and provide a 4th method?
In the spirit of providing a useful, general-purpose crate for computing contract addresses for Ethereum, I feel like the need to pass around a creation-scheme is fairly application specific and does not really need to be in this crate?

I agree :) Let's remove the enum.

This allows us to not return a tuple but just the address.
@thomaseizinger

Copy link
Copy Markdown
Contributor Author

@ordian As discussed, I removed the hashing and the tuple return value :)

Let me know, if this PR needs anything else from my side!

@ordian ordian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you update the readme (the doc tests unfortunately don't run on CI) and bump version to 0.2 as well?

@thomaseizinger

Copy link
Copy Markdown
Contributor Author

Could you update the readme (the doc tests unfortunately don't run on CI) and bump version to 0.2 as well?

  • Bumped version
  • Updated README
  • Added step to CI to run doc-tests on nightly (can drop that commit if you don't like it!)

@ordian ordian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@ordian ordian requested a review from ascjones August 21, 2019 09:00

@ascjones ascjones left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A good improvement to the API 👍

@ordian ordian merged commit 95543ae into paritytech:master Aug 21, 2019
@ordian

ordian commented Aug 21, 2019

Copy link
Copy Markdown
Contributor

Published 0.2.0

ordian added a commit that referenced this pull request Sep 5, 2019
* master:
  [plain_hasher] Migrate to 2018 edition (#213)
  [ethbloom] Improve ethbloom (#215)
  [rlp] fix nested unbounded lists (#203)
  stabilize parity-bytes in no_std environment (#212)
  Speed up hex serialization, support Serde `with`, and fix warnings (#208)
  [ethbloom, ethereum-types,kvdb] migrate to 2018 edition (#205)
  Introduce `ContractAddress` newtype instead of scheme enum (#200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants