mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
Merge remote-tracking branch 'origin/mweb' into mweb
This commit is contained in:
commit
729df419c0
15 changed files with 117 additions and 75 deletions
11
.github/workflows/pr_test_build_android.yml
vendored
11
.github/workflows/pr_test_build_android.yml
vendored
|
@ -110,15 +110,8 @@ jobs:
|
|||
export PATH=$PATH:/usr/local/go/bin
|
||||
export PATH=$PATH:~/go/bin
|
||||
# build mwebd:
|
||||
cd /opt/android/cake_wallet
|
||||
git clone https://github.com/ltcmweb/mwebd
|
||||
cd /opt/android/cake_wallet/mwebd
|
||||
git reset --hard f6ea8a9e3d348b01bb44f03a1cc4ad65b0abe935
|
||||
gomobile bind -target=android -androidapi 21 .
|
||||
mkdir -p /opt/android/cake_wallet/cw_mweb/android/libs/
|
||||
mv ./mwebd.aar $_
|
||||
cd ..
|
||||
rm -rf mwebd
|
||||
cd /opt/android/cake_wallet/scripts/android/
|
||||
./build_mwebd.sh
|
||||
|
||||
- name: Generate KeyStore
|
||||
run: |
|
||||
|
|
11
.github/workflows/pr_test_build_linux.yml
vendored
11
.github/workflows/pr_test_build_linux.yml
vendored
|
@ -105,15 +105,8 @@ jobs:
|
|||
export PATH=$PATH:/usr/local/go/bin
|
||||
export PATH=$PATH:~/go/bin
|
||||
# build mwebd:
|
||||
cd /opt/android/cake_wallet
|
||||
git clone https://github.com/ltcmweb/mwebd
|
||||
cd /opt/android/cake_wallet/mwebd
|
||||
git reset --hard f6ea8a9e3d348b01bb44f03a1cc4ad65b0abe935
|
||||
gomobile bind -target=android -androidapi 21 .
|
||||
mkdir -p /opt/android/cake_wallet/cw_mweb/android/libs/
|
||||
mv ./mwebd.aar $_
|
||||
cd ..
|
||||
rm -rf mwebd
|
||||
cd /opt/android/cake_wallet/scripts/android/
|
||||
./build_mwebd.sh
|
||||
|
||||
- name: Generate localization
|
||||
run: |
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:cw_core/sec_random_native.dart';
|
|||
import 'package:cw_core/utils/text_normalizer.dart';
|
||||
|
||||
const segwit = '100';
|
||||
const mweb = 'eb';
|
||||
final wordlist = englishWordlist;
|
||||
|
||||
double logBase(num x, num base) => log(x) / log(base);
|
||||
|
@ -125,7 +126,7 @@ Future<Uint8List> mnemonicToSeedBytes(String mnemonic,
|
|||
return Uint8List.fromList(bytes);
|
||||
}
|
||||
|
||||
bool matchesAnyPrefix(String mnemonic) => prefixMatches(mnemonic, [segwit]).any((el) => el);
|
||||
bool matchesAnyPrefix(String mnemonic) => prefixMatches(mnemonic, [segwit, mweb]).any((el) => el);
|
||||
|
||||
bool validateMnemonic(String mnemonic, {String prefix = segwit}) {
|
||||
try {
|
||||
|
|
|
@ -1689,12 +1689,15 @@ abstract class ElectrumWalletBase
|
|||
final Map<String, ElectrumTransactionInfo> historiesWithDetails = {};
|
||||
|
||||
if (type == WalletType.bitcoin) {
|
||||
await Future.wait(ADDRESS_TYPES
|
||||
await Future.wait(BITCOIN_ADDRESS_TYPES
|
||||
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
|
||||
} else if (type == WalletType.bitcoinCash) {
|
||||
await Future.wait(BITCOIN_CASH_ADDRESS_TYPES
|
||||
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
|
||||
await fetchTransactionsForAddressType(historiesWithDetails, P2pkhAddressType.p2pkh);
|
||||
} else if (type == WalletType.litecoin) {
|
||||
await fetchTransactionsForAddressType(historiesWithDetails, SegwitAddresType.p2wpkh);
|
||||
await Future.wait(LITECOIN_ADDRESS_TYPES
|
||||
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
|
||||
}
|
||||
|
||||
transactionHistory.transactions.values.forEach((tx) async {
|
||||
|
|
|
@ -11,15 +11,23 @@ part 'electrum_wallet_addresses.g.dart';
|
|||
|
||||
class ElectrumWalletAddresses = ElectrumWalletAddressesBase with _$ElectrumWalletAddresses;
|
||||
|
||||
const List<BitcoinAddressType> ADDRESS_TYPES = [
|
||||
const List<BitcoinAddressType> BITCOIN_ADDRESS_TYPES = [
|
||||
SegwitAddresType.p2wpkh,
|
||||
P2pkhAddressType.p2pkh,
|
||||
SegwitAddresType.p2tr,
|
||||
SegwitAddresType.p2wsh,
|
||||
SegwitAddresType.mweb,
|
||||
P2shAddressType.p2wpkhInP2sh,
|
||||
];
|
||||
|
||||
const List<BitcoinAddressType> LITECOIN_ADDRESS_TYPES = [
|
||||
SegwitAddresType.p2wpkh,
|
||||
SegwitAddresType.mweb,
|
||||
];
|
||||
|
||||
const List<BitcoinAddressType> BITCOIN_CASH_ADDRESS_TYPES = [
|
||||
P2pkhAddressType.p2pkh,
|
||||
];
|
||||
|
||||
abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
||||
ElectrumWalletAddressesBase(
|
||||
WalletInfo walletInfo, {
|
||||
|
@ -327,13 +335,6 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}) =>
|
||||
'';
|
||||
|
||||
Future<String> getAddressAsync({
|
||||
required int index,
|
||||
required Bip32Slip10Secp256k1 hd,
|
||||
BitcoinAddressType? addressType,
|
||||
}) async =>
|
||||
getAddress(index: index, hd: hd, addressType: addressType);
|
||||
|
||||
void addBitcoinAddressTypes() {
|
||||
final lastP2wpkh = _addresses
|
||||
.where((addressRecord) =>
|
||||
|
@ -393,22 +394,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateAddressesInBox() async {
|
||||
try {
|
||||
addressesMap.clear();
|
||||
addressesMap[address] = 'Active';
|
||||
|
||||
allAddressesMap.clear();
|
||||
_addresses.forEach((addressRecord) {
|
||||
allAddressesMap[addressRecord.address] = addressRecord.name;
|
||||
});
|
||||
|
||||
if (walletInfo.type == WalletType.bitcoin) {
|
||||
addBitcoinAddressTypes();
|
||||
}
|
||||
|
||||
if (walletInfo.type == WalletType.litecoin) {
|
||||
void addLitecoinAddressTypes() {
|
||||
final lastP2wpkh = _addresses
|
||||
.where((addressRecord) =>
|
||||
_isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wpkh))
|
||||
|
@ -429,6 +415,41 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}
|
||||
}
|
||||
|
||||
void addBitcoinCashAddressTypes() {
|
||||
final lastP2pkh = _addresses.firstWhere(
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, P2pkhAddressType.p2pkh));
|
||||
if (lastP2pkh.address != address) {
|
||||
addressesMap[lastP2pkh.address] = 'P2PKH';
|
||||
} else {
|
||||
addressesMap[address] = 'Active - P2PKH';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateAddressesInBox() async {
|
||||
try {
|
||||
addressesMap.clear();
|
||||
addressesMap[address] = 'Active';
|
||||
|
||||
allAddressesMap.clear();
|
||||
_addresses.forEach((addressRecord) {
|
||||
allAddressesMap[addressRecord.address] = addressRecord.name;
|
||||
});
|
||||
|
||||
switch (walletInfo.type) {
|
||||
case WalletType.bitcoin:
|
||||
addBitcoinAddressTypes();
|
||||
break;
|
||||
case WalletType.litecoin:
|
||||
addLitecoinAddressTypes();
|
||||
break;
|
||||
case WalletType.bitcoinCash:
|
||||
addBitcoinCashAddressTypes();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
await saveAddressesInBox();
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
|
@ -548,7 +569,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
|
||||
for (var i = startIndex; i < count + startIndex; i++) {
|
||||
final address = BitcoinAddressRecord(
|
||||
await getAddressAsync(index: i, hd: _getHd(isHidden), addressType: type ?? addressPageType),
|
||||
getAddress(index: i, hd: _getHd(isHidden), addressType: type ?? addressPageType),
|
||||
index: i,
|
||||
isHidden: isHidden,
|
||||
type: type ?? addressPageType,
|
||||
|
|
|
@ -317,11 +317,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
final oldBoxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
|
||||
final newBoxName = "${newWalletName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
|
||||
|
||||
final oldBox = await Hive.openBox<MwebUtxo>(oldBoxName);
|
||||
final oldBox = await CakeHive.openBox<MwebUtxo>(oldBoxName);
|
||||
mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
|
||||
for (final key in oldBox.keys) {
|
||||
await mwebUtxosBox.put(key, oldBox.get(key)!);
|
||||
}
|
||||
oldBox.deleteFromDisk();
|
||||
|
||||
await super.renameWalletFiles(newWalletName);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import 'dart:io';
|
||||
import 'package:cw_bitcoin/bitcoin_mnemonics_bip39.dart';
|
||||
import 'package:cw_bitcoin/mnemonic_is_incorrect_exception.dart';
|
||||
import 'package:cw_core/encryption_file_utils.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||
import 'package:cw_bitcoin/mnemonic_is_incorrect_exception.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||
import 'package:cw_bitcoin/litecoin_wallet.dart';
|
||||
import 'package:cw_core/wallet_service.dart';
|
||||
|
@ -150,9 +150,9 @@ class LitecoinWalletService extends WalletService<
|
|||
@override
|
||||
Future<LitecoinWallet> restoreFromSeed(BitcoinRestoreWalletFromSeedCredentials credentials,
|
||||
{bool? isTestnet}) async {
|
||||
// if (!validateMnemonic(credentials.mnemonic) && !bip39.validateMnemonic(credentials.mnemonic)) {
|
||||
// throw LitecoinMnemonicIsIncorrectException();
|
||||
// }
|
||||
if (!validateMnemonic(credentials.mnemonic) && !bip39.validateMnemonic(credentials.mnemonic)) {
|
||||
throw LitecoinMnemonicIsIncorrectException();
|
||||
}
|
||||
|
||||
final wallet = await LitecoinWalletBase.create(
|
||||
password: credentials.password!,
|
||||
|
|
|
@ -267,6 +267,11 @@ const bitcoinDates = {
|
|||
"2023-01": 769810,
|
||||
};
|
||||
|
||||
|
||||
const Map<String, int> litecoinDates = {
|
||||
// TODO: add litecoin dates
|
||||
};
|
||||
|
||||
int getBitcoinHeightByDate({required DateTime date}) {
|
||||
String dateKey = '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
||||
final closestKey = bitcoinDates.keys
|
||||
|
@ -300,6 +305,21 @@ DateTime getDateByBitcoinHeight(int height) {
|
|||
return estimatedDate;
|
||||
}
|
||||
|
||||
int getLitecoinHeightByDate({required DateTime date}) {
|
||||
String dateKey = '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
||||
final closestKey = litecoinDates.keys
|
||||
.firstWhere((key) => formatMapKey(key).isBefore(date), orElse: () => litecoinDates.keys.last);
|
||||
final beginningBlock = litecoinDates[dateKey] ?? litecoinDates[closestKey]!;
|
||||
|
||||
final startOfMonth = DateTime(date.year, date.month);
|
||||
final daysDifference = date.difference(startOfMonth).inDays;
|
||||
|
||||
// approximately 6 blocks per hour, 24 hours per day
|
||||
int estimatedBlocksSinceStartOfMonth = (daysDifference * 24 * 6);
|
||||
|
||||
return beginningBlock + estimatedBlocksSinceStartOfMonth;
|
||||
}
|
||||
|
||||
// TODO: enhance all of this global const lists
|
||||
const wowDates = {
|
||||
"2023-12": 583048,
|
||||
|
|
|
@ -529,6 +529,9 @@ class CWBitcoin extends Bitcoin {
|
|||
@override
|
||||
int getHeightByDate({required DateTime date}) => getBitcoinHeightByDate(date: date);
|
||||
|
||||
@override
|
||||
int getLitecoinHeightByDate({required DateTime date}) => getLitecoinHeightByDate(date: date);
|
||||
|
||||
@override
|
||||
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan}) async {
|
||||
final bitcoinWallet = wallet as ElectrumWallet;
|
||||
|
|
|
@ -168,8 +168,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
|||
if (date != null) {
|
||||
int height;
|
||||
if (widget.isMwebScan) {
|
||||
throw UnimplementedError();
|
||||
// height = bitcoin!.getMwebHeightByDate(date: date);
|
||||
height = bitcoin!.getLitecoinHeightByDate(date: date);
|
||||
} else if (widget.isSilentPaymentsScan) {
|
||||
height = bitcoin!.getHeightByDate(date: date);
|
||||
} else {
|
||||
|
|
|
@ -10,6 +10,7 @@ DIR=$(dirname "$0")
|
|||
case $APP_ANDROID_TYPE in
|
||||
"monero.com") $DIR/build_monero_all.sh ;;
|
||||
"cakewallet") $DIR/build_monero_all.sh
|
||||
$DIR/build_haven_all.sh ;;
|
||||
$DIR/build_haven_all.sh
|
||||
$DIR/build_mwebd.sh ;;
|
||||
"haven") $DIR/build_haven_all.sh ;;
|
||||
esac
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
if [[ "$1" == "--install" ]]; then
|
||||
# install go > 1.23:
|
||||
wget https://go.dev/dl/go1.23.1.linux-amd64.tar.gz
|
||||
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.23.1.linux-amd64.tar.gz
|
||||
|
@ -5,6 +6,8 @@ export PATH=$PATH:/usr/local/go/bin
|
|||
export PATH=$PATH:~/go/bin
|
||||
go install golang.org/x/mobile/cmd/gomobile@latest
|
||||
gomobile init
|
||||
fi
|
||||
|
||||
# build mwebd:
|
||||
git clone https://github.com/ltcmweb/mwebd
|
||||
cd mwebd
|
||||
|
|
|
@ -9,6 +9,6 @@ DIR=$(dirname "$0")
|
|||
|
||||
case $APP_IOS_TYPE in
|
||||
"monero.com") $DIR/build_monero_all.sh ;;
|
||||
"cakewallet") $DIR/build_monero_all.sh && $DIR/build_haven.sh ;;
|
||||
"cakewallet") $DIR/build_monero_all.sh && $DIR/build_haven.sh && $DIR/build_mwebd.sh ;;
|
||||
"haven") $DIR/build_haven_all.sh ;;
|
||||
esac
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#!/bin/bash
|
||||
if [[ "$1" == "--install" ]]; then
|
||||
# install go > 1.23:
|
||||
brew install go
|
||||
export PATH=$PATH:~/go/bin
|
||||
go install golang.org/x/mobile/cmd/gomobile@latest
|
||||
gomobile init
|
||||
fi
|
||||
|
||||
# build mwebd:
|
||||
git clone https://github.com/ltcmweb/mwebd
|
||||
cd mwebd
|
||||
|
|
|
@ -214,6 +214,7 @@ abstract class Bitcoin {
|
|||
{int? outputsCount, int? size});
|
||||
int feeAmountWithFeeRate(Object wallet, int feeRate, int inputsCount, int outputsCount, {int? size});
|
||||
int getHeightByDate({required DateTime date});
|
||||
int getLitecoinHeightByDate({required DateTime date});
|
||||
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan});
|
||||
Future<bool> getNodeIsElectrsSPEnabled(Object wallet);
|
||||
void deleteSilentPaymentAddress(Object wallet, String address);
|
||||
|
|
Loading…
Reference in a new issue