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