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

Chore: public structs with initializers #594

Conversation

JeneaVranceanu
Copy link
Collaborator

@JeneaVranceanu JeneaVranceanu commented Jul 19, 2022

Added initializers to public structs that had none.
By default, structs have initializers that are usable within the project because these initializers have an internal access modifier.
That initializer is obviously inaccessible when some library is used as a dependency in a different project.

Example of initializers available in 3rd party project for EthereumParameters (default internal initializer is not visible):

Screenshot 2022-07-19 at 10 48 12

Screenshot 2022-07-19 at 10 48 19


Duplicating the answer to the question from Discord about why this is merged into develop (just for the sake of clarity).

Because that (the issue) is in develop branch and I cannot init EthereumParameters and TransactionOptions easily because inits are internal.
Previously in develop branch TransactionOptions had public init() {} and EthereumParameters wasn't even existing.
With EIP1559 that changed:

  1. No more public init() {} for TransactionOptions and no init for EthereumParameters without TransactionOptions.
  2. That was a breaking change and IMHO introduced a bug. Updating to latest version from development breaks build process.

image

This is currently the only way to initialize TransactionOptions which is a requirement for initializer of EthereumParameters.
As an alternative developers could use TransactionOptions.defaultOptions but then they have to set all values to nil in the returned TransactionOptions object that they are not intending to use in order for public func merge(_ otherOptions: TransactionOptions?) -> TransactionOptions to work as expected.

All of the changes introduced with EIP1559 work perfectly well within the boundaries of the web3swift.
The only thing that was missing are public initializers for a few structs to make it possible to initialize these structs in 3rd party projects.


public init(fromBlock: Block?, toBlock: Block?,
public init(fromBlock: Block? = nil,
toBlock: Block? = nil,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Combined two inits into one. Doesn't break anything.

@@ -11,6 +11,12 @@ public struct ICAP {
public var asset: String
public var institution: String
public var client: String

public init(asset: String, institution: String, client: String) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This struct is not used anywhere in the project so I assumed it should be used in other projects that use web3swift as a dependency. Thus, this struct must provide an initializer.

let info: DirectDebitInfo
let epoch: BigUInt
public let info: DirectDebitInfo
public let epoch: BigUInt
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related to both of the structs above: no use of having public structs with internal inaccessible variables. Marked all as public.
An initializer is not added as these structs are not to be initialized by other developers. These models are used to decode responses.

@yaroslavyaroslav yaroslavyaroslav merged commit a0c7265 into web3swift-team:develop Jul 19, 2022
@JeneaVranceanu JeneaVranceanu deleted the chore/extensions-with-initializers branch July 19, 2022 10:00
SwiftyJacek added a commit to SwiftyJacek/web3swift that referenced this pull request Aug 11, 2022
commit 31b75de
Merge: 3ec8b24 da1517d
Author: SwiftyJacek <95341310+SwiftyJacek@users.noreply.github.com>
Date:   Thu Aug 11 12:02:36 2022 +0200

    Merge branch 'skywinder:develop' into develop

commit da1517d
Merge: a0c7265 4312a71
Author: Yaroslav <yaroslav.yashin@me.com>
Date:   Wed Jul 20 19:48:46 2022 +0700

    Merge branch 'master' into develop

    Dropping all frozen dependencies.

commit 4312a71
Author: Yaroslav <yaroslav.yashin@me.com>
Date:   Tue Jul 19 18:02:28 2022 +0700

    Update cocoapods version

commit dff6562
Author: Yaroslav <yaroslav.yashin@me.com>
Date:   Tue Jul 19 18:01:55 2022 +0700

    Freeze dependencies versions

commit b8de0b6
Merge: e269630 a0c7265
Author: Yaroslav <yaroslav.yashin@me.com>
Date:   Tue Jul 19 17:27:12 2022 +0700

    Merge pull request web3swift-team#595 from skywinder/develop

    develop to master merge

commit a0c7265
Merge: ce1c62f a9461c9
Author: Yaroslav <yaroslav.yashin@me.com>
Date:   Tue Jul 19 16:58:48 2022 +0700

    Merge pull request web3swift-team#594 from JeneaVranceanu/chore/extensions-with-initializers

    Chore: public structs with initializers

commit a9461c9
Author: Jenea Vranceanu <jeneavranceanu@gmail.com>
Date:   Tue Jul 19 11:26:23 2022 +0300

    fix: added default initializer for EthereumParameters;

commit 647a0dc
Author: Jenea Vranceanu <jeneavranceanu@gmail.com>
Date:   Tue Jul 19 11:23:40 2022 +0300

    fix: added default initializer for TransactionOptions;

commit dfa34e7
Author: Jenea Vranceanu <jeneavranceanu@gmail.com>
Date:   Tue Jul 19 11:23:21 2022 +0300

    chore: DirectDebitInfo and DirectDebit fields made public - no purpose of having all fields as internal in a public model;

commit 01f3a86
Author: Jenea Vranceanu <jeneavranceanu@gmail.com>
Date:   Tue Jul 19 11:21:50 2022 +0300

    chore: ICAP initializer added;

commit 3d7caf7
Author: Jenea Vranceanu <jeneavranceanu@gmail.com>
Date:   Tue Jul 19 11:20:47 2022 +0300

    chore: EventFilter initializers combined;
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