mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 12:54:38 +00:00
fix: api & create
This commit is contained in:
parent
c35dec0d09
commit
b7ff9ab32b
5 changed files with 64 additions and 25 deletions
|
@ -150,9 +150,17 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||||
hdWallets[CWBitcoinDerivationType.electrum]!;
|
hdWallets[CWBitcoinDerivationType.electrum]!;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
seedBytes = walletInfo.derivationInfo?.derivationType == DerivationType.electrum
|
switch (walletInfo.derivationInfo?.derivationType) {
|
||||||
? ElectrumV2SeedGenerator.generateFromString(mnemonic, passphrase)
|
case DerivationType.bip39:
|
||||||
: Bip39SeedGenerator.generateFromString(mnemonic, passphrase);
|
seedBytes = await Bip39SeedGenerator.generateFromString(mnemonic, passphrase);
|
||||||
|
hdWallets[CWBitcoinDerivationType.bip39] = Bip32Slip10Secp256k1.fromSeed(seedBytes);
|
||||||
|
break;
|
||||||
|
case DerivationType.electrum:
|
||||||
|
default:
|
||||||
|
seedBytes = await ElectrumV2SeedGenerator.generateFromString(mnemonic, passphrase);
|
||||||
|
hdWallets[CWBitcoinDerivationType.electrum] = Bip32Slip10Secp256k1.fromSeed(seedBytes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BitcoinWallet(
|
return BitcoinWallet(
|
||||||
|
|
|
@ -1308,6 +1308,11 @@ abstract class ElectrumWalletBase
|
||||||
Future<void> onHistoriesResponse(List<AddressHistoriesResponse> histories) async {
|
Future<void> onHistoriesResponse(List<AddressHistoriesResponse> histories) async {
|
||||||
if (histories.isEmpty || _updatingHistories) {
|
if (histories.isEmpty || _updatingHistories) {
|
||||||
_updatingHistories = false;
|
_updatingHistories = false;
|
||||||
|
_syncedTimes++;
|
||||||
|
if (_syncedTimes == 3) {
|
||||||
|
syncStatus = SyncedSyncStatus();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -467,7 +467,29 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
||||||
(element) => element.scriptType == addressType.toString(),
|
(element) => element.scriptType == addressType.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
for (final derivationInfo in derivationInfos ?? <DerivationInfo>[]) {
|
if (derivationInfos == null || derivationInfos.isEmpty) {
|
||||||
|
final bitcoinDerivationInfo = BitcoinDerivationInfo(
|
||||||
|
derivationType: isElectrum ? BitcoinDerivationType.electrum : BitcoinDerivationType.bip39,
|
||||||
|
derivationPath: walletInfo.derivationInfo!.derivationPath!,
|
||||||
|
scriptType: addressType,
|
||||||
|
);
|
||||||
|
|
||||||
|
await discoverNewAddresses(
|
||||||
|
derivationType: derivationType,
|
||||||
|
isChange: false,
|
||||||
|
addressType: addressType,
|
||||||
|
derivationInfo: bitcoinDerivationInfo,
|
||||||
|
);
|
||||||
|
await discoverNewAddresses(
|
||||||
|
derivationType: derivationType,
|
||||||
|
isChange: true,
|
||||||
|
addressType: addressType,
|
||||||
|
derivationInfo: bitcoinDerivationInfo,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final derivationInfo in derivationInfos) {
|
||||||
final bitcoinDerivationInfo = BitcoinDerivationInfo(
|
final bitcoinDerivationInfo = BitcoinDerivationInfo(
|
||||||
derivationType: isElectrum ? BitcoinDerivationType.electrum : BitcoinDerivationType.bip39,
|
derivationType: isElectrum ? BitcoinDerivationType.electrum : BitcoinDerivationType.bip39,
|
||||||
derivationPath: derivationInfo.derivationPath!,
|
derivationPath: derivationInfo.derivationPath!,
|
||||||
|
|
|
@ -47,6 +47,8 @@ class ElectrumWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMessage(dynamic message) async {
|
void handleMessage(dynamic message) async {
|
||||||
|
print("Worker received message: $message");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic> messageJson;
|
Map<String, dynamic> messageJson;
|
||||||
if (message is String) {
|
if (message is String) {
|
||||||
|
@ -107,7 +109,6 @@ class ElectrumWorker {
|
||||||
ElectrumWorkerStopScanningRequest.fromJson(messageJson),
|
ElectrumWorkerStopScanningRequest.fromJson(messageJson),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case ElectrumRequestMethods.estimateFeeMethod:
|
|
||||||
case ElectrumRequestMethods.tweaksSubscribeMethod:
|
case ElectrumRequestMethods.tweaksSubscribeMethod:
|
||||||
if (_isScanning) {
|
if (_isScanning) {
|
||||||
_stopScanRequested = false;
|
_stopScanRequested = false;
|
||||||
|
@ -279,12 +280,8 @@ class ElectrumWorker {
|
||||||
walletType: result.walletType,
|
walletType: result.walletType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Future.value(null);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return histories;
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
_sendResponse(ElectrumWorkerGetHistoryResponse(
|
_sendResponse(ElectrumWorkerGetHistoryResponse(
|
||||||
|
@ -411,29 +408,36 @@ class ElectrumWorker {
|
||||||
if (getTime) {
|
if (getTime) {
|
||||||
if (mempoolAPIEnabled) {
|
if (mempoolAPIEnabled) {
|
||||||
try {
|
try {
|
||||||
final txVerbose = await http.get(
|
// TODO: mempool api class
|
||||||
Uri.parse(
|
final txVerbose = await http
|
||||||
"http://mempool.cakewallet.com:8999/api/v1/tx/$hash/status",
|
.get(
|
||||||
),
|
Uri.parse(
|
||||||
);
|
"https://mempool.cakewallet.com/api/v1/tx/$hash/status",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.timeout(const Duration(seconds: 5));
|
||||||
|
|
||||||
if (txVerbose.statusCode == 200 &&
|
if (txVerbose.statusCode == 200 &&
|
||||||
txVerbose.body.isNotEmpty &&
|
txVerbose.body.isNotEmpty &&
|
||||||
jsonDecode(txVerbose.body) != null) {
|
jsonDecode(txVerbose.body) != null) {
|
||||||
height = jsonDecode(txVerbose.body)['block_height'] as int;
|
height = jsonDecode(txVerbose.body)['block_height'] as int;
|
||||||
|
|
||||||
final blockHash = await http.get(
|
final blockHash = await http
|
||||||
Uri.parse(
|
.get(
|
||||||
"http://mempool.cakewallet.com:8999/api/v1/block-height/$height",
|
Uri.parse(
|
||||||
),
|
"https://mempool.cakewallet.com/api/v1/block-height/$height",
|
||||||
);
|
),
|
||||||
|
)
|
||||||
|
.timeout(const Duration(seconds: 5));
|
||||||
|
|
||||||
if (blockHash.statusCode == 200 && blockHash.body.isNotEmpty) {
|
if (blockHash.statusCode == 200 && blockHash.body.isNotEmpty) {
|
||||||
final blockResponse = await http.get(
|
final blockResponse = await http
|
||||||
Uri.parse(
|
.get(
|
||||||
"http://mempool.cakewallet.com:8999/api/v1/block/${blockHash.body}",
|
Uri.parse(
|
||||||
),
|
"https://mempool.cakewallet.com/api/v1/block/${blockHash.body}",
|
||||||
);
|
),
|
||||||
|
)
|
||||||
|
.timeout(const Duration(seconds: 5));
|
||||||
|
|
||||||
if (blockResponse.statusCode == 200 &&
|
if (blockResponse.statusCode == 200 &&
|
||||||
blockResponse.body.isNotEmpty &&
|
blockResponse.body.isNotEmpty &&
|
||||||
|
|
|
@ -273,7 +273,7 @@ const bitcoinDates = {
|
||||||
Future<int> getBitcoinHeightByDateAPI({required DateTime date}) async {
|
Future<int> getBitcoinHeightByDateAPI({required DateTime date}) async {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"http://mempool.cakewallet.com:8999/api/v1/mining/blocks/timestamp/${(date.millisecondsSinceEpoch / 1000).round()}",
|
"https://mempool.cakewallet.com/api/v1/mining/blocks/timestamp/${(date.millisecondsSinceEpoch / 1000).round()}",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue