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

Providing easy access to Hedera network with vendor neutral SDKs #98

Open
hendrikebbers opened this issue Feb 3, 2025 · 0 comments
Open
Assignees

Comments

@hendrikebbers
Copy link
Member

Today all our SDKs have methods like connectToMainnet() or connectToTestnet() since the code is in that part made for Hedera. Happily all the SDKs provide a way how any Hiero based network is supported. This way today needs knowledge about technical information of the network (IPs, hosts, ...) and will end in a lot of code that need to be created to connect to a Hedera specific network.

Based on that we need to refactor our SDK to provide an easy way to support the configuration of specific networks (like Hedera Mainnet) in an easy way without being releated to a specific provider. Here I would suggest, that an SDK under Hiero can contain information for any public and open network operated by companies / entities being part of the Hiero project / the LFDT.

A possible solution

I did some tests in Java (see OpenElements/hiero-enterprise-java#148) and a SPI based approach in Java looks like the best solution:

I created an interface that provided all information that is needed by a network

public interface NetworkSettings {

     /**
      * Returns the network identifier.
      *
      * @return the network identifier
      */
     @NonNull
     String getNetworkIdentifier();

     /**
      * Returns the network name.
      *
      * @return the network name
      */
     @NonNull
     Optional<String> getNetworkName();

     /**
      * Returns the mirror node addresses.
      *
      * @return the mirror node addresses
      */
     @NonNull
     Set<String> getMirrorNodeAddresses();

     /**
      * Returns the consensus nodes.
      *
      * @return the consensus nodes
      */
     @NonNull
     Set<ConsensusNode> getConsensusNodes();

     ...
 }

For the Hedera networks (Mainnet, testnet) I now created concrete implementations that are handled as private API:

public final class HederMainnetSettings implements NetworkSettings {

     public static final String NETWORK_IDENTIFIER = "hedera-mainnet";

     @Override
     public @NonNull String getNetworkIdentifier() {
         return NETWORK_IDENTIFIER;
     }

     @Override
     public @NonNull Optional<String> getNetworkName() {
         return Optional.of("Hedera Mainnet");
     }

     @Override
     public @NonNull Set<String> getMirrorNodeAddresses() {
         return Set.of("https://mainnet.mirrornode.hedera.com:443");
     }

     @Override
     public @NonNull Set<ConsensusNode> getConsensusNodes() {
         return Set.of(new ConsensusNode("35.186.191.247", "50211", "0.0.4"));
     }

...
 }

By using the SPI we can now easy write code like this:

NetworkSettings settings = NetworkSettings.getFor("hedera-mainnet");

If a NetworkSettings implementation with the given identifier is found on the classpath it will be used.

Even provider of a private network could use that approach by adding a custom NetworkSettings implementation at runtime to the classpath.

Other languages

Language Solution
JavaScript/TypeScript Dynamic import(), Dependency Injection (Inversify)
Go Plugins (plugin package), Interface-based factory
Rust libloading crate, Trait-based factory
C++ dlopen/dlsym or LoadLibrary, Factory pattern
Swift Protocol-based factory, Dynamic frameworks (@objc dynamic)
Python importlib for dynamic loading, pkg_resources entry points

Looks like we can do a silimar solution for all our SDKs

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

No branches or pull requests

2 participants