Skip to content

Commit

Permalink
Allow to select different networks and upgrade on startup old code to…
Browse files Browse the repository at this point in the history
… new angornet code
  • Loading branch information
dangershony committed Nov 4, 2024
1 parent 23b2408 commit 368e05a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/Angor/Client/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@
<div class="card card-body mb-3 mt-4">
<label for="networkSelection">Select Network:</label>
<select class="form-control mt-2" id="networkSelection" @bind="selectedNetwork">
<option value="testnet" selected>Angornet</option>
<option value="testnet" selected>Testnet4</option>
<option value="testnet" selected>Signet</option>
<option value="testnet" selected>Testnet</option>
<option value="mainnet">Mainnet</option>
<option value="mainnet" disabled="">Liquid</option>
</select>
</div>

Expand Down
21 changes: 20 additions & 1 deletion src/Angor/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
@inject INetworkService _networkService
@inject NavigationManager _navManager
@inject NavMenuState NavMenuState;

@inject INetworkStorage _networkStorage
@inject IClientStorage storage;

<div class="@($"{(isDarkTheme ? "dark" : "")}") sidenav-show @sidenavClass ">
<aside class="sidenav navbar navbar-vertical navbar-expand-xs border-0 border-radius-xl my-3 fixed-start ms-3 b-shadow overflow-x-hidden" id="sidenav-main">
<NavMenu ToggleSidenavCallback="ToggleSidenavMobile" ToggleSidenavTextCallback="ToggleSidenav" ToggleleLockMenuCallback="ToggleLockMenu" />
Expand Down Expand Up @@ -108,6 +110,23 @@

private void InitializeNetworkConfiguration()
{
string networkName = _networkStorage.GetNetwork();

if (networkName.ToLower() == "testnet")
{
// we will probably not support bitcoins classic testnet for a while
// so any testnet is assumed to be angornet, in an attempt to support
// backwards compatibility we just set the network to angornet
var oldName = networkName;
networkName = "Angornet";

_networkStorage.SetNetwork(networkName);
var accountInfo = storage.GetAccountInfo(oldName);
storage.SetAccountInfo(networkName, accountInfo);
storage.DeleteAccountInfo(oldName);
}

_networkService.CheckAndSetNetwork(_navManager.Uri.ToLower());

SetNetworkText();
Expand Down
1 change: 0 additions & 1 deletion src/Angor/Shared/Networks/Angornet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public Angornet()
this.Bech32Encoders = new Bech32Encoder[2];
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
this.Bech32Encoders[(int)2] = encoder; //WITNESS_SCRIPT_ADDRESS until we add taproot to blockcore

this.SeedNodes = new List<NetworkAddress>();

Expand Down
1 change: 0 additions & 1 deletion src/Angor/Shared/Networks/BitcoinSignet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public BitcoinSignet()
this.Bech32Encoders = new Bech32Encoder[2];
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
this.Bech32Encoders[(int)2] = encoder; //WITNESS_SCRIPT_ADDRESS until we add taproot to blockcore

this.StandardScriptsRegistry = new BitcoinStandardScriptsRegistry();
}
Expand Down
1 change: 0 additions & 1 deletion src/Angor/Shared/Networks/BitcoinTest4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public BitcoinTest4()
this.Bech32Encoders = new Bech32Encoder[2];
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
this.Bech32Encoders[(int)2] = encoder; //WITNESS_SCRIPT_ADDRESS until we add taproot to blockcore

this.SeedNodes = new List<NetworkAddress>();

Expand Down
11 changes: 6 additions & 5 deletions src/Angor/Shared/Services/NetworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ public NetworkService(INetworkStorage networkStorage, HttpClient httpClient, ILo
public void CheckAndSetNetwork(string url, string? setNetwork = null)
{
string networkName = _networkStorage.GetNetwork();

if (string.IsNullOrEmpty(networkName))
{
Network network = null;

if (setNetwork != null)
{
network = setNetwork.Contains("test") ? new BitcoinTest() : new BitcoinMain();
network = setNetwork.Contains("test") ? new Angornet() : new BitcoinMain();

} else if (url.Contains("test"))
{
network = new BitcoinTest();
network = new Angornet();
}
else if (url.Contains("localhost"))
{
network = new BitcoinTest();
network = new Angornet();
}
else
{
Expand All @@ -59,9 +60,9 @@ public void CheckAndSetNetwork(string url, string? setNetwork = null)
_networkConfiguration.SetNetwork(new BitcoinMain());
}

if (networkName == NetworkType.Testnet.ToString())
if (networkName == "Angornet")
{
_networkConfiguration.SetNetwork(new BitcoinTest());
_networkConfiguration.SetNetwork(new Angornet());
}
}
}
Expand Down

0 comments on commit 368e05a

Please sign in to comment.