mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +00:00
decred: Enable mainnet.
This commit is contained in:
parent
fa8881f438
commit
484ba6b282
3 changed files with 45 additions and 14 deletions
|
@ -31,11 +31,13 @@ Future<void> createWalletAsync(
|
|||
{required String name,
|
||||
required String dataDir,
|
||||
required String password,
|
||||
required String network,
|
||||
String? mnemonic}) {
|
||||
final args = <String, String>{
|
||||
"name": name,
|
||||
"dataDir": dataDir,
|
||||
"password": password,
|
||||
"network": network,
|
||||
"mnemonic": mnemonic ?? "",
|
||||
};
|
||||
return compute(createWalletSync, args);
|
||||
|
@ -48,7 +50,7 @@ void createWalletSync(Map<String, String> args) {
|
|||
final dataDir = args["dataDir"]!.toCString();
|
||||
final password = args["password"]!.toCString();
|
||||
final mnemonic = args["mnemonic"]!.toCString();
|
||||
final network = "testnet".toCString();
|
||||
final network = args["network"]!.toCString();
|
||||
|
||||
executePayloadFn(
|
||||
fn: () =>
|
||||
|
@ -57,11 +59,12 @@ void createWalletSync(Map<String, String> args) {
|
|||
);
|
||||
}
|
||||
|
||||
void createWatchOnlyWallet(String walletName, String datadir, String pubkey) {
|
||||
void createWatchOnlyWallet(
|
||||
String walletName, String datadir, String pubkey, String network) {
|
||||
final cName = walletName.toCString();
|
||||
final cDataDir = datadir.toCString();
|
||||
final cPub = pubkey.toCString();
|
||||
final cNet = "testnet".toCString();
|
||||
final cNet = network.toCString();
|
||||
executePayloadFn(
|
||||
fn: () => dcrwalletApi.createWatchOnlyWallet(cName, cDataDir, cNet, cPub),
|
||||
ptrsToFree: [cName, cDataDir, cNet, cPub],
|
||||
|
@ -69,10 +72,12 @@ void createWatchOnlyWallet(String walletName, String datadir, String pubkey) {
|
|||
}
|
||||
|
||||
/// loadWalletAsync calls the libdcrwallet's loadWallet function asynchronously.
|
||||
Future<void> loadWalletAsync({required String name, required String dataDir}) {
|
||||
Future<void> loadWalletAsync(
|
||||
{required String name, required String dataDir, required String net}) {
|
||||
final args = <String, String>{
|
||||
"name": name,
|
||||
"dataDir": dataDir,
|
||||
"network": net,
|
||||
};
|
||||
return compute(loadWalletSync, args);
|
||||
}
|
||||
|
@ -81,7 +86,7 @@ Future<void> loadWalletAsync({required String name, required String dataDir}) {
|
|||
void loadWalletSync(Map<String, String> args) {
|
||||
final name = args["name"]!.toCString();
|
||||
final dataDir = args["dataDir"]!.toCString();
|
||||
final network = "testnet".toCString();
|
||||
final network = args["network"]!.toCString();
|
||||
executePayloadFn(
|
||||
fn: () => dcrwalletApi.loadWallet(name, dataDir, network),
|
||||
ptrsToFree: [name, dataDir, network],
|
||||
|
|
|
@ -38,8 +38,10 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
: _password = password,
|
||||
this.syncStatus = NotConnectedSyncStatus(),
|
||||
this.unspentCoinsInfo = unspentCoinsInfo,
|
||||
this.watchingOnly =
|
||||
walletInfo.derivationPath == DecredWalletService.pubkeyRestorePath,
|
||||
this.watchingOnly = walletInfo.derivationPath ==
|
||||
DecredWalletService.pubkeyRestorePath ||
|
||||
walletInfo.derivationPath ==
|
||||
DecredWalletService.pubkeyRestorePathTestnet,
|
||||
this.balance =
|
||||
ObservableMap.of({CryptoCurrency.dcr: DecredBalance.zero()}),
|
||||
super(walletInfo) {
|
||||
|
@ -209,9 +211,16 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
}
|
||||
persistantPeer = addr;
|
||||
libdcrwallet.closeWallet(walletInfo.name);
|
||||
final network = walletInfo.derivationPath ==
|
||||
DecredWalletService.seedRestorePathTestnet ||
|
||||
walletInfo.derivationPath ==
|
||||
DecredWalletService.pubkeyRestorePathTestnet
|
||||
? "testnet"
|
||||
: "mainnet";
|
||||
libdcrwallet.loadWalletSync({
|
||||
"name": walletInfo.name,
|
||||
"dataDir": walletInfo.dirPath,
|
||||
"network": network,
|
||||
});
|
||||
}
|
||||
await this._startSync();
|
||||
|
|
|
@ -21,7 +21,11 @@ class DecredWalletService extends WalletService<
|
|||
final Box<WalletInfo> walletInfoSource;
|
||||
final Box<UnspentCoinsInfo> unspentCoinsInfoSource;
|
||||
final seedRestorePath = "m/44'/42'";
|
||||
static final seedRestorePathTestnet = "m/44'/1'";
|
||||
static final pubkeyRestorePath = "m/44'/42'/0'";
|
||||
static final pubkeyRestorePathTestnet = "m/44'/1'/0'";
|
||||
final mainnet = "mainnet";
|
||||
final testnet = "testnet";
|
||||
|
||||
static void init() async {
|
||||
// Use the general path for all dcr wallets as the general log directory.
|
||||
|
@ -44,8 +48,10 @@ class DecredWalletService extends WalletService<
|
|||
name: credentials.walletInfo!.name,
|
||||
dataDir: credentials.walletInfo!.dirPath,
|
||||
password: credentials.password!,
|
||||
network: isTestnet == true ? testnet : mainnet,
|
||||
);
|
||||
credentials.walletInfo!.derivationPath = seedRestorePath;
|
||||
credentials.walletInfo!.derivationPath =
|
||||
isTestnet == true ? seedRestorePathTestnet : seedRestorePath;
|
||||
final wallet = DecredWallet(credentials.walletInfo!, credentials.password!,
|
||||
this.unspentCoinsInfoSource);
|
||||
await wallet.init();
|
||||
|
@ -56,9 +62,14 @@ class DecredWalletService extends WalletService<
|
|||
Future<DecredWallet> openWallet(String name, String password) async {
|
||||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||
(info) => info.id == WalletBase.idFor(name, getType()))!;
|
||||
final network = walletInfo.derivationPath == seedRestorePathTestnet ||
|
||||
walletInfo.derivationPath == pubkeyRestorePathTestnet
|
||||
? testnet
|
||||
: mainnet;
|
||||
await loadWalletAsync(
|
||||
name: walletInfo.name,
|
||||
dataDir: walletInfo.dirPath,
|
||||
net: network,
|
||||
);
|
||||
final wallet =
|
||||
DecredWallet(walletInfo, password, this.unspentCoinsInfoSource);
|
||||
|
@ -80,6 +91,11 @@ class DecredWalletService extends WalletService<
|
|||
String currentName, String password, String newName) async {
|
||||
final currentWalletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||
(info) => info.id == WalletBase.idFor(currentName, getType()))!;
|
||||
final network =
|
||||
currentWalletInfo.derivationPath == seedRestorePathTestnet ||
|
||||
currentWalletInfo.derivationPath == pubkeyRestorePathTestnet
|
||||
? testnet
|
||||
: mainnet;
|
||||
final currentWallet =
|
||||
DecredWallet(currentWalletInfo, password, this.unspentCoinsInfoSource);
|
||||
|
||||
|
@ -99,12 +115,13 @@ class DecredWalletService extends WalletService<
|
|||
DecredRestoreWalletFromSeedCredentials credentials,
|
||||
{bool? isTestnet}) async {
|
||||
await createWalletAsync(
|
||||
name: credentials.walletInfo!.name,
|
||||
dataDir: credentials.walletInfo!.dirPath,
|
||||
password: credentials.password!,
|
||||
mnemonic: credentials.mnemonic,
|
||||
);
|
||||
credentials.walletInfo!.derivationPath = seedRestorePath;
|
||||
name: credentials.walletInfo!.name,
|
||||
dataDir: credentials.walletInfo!.dirPath,
|
||||
password: credentials.password!,
|
||||
mnemonic: credentials.mnemonic,
|
||||
network: isTestnet == true ? testnet : mainnet);
|
||||
credentials.walletInfo!.derivationPath =
|
||||
isTestnet == true ? seedRestorePathTestnet : seedRestorePath;
|
||||
final wallet = DecredWallet(credentials.walletInfo!, credentials.password!,
|
||||
this.unspentCoinsInfoSource);
|
||||
await wallet.init();
|
||||
|
|
Loading…
Reference in a new issue