Description
openedon Sep 12, 2017
... and that's a quite big no-no, especially in JS land 😕
Consider this use case (we have a similar situation as we speak):
There is a package X using stellar-sdk
and a package Y using stellar-sdk
as well, but a slightly different version.
If Y is a dependency of X or if X and Y are both being used in another package Z then we will end up with a nasty situation. The Network
singleton that X imports from stellar-sdk
/stellar-base
won't be the same instance that Y has, since they each depend on a different version (two different stellar-base
in the node_modules/
tree).
Thus you can run Network.useTestNetwork()
in X and still get a No network selected.
error in Y. Same happens when npm link
-ing packages during development, even if all packages require the same version.
Proposal
Is there actually a need to have this stateful Network
singleton? I would favor a solution based on passing the pubnet/testnet switch to the Server
constructor, since horizon servers won't suddenly change the network they are running on.
import { Network, Server } from 'stellar-base'
const horizon = new Server('https://horizon-testnet.stellar.org/', { network: Network.testnet() })
Sorry for the wall of text 😉