Open IronGauntlets opened 1 year ago
I'd like to work on this
I've broken this PR into three sub-PRs:
Love the idea of merging feeder
and gateway
.
Therefore we need to introduce a Feeder interface which is used by both the rpc package and the StarknetData package.
Why not add an AddTransaction
method to the StarknetData interface and use StarknetData in rpc
? cc @rianhughes @IronGauntlets
The
clients/feeder
andclients/gateway
packages belong to theFrameworks & Drivers
layer of clean architecture, therefore any layer inside ofFrameworks & Drivers
can only useclients/feeder
andclients/gateway
through an interface. This is known as The Dependency Inversion Rule, the overarching principle of clean architecture.Defining an interface to access an outer layer has the benefit of having multiple concrete implementations which are accessed through a single interface. This helps with minimising sweeping changes across the codebase when a breaking change is introduced. However, the Dependency Inversion rule can introduce unnecessary complexity early on in the project, as declaring an interface for a single concrete implementation doesn't always make sense.
At the beginning of the project, we declared
StarknetData
as an interface used to fetch Starknet's data which could be implemented by either the feeder gateway or the p2p layer (Interface Adapter layer).To add different transactions we introduced a gateway package, accessed through a
Gateway
interface in therpc
package, however, we still use the feeder package directly in the starknet data package andrpc
package which violates the dependency inversion rule. Therefore we need to introduce a Feeder interface which is used by both therpc
package and theStarknetData
package.feeder
andgateway
are under the same parentclient
package where each package creates its ownclient
with the only difference ofpost
andget
methods. As @omerfirmak suggested we should merge these packages together to have a singleclient
with both apost
andget
methods. This client is then composed intofeeder
andgateway
structs (which are responsible for building the query URL for fetching Starknet data from the sequencer). Another benefit of merging these packages together is that they share the same types, therefore, merging them would reduce duplication.Crossing layers in the clean architecture requires adapter functions: input from
rpc
to core types should have its own adapter and input fromfeeder
andgateway
also should have their own adapters to core types (and vice versa). However, due to the commonality between all of the adapters and to reduce duplication, we createdfeeder2core
. These functions can be moved to theutils
package with a more generic name.Also, the
feeder
,gateway
andrpc
packages have very similar types (namelyTransaction
andTransactionReceipts
nested types) all of whom can also be moved to theutils
to reduce duplication.In summary, this issue has the following parts:
clients/feeder
andclients/gateway
packages into theclients
packageClient
struct (with privatepost
andget
) would implement theFeeder
(needs to be defined) andGateway
(needs to be moved fromrpc
package to theclients
package) interface.feeder2core
adapter by renaming it and moving it to theutils
package.feeder
package andrpc
package to theutils
package to reduce duplication.