dgarage / NBXplorer

NBitcoin Explorer
MIT License
320 stars 210 forks source link

Mixing NBitcoin.Litecoin and NBXplorer.Client in one project #31

Closed bazooka70 closed 6 years ago

bazooka70 commented 6 years ago

There seems to be a problem mixing the two together.

If I install the package NBitcoin.Litecoin (or other alt coin created in similar matter) and NBXplorer.Client, and use:

NBitcoin.Litecoin.Networks.EnsureRegistered();
var network_ltc = NBitcoin.Litecoin.Networks.Mainnet;
....
var xnetwork_ltc = new NBXplorerNetworkProvider(ChainType.Main).GetLTC(); // <- exception

The line new NBXplorerNetworkProvider(ChainType.Main).GetLTC(); throws an exception:

System.InvalidOperationException: 'The network ltc-main is already registered'

This could be resolved by using only NBXplorer.Client in the project, e.g.

var xnetwork_ltc = new NBXplorerNetworkProvider(ChainType.Main).GetLTC();
var network_ltc = xnetwork_ltc.NBitcoinNetwork;

I wonder if this is by design?

NicolasDorier commented 6 years ago

stack trace?

bazooka70 commented 6 years ago
Exception thrown: 'System.InvalidOperationException' in mscorlib.dll
***********************************
   at NBitcoin.Network.Register(NetworkBuilder builder)
   at NBitcoin.NetworkBuilder.BuildAndRegister()
   at NBXplorer.Altcoins.Litecoin.Networks.RegisterLazy()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at NBXplorer.Altcoins.Litecoin.Networks.<>c.<EnsureRegistered>b__3_0(Lazy`1 o)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at NBXplorer.Altcoins.Litecoin.Networks.EnsureRegistered()
   at NBXplorer.NBXplorerNetworkProvider.InitLitecoin(ChainType chainType)
   at NBXplorer.NBXplorerNetworkProvider..ctor(ChainType chainType)
   at BCH.Program.Main(String[] args)
NicolasDorier commented 6 years ago

Yes indeed they should not be used together...

I think I should do a separate package with all altcoins instead of duplicating the code in NBXplorer.Client.

NicolasDorier commented 6 years ago

I am closing this, I moved all altcoin related projects on https://github.com/MetacoSA/NBitcoin/tree/master/NBitcoin.Altcoins so you should use this now.

bazooka70 commented 6 years ago

OK, thanks. so the problem I described is fixed now? (mixing NBXplorer.Client with other NBitcoin alt coins)

NicolasDorier commented 6 years ago

Yes, fixed once you update the packages