mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 22:58:49 +00:00
Check if default Epicbox is up on start up, always update wallet address to connected Epicbox server
This commit is contained in:
parent
38c9de21f4
commit
ab3df052d4
2 changed files with 58 additions and 59 deletions
|
@ -17,7 +17,7 @@ abstract class DefaultEpicBoxes {
|
||||||
static List<String> get defaultIds => ['americas', 'asia', 'europe'];
|
static List<String> get defaultIds => ['americas', 'asia', 'europe'];
|
||||||
|
|
||||||
static EpicBoxServerModel get americas => EpicBoxServerModel(
|
static EpicBoxServerModel get americas => EpicBoxServerModel(
|
||||||
host: 'stackwallet.epicbox.com',
|
host: 'epicbox.stackwallet.com',
|
||||||
port: 443,
|
port: 443,
|
||||||
name: 'Americas',
|
name: 'Americas',
|
||||||
id: 'americas',
|
id: 'americas',
|
||||||
|
|
|
@ -104,45 +104,28 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
|
|
||||||
Future<EpicBoxConfigModel> getEpicBoxConfig() async {
|
Future<EpicBoxConfigModel> getEpicBoxConfig() async {
|
||||||
EpicBoxConfigModel? _epicBoxConfig;
|
EpicBoxConfigModel? _epicBoxConfig;
|
||||||
// read epicbox config from secure store
|
|
||||||
String? storedConfig =
|
|
||||||
await secureStorageInterface.read(key: '${walletId}_epicboxConfig');
|
|
||||||
|
|
||||||
// we should move to storing the primary server model like we do with nodes, and build the config from that (see epic-mobile)
|
//Get the default Epicbox server and check if it's conected
|
||||||
// EpicBoxServerModel? _epicBox = epicBox ??
|
bool isEpicboxConnected = await _testEpicboxServer(
|
||||||
// DB.instance.get<EpicBoxServerModel>(
|
DefaultEpicBoxes.defaultEpicBoxServer.host, DefaultEpicBoxes.defaultEpicBoxServer.port ?? 443);
|
||||||
// boxName: DB.boxNamePrimaryEpicBox, key: 'primary');
|
|
||||||
// Logging.instance.log(
|
|
||||||
// "Read primary Epic Box config: ${jsonEncode(_epicBox)}",
|
|
||||||
// level: LogLevel.Info);
|
|
||||||
|
|
||||||
if (storedConfig == null) {
|
if (isEpicboxConnected) {
|
||||||
// if no config stored, use the default epicbox server as config
|
//Use default server for as Epicbox config
|
||||||
_epicBoxConfig =
|
_epicBoxConfig =
|
||||||
EpicBoxConfigModel.fromServer(DefaultEpicBoxes.defaultEpicBoxServer);
|
EpicBoxConfigModel.fromServer(DefaultEpicBoxes.defaultEpicBoxServer);
|
||||||
} else {
|
} else {
|
||||||
// if a config is stored, test it
|
//Use Europe config
|
||||||
|
|
||||||
_epicBoxConfig = EpicBoxConfigModel.fromString(
|
|
||||||
storedConfig); // fromString handles checking old config formats
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isEpicboxConnected = await _testEpicboxServer(
|
|
||||||
_epicBoxConfig.host, _epicBoxConfig.port ?? 443);
|
|
||||||
|
|
||||||
if (!isEpicboxConnected) {
|
|
||||||
// default Epicbox is not connected, default to Europe
|
|
||||||
_epicBoxConfig = EpicBoxConfigModel.fromServer(DefaultEpicBoxes.europe);
|
_epicBoxConfig = EpicBoxConfigModel.fromServer(DefaultEpicBoxes.europe);
|
||||||
|
|
||||||
// example of selecting another random server from the default list
|
|
||||||
// alternative servers: copy list of all default EB servers but remove the default default
|
|
||||||
// List<EpicBoxServerModel> alternativeServers = DefaultEpicBoxes.all;
|
|
||||||
// alternativeServers.removeWhere((opt) => opt.name == DefaultEpicBoxes.defaultEpicBoxServer.name);
|
|
||||||
// alternativeServers.shuffle(); // randomize which server is used
|
|
||||||
// _epicBoxConfig = EpicBoxConfigModel.fromServer(alternativeServers.first);
|
|
||||||
|
|
||||||
// TODO test this connection before returning it
|
|
||||||
}
|
}
|
||||||
|
// // example of selecting another random server from the default list
|
||||||
|
// // alternative servers: copy list of all default EB servers but remove the default default
|
||||||
|
// // List<EpicBoxServerModel> alternativeServers = DefaultEpicBoxes.all;
|
||||||
|
// // alternativeServers.removeWhere((opt) => opt.name == DefaultEpicBoxes.defaultEpicBoxServer.name);
|
||||||
|
// // alternativeServers.shuffle(); // randomize which server is used
|
||||||
|
// // _epicBoxConfig = EpicBoxConfigModel.fromServer(alternativeServers.first);
|
||||||
|
//
|
||||||
|
// // TODO test this connection before returning it
|
||||||
|
// }
|
||||||
|
|
||||||
return _epicBoxConfig;
|
return _epicBoxConfig;
|
||||||
}
|
}
|
||||||
|
@ -334,36 +317,52 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
int index,
|
int index,
|
||||||
) async {
|
) async {
|
||||||
Address? address = await getCurrentReceivingAddress();
|
Address? address = await getCurrentReceivingAddress();
|
||||||
|
EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
||||||
|
|
||||||
if (address == null) {
|
if (address != null) {
|
||||||
final wallet =
|
final splitted = address.value.split('@');
|
||||||
await secureStorageInterface.read(key: '${walletId}_wallet');
|
//Check if the address is the same as the current epicbox index
|
||||||
EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
if (splitted[1] != epicboxConfig.host) {
|
||||||
|
//Update the address
|
||||||
|
address = await thisWalletAddress(index, epicboxConfig);
|
||||||
|
}
|
||||||
|
|
||||||
final walletAddress = await epiccash.LibEpiccash.getAddressInfo(
|
} else {
|
||||||
wallet: wallet!,
|
address = await thisWalletAddress(index, epicboxConfig);
|
||||||
index: index,
|
|
||||||
epicboxConfig: epicboxConfig.toString(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Logging.instance.log(
|
|
||||||
"WALLET_ADDRESS_IS $walletAddress",
|
|
||||||
level: LogLevel.Info,
|
|
||||||
);
|
|
||||||
|
|
||||||
address = Address(
|
|
||||||
walletId: walletId,
|
|
||||||
value: walletAddress,
|
|
||||||
derivationIndex: index,
|
|
||||||
derivationPath: null,
|
|
||||||
type: AddressType.mimbleWimble,
|
|
||||||
subType: AddressSubType.receiving,
|
|
||||||
publicKey: [], // ??
|
|
||||||
);
|
|
||||||
|
|
||||||
await mainDB.updateOrPutAddresses([address]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// print("NOW THIS ADDRESS IS $address");
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Address> thisWalletAddress(int index, EpicBoxConfigModel epicboxConfig) async {
|
||||||
|
final wallet =
|
||||||
|
await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
|
// EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
||||||
|
|
||||||
|
final walletAddress = await epiccash.LibEpiccash.getAddressInfo(
|
||||||
|
wallet: wallet!,
|
||||||
|
index: index,
|
||||||
|
epicboxConfig: epicboxConfig.toString(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Logging.instance.log(
|
||||||
|
"WALLET_ADDRESS_IS $walletAddress",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
|
|
||||||
|
final address = Address(
|
||||||
|
walletId: walletId,
|
||||||
|
value: walletAddress,
|
||||||
|
derivationIndex: index,
|
||||||
|
derivationPath: null,
|
||||||
|
type: AddressType.mimbleWimble,
|
||||||
|
subType: AddressSubType.receiving,
|
||||||
|
publicKey: [], // ??
|
||||||
|
);
|
||||||
|
|
||||||
|
await mainDB.updateOrPutAddresses([address]);
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue