-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code fore blockchain network management (#1691)
* [settings] remove unused `NetworkState` class * [config] introduce network enum for different networks (it is not used yet) * remove obsolete fields of endpoint data and settings store * [settingsStore] remove obsolete endpointList observable * [settingsStore] switch from EndpointData to the new Network enum * remove obsolete hardcoded encointer endpoints * [consts] rename `ipfs_gateway_local` to `ipfsGatewayLocal` * [consts] remove obsolete `faucetAmount` * fix: endpoint getters * [settings] fix: remove obsolete EndpointData class * [encointer_store_test] fix: serialization roundtrip * [LocalStorage] disambiguate between removeObject and removeKV * fmt * [settings] re-introduce default endpoint test * [config/networks] proper enum ordering and make clear that we are not referring to the relaychains * [config/networks] rename info to id * [config/networks] add comment about removing `value` * [mockData] remove obsolete `unitTestEndpointInfo` * [settings] rename misnomer `endpoint` to `currentNetwork`
- Loading branch information
Showing
31 changed files
with
247 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:encointer_wallet/config/consts.dart'; | ||
|
||
class NetworkEndpoint { | ||
NetworkEndpoint({required this.name, required this.address}); | ||
|
||
final String name; | ||
final String address; | ||
} | ||
|
||
const String gesellId = 'nctr-gsl'; | ||
const String gesellDevId = 'nctr-gsl-dev'; | ||
const String rococoId = 'nctr-r'; | ||
const String kusamaId = 'nctr-k'; | ||
|
||
/// Enum representing the different networks. | ||
/// | ||
/// NOTE: We shouldn't do `_` wildcard matching in the switch statement so that | ||
/// we get guaranteed type safety when we extend the enum variant due to the | ||
/// compiler check for exhaustive matching. | ||
enum Network { | ||
encointerKusama, | ||
encointerRococo, | ||
gesell, | ||
gesellDev; | ||
|
||
factory Network.fromInfoOrDefault(String info) { | ||
return switch (info) { | ||
kusamaId => Network.encointerKusama, | ||
rococoId => Network.encointerRococo, | ||
gesellId => Network.gesell, | ||
gesellDevId => Network.gesellDev, | ||
_ => Network.encointerKusama, | ||
}; | ||
} | ||
|
||
factory Network.tryFromInfo(String info) { | ||
return switch (info) { | ||
kusamaId => Network.encointerKusama, | ||
rococoId => Network.encointerRococo, | ||
gesellId => Network.gesell, | ||
gesellDevId => Network.gesellDev, | ||
_ => throw Exception(['Invalid network $info']), | ||
}; | ||
} | ||
|
||
String id() { | ||
return switch (this) { | ||
encointerKusama => kusamaId, | ||
encointerRococo => rococoId, | ||
gesell => gesellId, | ||
gesellDev => gesellDevId, | ||
}; | ||
} | ||
|
||
int ss58() { | ||
return switch (this) { | ||
encointerKusama => 2, | ||
encointerRococo => 42, | ||
gesell => 42, | ||
gesellDev => 42, | ||
}; | ||
} | ||
|
||
/// After #1603 is implemented, we can also replace this with multiple endpoints, | ||
/// such that we have fallback endpoints. | ||
String ipfsGateway() { | ||
return switch (this) { | ||
encointerKusama => ipfsGatewayEncointer, | ||
encointerRococo => ipfsGatewayEncointer, | ||
gesell => ipfsGatewayEncointer, | ||
// only dev network refers to the local one | ||
gesellDev => ipfsGatewayLocal, | ||
}; | ||
} | ||
|
||
/// Exists for simple reverse compatibility. | ||
/// Will be remove in the course of https://github.com/encointer/encointer-wallet-flutter/issues/1603. | ||
String value() { | ||
return switch (this) { | ||
encointerKusama => networkEndpoints().first.address, | ||
encointerRococo => networkEndpoints().first.address, | ||
gesell => networkEndpoints().first.address, | ||
// only dev network refers to the local one | ||
gesellDev => networkEndpoints().first.address, | ||
}; | ||
} | ||
|
||
List<NetworkEndpoint> networkEndpoints() { | ||
return switch (this) { | ||
encointerKusama => kusamaEndpoints(), | ||
encointerRococo => rococoEndpoints(), | ||
gesell => gesellEndpoints(), | ||
gesellDev => gesellDevEndpoints(), | ||
}; | ||
} | ||
} | ||
|
||
List<NetworkEndpoint> gesellEndpoints() { | ||
return [ | ||
NetworkEndpoint(name: 'Encointer Gesell (Hosted by Encointer Association)', address: 'wss://gesell.encointer.org') | ||
]; | ||
} | ||
|
||
List<NetworkEndpoint> gesellDevEndpoints() { | ||
return [ | ||
NetworkEndpoint( | ||
name: 'Encointer Gesell Local DevNet', | ||
address: 'ws://${Platform.isAndroid ? androidLocalHost : iosLocalHost}:9944') | ||
]; | ||
} | ||
|
||
List<NetworkEndpoint> rococoEndpoints() { | ||
return [ | ||
NetworkEndpoint( | ||
name: 'Encointer Lietaer on Rococo (Hosted by Encointer Association)', | ||
address: 'wss://rococo.api.encointer.org') | ||
]; | ||
} | ||
|
||
List<NetworkEndpoint> kusamaEndpoints() { | ||
return [ | ||
NetworkEndpoint( | ||
name: 'Encointer Network on Kusama (Hosted by Encointer Association)', | ||
address: 'wss://kusama.api.encointer.org') | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.