inital commit: testnet support, silent payments

This commit is contained in:
Rafael Saes 2023-10-06 16:54:02 -03:00
parent edbdc8e365
commit 266b43f42a
59 changed files with 838 additions and 444 deletions

View file

@ -1,15 +1,17 @@
import 'package:cw_bitcoin/bitcoin_address_record.dart';
class BitcoinUnspent {
BitcoinUnspent(this.address, this.hash, this.value, this.vout)
BitcoinUnspent(this.address, this.hash, this.value, this.vout, {bool? isSilent})
: isSending = true,
isFrozen = false,
note = '';
note = '',
isSilent = isSilent ?? false;
factory BitcoinUnspent.fromJSON(
BitcoinAddressRecord address, Map<String, dynamic> json) =>
BitcoinUnspent(address, json['tx_hash'] as String, json['value'] as int,
json['tx_pos'] as int);
factory BitcoinUnspent.fromJSON(BitcoinAddressRecord address, Map<String, dynamic> json,
{bool? isSilent}) =>
BitcoinUnspent(
address, json['tx_hash'] as String, json['value'] as int, json['tx_pos'] as int,
isSilent: isSilent);
final BitcoinAddressRecord address;
final String hash;
@ -17,8 +19,12 @@ class BitcoinUnspent {
final int vout;
bool get isP2wpkh =>
address.address.startsWith('bc') || address.address.startsWith('ltc');
address.address.startsWith('bc') ||
// testnet
address.address.startsWith('tb') ||
address.address.startsWith('ltc');
bool isSending;
bool isFrozen;
bool isSilent;
String note;
}

View file

@ -23,77 +23,86 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
required String password,
required WalletInfo walletInfo,
required Box<UnspentCoinsInfo> unspentCoinsInfo,
bitcoin.NetworkType? networkType,
required Uint8List seedBytes,
required EncryptionFileUtils encryptionFileUtils,
List<BitcoinAddressRecord>? initialAddresses,
ElectrumBalance? initialBalance,
int initialRegularAddressIndex = 0,
int initialChangeAddressIndex = 0})
int initialChangeAddressIndex = 0,
bitcoin.SilentPaymentAddress? silentAddress})
: super(
mnemonic: mnemonic,
password: password,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
networkType: bitcoin.bitcoin,
networkType: networkType ?? bitcoin.bitcoin,
initialAddresses: initialAddresses,
initialBalance: initialBalance,
seedBytes: seedBytes,
currency: CryptoCurrency.btc,
encryptionFileUtils: encryptionFileUtils) {
walletAddresses = BitcoinWalletAddresses(
walletInfo,
walletAddresses = BitcoinWalletAddresses(walletInfo,
electrumClient: electrumClient,
initialAddresses: initialAddresses,
initialRegularAddressIndex: initialRegularAddressIndex,
initialChangeAddressIndex: initialChangeAddressIndex,
mainHd: hd,
sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType)
.derivePath("m/0'/1"),
networkType: networkType);
sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath("m/0'/1"),
networkType: networkType ?? bitcoin.bitcoin,
silentAddress: silentAddress);
}
static Future<BitcoinWallet> create({
required String mnemonic,
static Future<BitcoinWallet> create(
{required String mnemonic,
required String password,
required WalletInfo walletInfo,
required Box<UnspentCoinsInfo> unspentCoinsInfo,
bitcoin.NetworkType? networkType,
required EncryptionFileUtils encryptionFileUtils,
List<BitcoinAddressRecord>? initialAddresses,
ElectrumBalance? initialBalance,
int initialRegularAddressIndex = 0,
int initialChangeAddressIndex = 0
}) async {
int initialChangeAddressIndex = 0}) async {
return BitcoinWallet(
mnemonic: mnemonic,
password: password,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
networkType: networkType,
initialAddresses: initialAddresses,
initialBalance: initialBalance,
encryptionFileUtils: encryptionFileUtils,
seedBytes: await mnemonicToSeedBytes(mnemonic),
initialRegularAddressIndex: initialRegularAddressIndex,
initialChangeAddressIndex: initialChangeAddressIndex);
initialChangeAddressIndex: initialChangeAddressIndex,
silentAddress: await bitcoin.SilentPaymentAddress.fromMnemonic(mnemonic,
hrp: networkType == bitcoin.bitcoin ? 'sp' : 'tsp'));
}
static Future<BitcoinWallet> open({
required String name,
static Future<BitcoinWallet> open(
{required String name,
required WalletInfo walletInfo,
required Box<UnspentCoinsInfo> unspentCoinsInfo,
required String password,
required EncryptionFileUtils encryptionFileUtils
}) async {
final snp = await ElectrumWallletSnapshot.load(encryptionFileUtils, name, walletInfo.type, password);
required EncryptionFileUtils encryptionFileUtils}) async {
final snp =
await ElectrumWallletSnapshot.load(encryptionFileUtils, name, walletInfo.type, password);
return BitcoinWallet(
mnemonic: snp.mnemonic,
password: password,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
networkType: snp.networkType,
initialAddresses: snp.addresses,
initialBalance: snp.balance,
seedBytes: await mnemonicToSeedBytes(snp.mnemonic),
encryptionFileUtils: encryptionFileUtils,
initialRegularAddressIndex: snp.regularAddressIndex,
initialChangeAddressIndex: snp.changeAddressIndex);
initialChangeAddressIndex: snp.changeAddressIndex,
// TODO: store this value instead of calculating it every time
silentAddress: await bitcoin.SilentPaymentAddress.fromMnemonic(snp.mnemonic,
hrp: snp.networkType == bitcoin.bitcoin ? 'sp' : 'tsp'));
}
}

View file

@ -4,36 +4,34 @@ import 'package:cw_bitcoin/utils.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart';
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
part 'bitcoin_wallet_addresses.g.dart';
class BitcoinWalletAddresses = BitcoinWalletAddressesBase
with _$BitcoinWalletAddresses;
class BitcoinWalletAddresses = BitcoinWalletAddressesBase with _$BitcoinWalletAddresses;
abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses
with Store {
BitcoinWalletAddressesBase(
WalletInfo walletInfo,
abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with Store {
BitcoinWalletAddressesBase(WalletInfo walletInfo,
{required bitcoin.HDWallet mainHd,
required bitcoin.HDWallet sideHd,
required bitcoin.NetworkType networkType,
required ElectrumClient electrumClient,
List<BitcoinAddressRecord>? initialAddresses,
int initialRegularAddressIndex = 0,
int initialChangeAddressIndex = 0})
: super(
walletInfo,
int initialChangeAddressIndex = 0,
bitcoin.SilentPaymentAddress? silentAddress})
: super(walletInfo,
initialAddresses: initialAddresses,
initialRegularAddressIndex: initialRegularAddressIndex,
initialChangeAddressIndex: initialChangeAddressIndex,
mainHd: mainHd,
sideHd: sideHd,
electrumClient: electrumClient,
networkType: networkType);
networkType: networkType,
silentAddress: silentAddress);
@override
String getAddress({required int index, required bitcoin.HDWallet hd}) =>
generateP2WPKHAddress(hd: hd, index: index, networkType: networkType);
}

View file

@ -12,11 +12,10 @@ import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart';
import 'package:collection/collection.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
class BitcoinWalletService extends WalletService<
BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials,
BitcoinRestoreWalletFromWIFCredentials> {
class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials, BitcoinRestoreWalletFromWIFCredentials> {
BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource, this.isDirect);
final Box<WalletInfo> walletInfoSource;
@ -27,12 +26,13 @@ class BitcoinWalletService extends WalletService<
WalletType getType() => WalletType.bitcoin;
@override
Future<BitcoinWallet> create(BitcoinNewWalletCredentials credentials) async {
Future<BitcoinWallet> create(BitcoinNewWalletCredentials credentials, {bool? isTestnet}) async {
final wallet = await BitcoinWalletBase.create(
mnemonic: await generateMnemonic(),
password: credentials.password!,
walletInfo: credentials.walletInfo!,
unspentCoinsInfo: unspentCoinsInfoSource,
networkType: isTestnet == true ? bitcoin.testnet : bitcoin.bitcoin,
encryptionFileUtils: encryptionFileUtilsFor(isDirect));
await wallet.save();
await wallet.init();
@ -45,8 +45,8 @@ class BitcoinWalletService extends WalletService<
@override
Future<BitcoinWallet> openWallet(String name, String password) async {
final walletInfo = walletInfoSource.values.firstWhereOrNull(
(info) => info.id == WalletBase.idFor(name, getType()))!;
final walletInfo = walletInfoSource.values
.firstWhereOrNull((info) => info.id == WalletBase.idFor(name, getType()))!;
final wallet = await BitcoinWalletBase.open(
password: password,
name: name,
@ -59,17 +59,16 @@ class BitcoinWalletService extends WalletService<
@override
Future<void> remove(String wallet) async {
File(await pathForWalletDir(name: wallet, type: getType()))
.delete(recursive: true);
final walletInfo = walletInfoSource.values.firstWhereOrNull(
(info) => info.id == WalletBase.idFor(wallet, getType()))!;
File(await pathForWalletDir(name: wallet, type: getType())).delete(recursive: true);
final walletInfo = walletInfoSource.values
.firstWhereOrNull((info) => info.id == WalletBase.idFor(wallet, getType()))!;
await walletInfoSource.delete(walletInfo.key);
}
@override
Future<void> rename(String currentName, String password, String newName) async {
final currentWalletInfo = walletInfoSource.values.firstWhereOrNull(
(info) => info.id == WalletBase.idFor(currentName, getType()))!;
final currentWalletInfo = walletInfoSource.values
.firstWhereOrNull((info) => info.id == WalletBase.idFor(currentName, getType()))!;
final currentWallet = await BitcoinWalletBase.open(
password: password,
name: currentName,
@ -87,13 +86,11 @@ class BitcoinWalletService extends WalletService<
}
@override
Future<BitcoinWallet> restoreFromKeys(
BitcoinRestoreWalletFromWIFCredentials credentials) async =>
Future<BitcoinWallet> restoreFromKeys(BitcoinRestoreWalletFromWIFCredentials credentials) async =>
throw UnimplementedError();
@override
Future<BitcoinWallet> restoreFromSeed(
BitcoinRestoreWalletFromSeedCredentials credentials) async {
Future<BitcoinWallet> restoreFromSeed(BitcoinRestoreWalletFromSeedCredentials credentials) async {
if (!validateMnemonic(credentials.mnemonic)) {
throw BitcoinMnemonicIsIncorrectException();
}

View file

@ -22,10 +22,7 @@ String jsonrpc(
'{"jsonrpc": "$version", "method": "$method", "id": "$id", "params": ${json.encode(params)}}\n';
class SocketTask {
SocketTask({
required this.isSubscription,
this.completer,
this.subject});
SocketTask({required this.isSubscription, this.completer, this.subject});
final Completer<dynamic>? completer;
final BehaviorSubject<dynamic>? subject;
@ -51,8 +48,7 @@ class ElectrumClient {
Timer? _aliveTimer;
String unterminatedString;
Future<void> connectToUri(Uri uri) async =>
await connect(host: uri.host, port: uri.port);
Future<void> connectToUri(Uri uri) async => await connect(host: uri.host, port: uri.port);
Future<void> connect({required String host, required int port}) async {
try {
@ -104,21 +100,20 @@ class ElectrumClient {
}
if (isJSONStringCorrect(unterminatedString)) {
final response =
json.decode(unterminatedString) as Map<String, dynamic>;
final response = json.decode(unterminatedString) as Map<String, dynamic>;
_handleResponse(response);
unterminatedString = '';
}
} on TypeError catch (e) {
if (!e.toString().contains('Map<String, Object>') && !e.toString().contains('Map<String, dynamic>')) {
if (!e.toString().contains('Map<String, Object>') &&
!e.toString().contains('Map<String, dynamic>')) {
return;
}
unterminatedString += message;
if (isJSONStringCorrect(unterminatedString)) {
final response =
json.decode(unterminatedString) as Map<String, dynamic>;
final response = json.decode(unterminatedString) as Map<String, dynamic>;
_handleResponse(response);
// unterminatedString = null;
unterminatedString = '';
@ -142,8 +137,7 @@ class ElectrumClient {
}
}
Future<List<String>> version() =>
call(method: 'server.version').then((dynamic result) {
Future<List<String>> version() => call(method: 'server.version').then((dynamic result) {
if (result is List) {
return result.map((dynamic val) => val.toString()).toList();
}
@ -181,8 +175,7 @@ class ElectrumClient {
String address, NetworkType networkType) =>
call(
method: 'blockchain.scripthash.listunspent',
params: [scriptHash(address, networkType: networkType)])
.then((dynamic result) {
params: [scriptHash(address, networkType: networkType)]).then((dynamic result) {
if (result is List) {
return result.map((dynamic val) {
if (val is Map<String, dynamic>) {
@ -229,19 +222,25 @@ class ElectrumClient {
return [];
});
Future<Map<String, dynamic>> getTransactionRaw(
{required String hash}) async =>
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, true], timeout: 10000)
Future<dynamic> getTransactionRaw(
{required String hash, required NetworkType networkType}) async =>
callWithTimeout(
method: 'blockchain.transaction.get',
params: networkType == bitcoin ? [hash, true] : [hash],
timeout: 10000)
.then((dynamic result) {
if (result is Map<String, dynamic>) {
return result;
}
if (networkType == testnet && result is String) {
return result;
}
return <String, dynamic>{};
});
Future<String> getTransactionHex(
{required String hash}) async =>
Future<String> getTransactionHex({required String hash}) async =>
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, false], timeout: 10000)
.then((dynamic result) {
if (result is String) {
@ -251,8 +250,7 @@ class ElectrumClient {
return '';
});
Future<String> broadcastTransaction(
{required String transactionRaw}) async =>
Future<String> broadcastTransaction({required String transactionRaw}) async =>
call(method: 'blockchain.transaction.broadcast', params: [transactionRaw])
.then((dynamic result) {
if (result is String) {
@ -262,19 +260,15 @@ class ElectrumClient {
return '';
});
Future<Map<String, dynamic>> getMerkle(
{required String hash, required int height}) async =>
await call(
method: 'blockchain.transaction.get_merkle',
params: [hash, height]) as Map<String, dynamic>;
Future<Map<String, dynamic>> getHeader({required int height}) async =>
await call(method: 'blockchain.block.get_header', params: [height])
Future<Map<String, dynamic>> getMerkle({required String hash, required int height}) async =>
await call(method: 'blockchain.transaction.get_merkle', params: [hash, height])
as Map<String, dynamic>;
Future<Map<String, dynamic>> getHeader({required int height}) async =>
await call(method: 'blockchain.block.get_header', params: [height]) as Map<String, dynamic>;
Future<double> estimatefee({required int p}) =>
call(method: 'blockchain.estimatefee', params: [p])
.then((dynamic result) {
call(method: 'blockchain.estimatefee', params: [p]).then((dynamic result) {
if (result is double) {
return result;
}
@ -319,15 +313,9 @@ class ElectrumClient {
final topDoubleString = await estimatefee(p: 1);
final middleDoubleString = await estimatefee(p: 5);
final bottomDoubleString = await estimatefee(p: 100);
final top =
(stringDoubleToBitcoinAmount(topDoubleString.toString()) / 1000)
.round();
final middle =
(stringDoubleToBitcoinAmount(middleDoubleString.toString()) / 1000)
.round();
final bottom =
(stringDoubleToBitcoinAmount(bottomDoubleString.toString()) / 1000)
.round();
final top = (stringDoubleToBitcoinAmount(topDoubleString.toString()) / 1000).round();
final middle = (stringDoubleToBitcoinAmount(middleDoubleString.toString()) / 1000).round();
final bottom = (stringDoubleToBitcoinAmount(bottomDoubleString.toString()) / 1000).round();
return [bottom, middle, top];
} catch (_) {
@ -344,9 +332,7 @@ class ElectrumClient {
}
BehaviorSubject<T>? subscribe<T>(
{required String id,
required String method,
List<Object> params = const []}) {
{required String id, required String method, List<Object> params = const []}) {
try {
final subscription = BehaviorSubject<T>();
_regisrySubscription(id, subscription);
@ -370,9 +356,7 @@ class ElectrumClient {
}
Future<dynamic> callWithTimeout(
{required String method,
List<Object> params = const [],
int timeout = 4000}) async {
{required String method, List<Object> params = const [], int timeout = 4000}) async {
try {
final completer = Completer<dynamic>();
_id += 1;
@ -397,8 +381,8 @@ class ElectrumClient {
onConnectionStatusChange = null;
}
void _registryTask(int id, Completer<dynamic> completer) => _tasks[id.toString()] =
SocketTask(completer: completer, isSubscription: false);
void _registryTask(int id, Completer<dynamic> completer) =>
_tasks[id.toString()] = SocketTask(completer: completer, isSubscription: false);
void _regisrySubscription(String id, BehaviorSubject<dynamic> subject) =>
_tasks[id] = SocketTask(subject: subject, isSubscription: true);
@ -419,8 +403,7 @@ class ElectrumClient {
}
}
void _methodHandler(
{required String method, required Map<String, dynamic> request}) {
void _methodHandler({required String method, required Map<String, dynamic> request}) {
switch (method) {
case 'blockchain.scripthash.subscribe':
final params = request['params'] as List<dynamic>;

View file

@ -34,13 +34,15 @@ import 'package:cw_bitcoin/electrum.dart';
import 'package:hex/hex.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
part 'electrum_wallet.g.dart';
class ElectrumWallet = ElectrumWalletBase with _$ElectrumWallet;
abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
ElectrumTransactionHistory, ElectrumTransactionInfo> with Store {
abstract class ElectrumWalletBase
extends WalletBase<ElectrumBalance, ElectrumTransactionHistory, ElectrumTransactionInfo>
with Store {
ElectrumWalletBase(
{required String password,
required WalletInfo walletInfo,
@ -53,28 +55,25 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
ElectrumClient? electrumClient,
ElectrumBalance? initialBalance,
CryptoCurrency? currency})
: hd = bitcoin.HDWallet.fromSeed(seedBytes, network: networkType)
.derivePath("m/0'/0"),
: hd = bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath("m/0'/0"),
syncStatus = NotConnectedSyncStatus(),
_password = password,
_feeRates = <int>[],
_isTransactionUpdating = false,
unspentCoins = [],
_scripthashesUpdateSubject = {},
balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of(
currency != null
? {currency: initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0,
frozen: 0)}
balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of(currency != null
? {
currency:
initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0)
}
: {}),
this.unspentCoinsInfo = unspentCoinsInfo,
super(walletInfo) {
this.electrumClient = electrumClient ?? ElectrumClient();
this.walletInfo = walletInfo;
transactionHistory =
ElectrumTransactionHistory(
walletInfo: walletInfo,
password: password,
encryptionFileUtils: encryptionFileUtils);
transactionHistory = ElectrumTransactionHistory(
walletInfo: walletInfo, password: password, encryptionFileUtils: encryptionFileUtils);
}
static int estimatedTransactionSize(int inputsCount, int outputsCounts) =>
@ -118,8 +117,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
bitcoin.NetworkType networkType;
@override
BitcoinWalletKeys get keys => BitcoinWalletKeys(
wif: hd.wif!, privateKey: hd.privKey!, publicKey: hd.pubKey!);
BitcoinWalletKeys get keys =>
BitcoinWalletKeys(wif: hd.wif!, privateKey: hd.privKey!, publicKey: hd.pubKey!);
String _password;
List<BitcoinUnspent> unspentCoins;
@ -147,8 +146,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
await updateBalance();
_feeRates = await electrumClient.feeRates();
Timer.periodic(const Duration(minutes: 1),
(timer) async => _feeRates = await electrumClient.feeRates());
Timer.periodic(
const Duration(minutes: 1), (timer) async => _feeRates = await electrumClient.feeRates());
syncStatus = SyncedSyncStatus();
} catch (e, stacktrace) {
@ -177,8 +176,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
@override
Future<PendingBitcoinTransaction> createTransaction(
Object credentials) async {
Future<PendingBitcoinTransaction> createTransaction(Object credentials) async {
const minAmount = 546;
final transactionCredentials = credentials as BitcoinTransactionCredentials;
final inputs = <BitcoinUnspent>[];
@ -201,9 +199,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
throw BitcoinTransactionNoInputsException();
}
final allAmountFee = transactionCredentials.feeRate != null
? feeAmountWithFeeRate(transactionCredentials.feeRate!, inputs.length, outputs.length)
: feeAmountForPriority(transactionCredentials.priority!, inputs.length, outputs.length);
final allAmountFee = 188;
final allAmount = allInputsAmount - allAmountFee;
@ -212,13 +208,11 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
var fee = 0;
if (hasMultiDestination) {
if (outputs.any((item) => item.sendAll
|| item.formattedCryptoAmount! <= 0)) {
if (outputs.any((item) => item.sendAll || item.formattedCryptoAmount! <= 0)) {
throw BitcoinTransactionWrongBalanceException(currency);
}
credentialsAmount = outputs.fold(0, (acc, value) =>
acc + value.formattedCryptoAmount!);
credentialsAmount = outputs.fold(0, (acc, value) => acc + value.formattedCryptoAmount!);
if (allAmount - credentialsAmount < minAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
@ -235,9 +229,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
} else {
final output = outputs.first;
credentialsAmount = !output.sendAll
? output.formattedCryptoAmount!
: 0;
credentialsAmount = !output.sendAll ? output.formattedCryptoAmount! : 0;
if (credentialsAmount > allAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
@ -256,14 +248,14 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
}
if (fee == 0) {
throw BitcoinTransactionWrongBalanceException(currency);
if (fee == 0 && networkType == bitcoin.bitcoin) {
// throw BitcoinTransactionWrongBalanceException(currency);
}
final totalAmount = amount + fee;
if (totalAmount > balance[currency]!.confirmed || totalAmount > allInputsAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
// throw BitcoinTransactionWrongBalanceException(currency);
}
final txb = bitcoin.TransactionBuilder(network: networkType);
@ -290,11 +282,19 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
if (amount <= 0 || totalInputAmount < totalAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
// throw BitcoinTransactionWrongBalanceException(currency);
}
txb.setVersion(1);
List<bitcoin.PrivateKeyInfo> privateKeys = [];
List<bitcoin.Outpoint> outpoints = [];
inputs.forEach((input) {
privateKeys.add(bitcoin.PrivateKeyInfo(
bitcoin.ECPrivateKey(Uint8List.fromList(
HEX.decode(walletAddresses.sideHd.derive(input.address.index).privKey!))),
false));
outpoints.add(bitcoin.Outpoint(Uint8List.fromList(HEX.decode(input.hash)), input.vout));
if (input.isP2wpkh) {
final p2wpkh = bitcoin
.P2WPKH(
@ -310,28 +310,43 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
});
List<bitcoin.SilentPaymentDestination> silentDestinations = [];
outputs.forEach((item) {
final outputAmount = hasMultiDestination
? item.formattedCryptoAmount
: amount;
final outputAddress = item.isParsedAddress
? item.extractedAddress!
: item.address;
txb.addOutput(
addressToOutputScript(outputAddress, networkType),
outputAmount!);
final outputAmount = hasMultiDestination ? item.formattedCryptoAmount : amount;
final outputAddress = item.isParsedAddress ? item.extractedAddress! : item.address;
if (outputAddress.startsWith('tsp1')) {
silentDestinations
.add(bitcoin.SilentPaymentDestination.fromAddress(outputAddress, outputAmount!));
} else {
txb.addOutput(addressToOutputScript(outputAddress, networkType), outputAmount!);
}
});
final estimatedSize =
estimatedTransactionSize(inputs.length, outputs.length + 1);
var feeAmount = 0;
if (silentDestinations.isNotEmpty) {
final outpointsHash = bitcoin.SilentPayment.hashOutpoints(outpoints);
if (transactionCredentials.feeRate != null) {
feeAmount = transactionCredentials.feeRate! * estimatedSize;
} else {
feeAmount = feeRate(transactionCredentials.priority!) * estimatedSize;
final sumOfInputPrivKeys = bitcoin.getSumInputPrivKeys(privateKeys);
final generatedPubkeys = bitcoin.SilentPayment.generateMultipleRecipientPubkeys(
sumOfInputPrivKeys, outpointsHash, silentDestinations);
generatedPubkeys.forEach((recipientSilentAddress, generatedOutputs) {
generatedOutputs.forEach((output) {
final generatedPubkey = HEX.encode(output.$1.data);
txb.addOutput(bitcoin.getTaproot(generatedPubkey).toScriptPubKey().toBytes(), output.$2);
});
});
}
final estimatedSize = estimatedTransactionSize(inputs.length, outputs.length + 1);
var feeAmount = 188;
// if (transactionCredentials.feeRate != null) {
// feeAmount = transactionCredentials.feeRate! * estimatedSize;
// } else {
// feeAmount = feeRate(transactionCredentials.priority!) * estimatedSize;
// }
final changeValue = totalInputAmount - amount - feeAmount;
if (changeValue > minAmount) {
@ -362,7 +377,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
'account_index': walletAddresses.currentReceiveAddressIndex.toString(),
'change_address_index': walletAddresses.currentChangeAddressIndex.toString(),
'addresses': walletAddresses.addresses.map((addr) => addr.toJSON()).toList(),
'balance': balance[currency]?.toJSON()
'balance': balance[currency]?.toJSON(),
'network_type': networkType.toString()
});
int feeRate(TransactionPriority priority) {
@ -377,29 +393,24 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
}
int feeAmountForPriority(BitcoinTransactionPriority priority, int inputsCount,
int outputsCount) =>
int feeAmountForPriority(
BitcoinTransactionPriority priority, int inputsCount, int outputsCount) =>
feeRate(priority) * estimatedTransactionSize(inputsCount, outputsCount);
int feeAmountWithFeeRate(int feeRate, int inputsCount,
int outputsCount) =>
int feeAmountWithFeeRate(int feeRate, int inputsCount, int outputsCount) =>
feeRate * estimatedTransactionSize(inputsCount, outputsCount);
@override
int calculateEstimatedFee(TransactionPriority? priority, int? amount,
{int? outputsCount}) {
int calculateEstimatedFee(TransactionPriority? priority, int? amount, {int? outputsCount}) {
if (priority is BitcoinTransactionPriority) {
return calculateEstimatedFeeWithFeeRate(
feeRate(priority),
amount,
return calculateEstimatedFeeWithFeeRate(feeRate(priority), amount,
outputsCount: outputsCount);
}
return 0;
}
int calculateEstimatedFeeWithFeeRate(int feeRate, int? amount,
{int? outputsCount}) {
int calculateEstimatedFeeWithFeeRate(int feeRate, int? amount, {int? outputsCount}) {
int inputsCount = 0;
if (amount != null) {
@ -428,8 +439,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
// If send all, then we have no change value
final _outputsCount = outputsCount ?? (amount != null ? 2 : 1);
return feeAmountWithFeeRate(
feeRate, inputsCount, _outputsCount);
return feeAmountWithFeeRate(feeRate, inputsCount, _outputsCount);
}
@override
@ -444,8 +454,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
final currentWalletFile = File(currentWalletPath);
final currentDirPath =
await pathForWalletDir(name: walletInfo.name, type: type);
final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
// Copies current wallet files into new wallet name's dir and files
@ -482,21 +491,63 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
} catch (_) {}
}
Future<String> makePath() async =>
pathForWallet(name: walletInfo.name, type: walletInfo.type);
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
Future<void> updateUnspent() async {
final unspent = await Future.wait(walletAddresses
.addresses.map((address) => electrumClient
final unspent = await Future.wait(walletAddresses.addresses.map((address) => electrumClient
.getListUnspentWithAddress(address.address, networkType)
.then((unspent) => unspent
.map((unspent) {
.then((unspent) => unspent.map((unspent) {
try {
return BitcoinUnspent.fromJSON(address, unspent);
} catch (_) {
return null;
}
}).whereNotNull())));
final uri = Uri(
scheme: 'https',
host: 'blockstream.info',
path: '/testnet/api/tx/986547a4daec37b21d2252e39c740d77ff92d927343b0b6e017d45e857955efa');
await http.get(uri).then((response) {
final obj = json.decode(response.body);
final scanPrivateKey = walletAddresses.silentAddress!.scanPrivkey;
final spendPublicKey = walletAddresses.silentAddress!.spendPubkey;
Uint8List? sumOfInputPublicKeys;
List<bitcoin.Outpoint> outpoints = [];
obj["vin"].forEach((input) {
sumOfInputPublicKeys = Uint8List.fromList(HEX.decode(input["witness"][1] as String));
outpoints.add(bitcoin.Outpoint(
Uint8List.fromList(HEX.decode(input['txid'] as String)), input['vout'] as int));
});
final outpointHash = bitcoin.SilentPayment.hashOutpoints(outpoints);
List<Uint8List> outputs = [];
obj['vout'].forEach((out) {
outputs.add(Uint8List.fromList(
HEX.decode(bitcoin.getScript(out["scriptpubkey"] as String)[1] as String)));
});
final result = bitcoin.scanOutputs(
scanPrivateKey.data, spendPublicKey.data, sumOfInputPublicKeys!, outpointHash, outputs);
result.forEach((key, value) {
final tweak = value;
// TODO: store tweak for BitcoinUnspent
final spendPrivateKey = walletAddresses.silentAddress!.spendPrivkey;
final privKey = spendPrivateKey.tweak(tweak);
final pubKey = bitcoin.ECPrivateKey(privKey!.data).pubkey;
int i = 0;
final vout = obj['vout'].firstWhere((out) {
final script = bitcoin.getScript(out["scriptpubkey"] as String);
final scriptHash = script[1] as String;
i++;
return scriptHash == key;
});
unspent.add([
BitcoinUnspent.fromJSON(
BitcoinAddressRecord(vout["scriptpubkey_address"] as String, index: 0, isUsed: true),
{"tx_hash": obj["txid"], "value": vout["value"], "tx_pos": i},
isSilent: true)
]);
});
});
unspentCoins = unspent.expand((e) => e).toList();
if (unspentCoinsInfo.isEmpty) {
@ -507,7 +558,9 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
if (unspentCoins.isNotEmpty) {
unspentCoins.forEach((coin) {
final coinInfoList = unspentCoinsInfo.values.where((element) =>
element.walletId.contains(id) && element.hash.contains(coin.hash));
element.walletId.contains(id) &&
element.hash.contains(coin.hash) &&
element.address.contains(coin.address.address));
if (coinInfoList.isNotEmpty) {
final coinInfo = coinInfoList.first;
@ -542,8 +595,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
Future<void> _refreshUnspentCoinsInfo() async {
try {
final List<dynamic> keys = <dynamic>[];
final currentWalletUnspentCoins = unspentCoinsInfo.values
.where((element) => element.walletId.contains(id));
final currentWalletUnspentCoins =
unspentCoinsInfo.values.where((element) => element.walletId.contains(id));
if (currentWalletUnspentCoins.isNotEmpty) {
currentWalletUnspentCoins.forEach((element) {
@ -565,12 +618,23 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
Future<ElectrumTransactionBundle> getTransactionExpanded(
{required String hash, required int height}) async {
final verboseTransaction = await electrumClient.getTransactionRaw(hash: hash);
final transactionHex = verboseTransaction['hex'] as String;
final verboseTransaction =
await electrumClient.getTransactionRaw(hash: hash, networkType: networkType);
String transactionHex;
int? time;
int confirmations = 0;
if (networkType == bitcoin.testnet) {
transactionHex = verboseTransaction as String;
confirmations = 1;
} else {
transactionHex = verboseTransaction['hex'] as String;
time = verboseTransaction['time'] as int?;
confirmations = verboseTransaction['confirmations'] as int? ?? 0;
}
final original = bitcoin.Transaction.fromHex(transactionHex);
final ins = <bitcoin.Transaction>[];
final time = verboseTransaction['time'] as int?;
final confirmations = verboseTransaction['confirmations'] as int? ?? 0;
for (final vin in original.ins) {
final id = HEX.encode(vin.hash!.reversed.toList());
@ -579,11 +643,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
ins.add(tx);
}
return ElectrumTransactionBundle(
original,
ins: ins,
time: time,
confirmations: confirmations);
return ElectrumTransactionBundle(original, ins: ins, time: time, confirmations: confirmations);
}
Future<ElectrumTransactionInfo?> fetchTransactionInfo(
@ -591,12 +651,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
try {
final tx = await getTransactionExpanded(hash: hash, height: height);
final addresses = walletAddresses.addresses.map((addr) => addr.address).toSet();
return ElectrumTransactionInfo.fromElectrumBundle(
tx,
walletInfo.type,
networkType,
addresses: addresses,
height: height);
return ElectrumTransactionInfo.fromElectrumBundle(tx, walletInfo.type, networkType,
addresses: addresses, height: height);
} catch (_) {
return null;
}
@ -610,10 +666,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
final sh = scriptHash(addressRecord.address, networkType: networkType);
addressHashes[sh] = addressRecord;
});
final histories =
addressHashes.keys.map((scriptHash) => electrumClient
.getHistory(scriptHash)
.then((history) => {scriptHash: history}));
final histories = addressHashes.keys.map((scriptHash) =>
electrumClient.getHistory(scriptHash).then((history) => {scriptHash: history}));
final historyResults = await Future.wait(histories);
historyResults.forEach((history) {
history.entries.forEach((historyItem) {
@ -624,19 +678,16 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
});
});
final historiesWithDetails = await Future.wait(
normalizedHistories
.map((transaction) {
final historiesWithDetails = await Future.wait(normalizedHistories.map((transaction) {
try {
return fetchTransactionInfo(
hash: transaction['tx_hash'] as String,
height: transaction['height'] as int);
hash: transaction['tx_hash'] as String, height: transaction['height'] as int);
} catch (_) {
return Future.value(null);
}
}));
return historiesWithDetails.fold<Map<String, ElectrumTransactionInfo>>(
<String, ElectrumTransactionInfo>{}, (acc, tx) {
return historiesWithDetails
.fold<Map<String, ElectrumTransactionInfo>>(<String, ElectrumTransactionInfo>{}, (acc, tx) {
if (tx == null) {
return acc;
}
@ -689,6 +740,9 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
final addresses = walletAddresses.addresses.toList();
final balanceFutures = <Future<Map<String, dynamic>>>[];
var totalConfirmed = 0;
var totalUnconfirmed = 0;
for (var i = 0; i < addresses.length; i++) {
final addressRecord = addresses[i];
final sh = scriptHash(addressRecord.address, networkType: networkType);
@ -699,16 +753,21 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
var totalFrozen = 0;
unspentCoinsInfo.values.forEach((info) {
unspentCoins.forEach((element) {
if (element.hash == info.hash && info.isFrozen && element.address.address == info.address
&& element.value == info.value) {
if (element.hash == info.hash &&
info.isFrozen &&
element.address.address == info.address &&
element.value == info.value) {
totalFrozen += element.value;
} else if (element.hash == info.hash &&
element.isSilent &&
element.address.address == info.address &&
element.value == info.value) {
totalConfirmed += element.value;
}
});
});
final balances = await Future.wait(balanceFutures);
var totalConfirmed = 0;
var totalUnconfirmed = 0;
for (var i = 0; i < balances.length; i++) {
final addressRecord = addresses[i];
@ -723,8 +782,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
}
return ElectrumBalance(confirmed: totalConfirmed, unconfirmed: totalUnconfirmed,
frozen: totalFrozen);
return ElectrumBalance(
confirmed: totalConfirmed, unconfirmed: totalUnconfirmed, frozen: totalFrozen);
}
Future<void> updateBalance() async {
@ -735,9 +794,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
String getChangeAddress() {
const minCountOfHiddenAddresses = 5;
final random = Random();
var addresses = walletAddresses.addresses
.where((addr) => addr.isHidden)
.toList();
var addresses = walletAddresses.addresses.where((addr) => addr.isHidden).toList();
if (addresses.length < minCountOfHiddenAddresses) {
addresses = walletAddresses.addresses.toList();

View file

@ -8,8 +8,7 @@ import 'package:mobx/mobx.dart';
part 'electrum_wallet_addresses.g.dart';
class ElectrumWalletAddresses = ElectrumWalletAddressesBase
with _$ElectrumWalletAddresses;
class ElectrumWalletAddresses = ElectrumWalletAddressesBase with _$ElectrumWalletAddresses;
abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
ElectrumWalletAddressesBase(WalletInfo walletInfo,
@ -19,15 +18,14 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
required this.networkType,
List<BitcoinAddressRecord>? initialAddresses,
int initialRegularAddressIndex = 0,
int initialChangeAddressIndex = 0})
: addresses = ObservableList<BitcoinAddressRecord>.of(
(initialAddresses ?? []).toSet()),
receiveAddresses = ObservableList<BitcoinAddressRecord>.of(
(initialAddresses ?? [])
int initialChangeAddressIndex = 0,
bitcoin.SilentPaymentAddress? silentAddress})
: addresses = ObservableList<BitcoinAddressRecord>.of((initialAddresses ?? []).toSet()),
silentAddress = silentAddress,
receiveAddresses = ObservableList<BitcoinAddressRecord>.of((initialAddresses ?? [])
.where((addressRecord) => !addressRecord.isHidden && !addressRecord.isUsed)
.toSet()),
changeAddresses = ObservableList<BitcoinAddressRecord>.of(
(initialAddresses ?? [])
changeAddresses = ObservableList<BitcoinAddressRecord>.of((initialAddresses ?? [])
.where((addressRecord) => addressRecord.isHidden && !addressRecord.isUsed)
.toSet()),
currentReceiveAddressIndex = initialRegularAddressIndex,
@ -46,9 +44,14 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
final bitcoin.HDWallet mainHd;
final bitcoin.HDWallet sideHd;
@override
// TODO: labels -> disable edit on receive page
final bitcoin.SilentPaymentAddress? silentAddress;
@observable
String? activeAddress;
@computed
String get address {
String get receiveAddress {
if (receiveAddresses.isEmpty) {
return generateNewAddress().address;
}
@ -57,14 +60,27 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
}
@override
set address(String addr) => null;
@computed
String get address {
if (activeAddress != null) {
return activeAddress!;
}
if (receiveAddresses.isEmpty) {
return generateNewAddress().address;
}
return receiveAddresses.first.address;
}
@override
set address(String addr) => activeAddress = addr;
int currentReceiveAddressIndex;
int currentChangeAddressIndex;
@computed
int get totalCountOfReceiveAddresses =>
addresses.fold(0, (acc, addressRecord) {
int get totalCountOfReceiveAddresses => addresses.fold(0, (acc, addressRecord) {
if (!addressRecord.isHidden) {
return acc + 1;
}
@ -72,8 +88,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
});
@computed
int get totalCountOfChangeAddresses =>
addresses.fold(0, (acc, addressRecord) {
int get totalCountOfChangeAddresses => addresses.fold(0, (acc, addressRecord) {
if (addressRecord.isHidden) {
return acc + 1;
}
@ -107,12 +122,9 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
updateChangeAddresses();
if (changeAddresses.isEmpty) {
final newAddresses = await _createNewAddresses(
gap,
final newAddresses = await _createNewAddresses(gap,
hd: sideHd,
startIndex: totalCountOfChangeAddresses > 0
? totalCountOfChangeAddresses - 1
: 0,
startIndex: totalCountOfChangeAddresses > 0 ? totalCountOfChangeAddresses - 1 : 0,
isHidden: true);
_addAddresses(newAddresses);
}
@ -127,8 +139,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
return address;
}
BitcoinAddressRecord generateNewAddress(
{bitcoin.HDWallet? hd, bool isHidden = false}) {
BitcoinAddressRecord generateNewAddress({bitcoin.HDWallet? hd, bool isHidden = false}) {
currentReceiveAddressIndex += 1;
// FIX-ME: Check logic for whichi HD should be used here ???
final address = BitcoinAddressRecord(
@ -155,16 +166,16 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
@action
void updateReceiveAddresses() {
receiveAddresses.removeRange(0, receiveAddresses.length);
final newAdresses = addresses
.where((addressRecord) => !addressRecord.isHidden && !addressRecord.isUsed);
final newAdresses =
addresses.where((addressRecord) => !addressRecord.isHidden && !addressRecord.isUsed);
receiveAddresses.addAll(newAdresses);
}
@action
void updateChangeAddresses() {
changeAddresses.removeRange(0, changeAddresses.length);
final newAdresses = addresses
.where((addressRecord) => addressRecord.isHidden && !addressRecord.isUsed);
final newAdresses =
addresses.where((addressRecord) => addressRecord.isHidden && !addressRecord.isUsed);
changeAddresses.addAll(newAdresses);
}
@ -173,14 +184,10 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
List<BitcoinAddressRecord> addrs;
if (addresses.isNotEmpty) {
addrs = addresses
.where((addr) => addr.isHidden == isHidden)
.toList();
addrs = addresses.where((addr) => addr.isHidden == isHidden).toList();
} else {
addrs = await _createNewAddresses(
isHidden
? defaultChangeAddressesCount
: defaultReceiveAddressesCount,
isHidden ? defaultChangeAddressesCount : defaultReceiveAddressesCount,
startIndex: 0,
hd: hd,
isHidden: isHidden);
@ -196,11 +203,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
final start = addrs.length;
final count = start + gap;
final batch = await _createNewAddresses(
count,
startIndex: start,
hd: hd,
isHidden: isHidden);
final batch = await _createNewAddresses(count, startIndex: start, hd: hd, isHidden: isHidden);
addrs.addAll(batch);
}
@ -224,21 +227,15 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
if (countOfReceiveAddresses < defaultReceiveAddressesCount) {
final addressesCount = defaultReceiveAddressesCount - countOfReceiveAddresses;
final newAddresses = await _createNewAddresses(
addressesCount,
startIndex: countOfReceiveAddresses,
hd: mainHd,
isHidden: false);
final newAddresses = await _createNewAddresses(addressesCount,
startIndex: countOfReceiveAddresses, hd: mainHd, isHidden: false);
addresses.addAll(newAddresses);
}
if (countOfHiddenAddresses < defaultChangeAddressesCount) {
final addressesCount = defaultChangeAddressesCount - countOfHiddenAddresses;
final newAddresses = await _createNewAddresses(
addressesCount,
startIndex: countOfHiddenAddresses,
hd: sideHd,
isHidden: true);
final newAddresses = await _createNewAddresses(addressesCount,
startIndex: countOfHiddenAddresses, hd: sideHd, isHidden: true);
addresses.addAll(newAddresses);
}
}
@ -248,10 +245,8 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
final list = <BitcoinAddressRecord>[];
for (var i = startIndex; i < count + startIndex; i++) {
final address = BitcoinAddressRecord(
getAddress(index: i, hd: hd),
index: i,
isHidden: isHidden);
final address =
BitcoinAddressRecord(getAddress(index: i, hd: hd), index: i, isHidden: isHidden);
list.add(address);
}

View file

@ -4,6 +4,7 @@ import 'package:cw_bitcoin/electrum_balance.dart';
import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
class ElectrumWallletSnapshot {
ElectrumWallletSnapshot({
@ -13,6 +14,7 @@ class ElectrumWallletSnapshot {
required this.mnemonic,
required this.addresses,
required this.balance,
required this.networkType,
required this.regularAddressIndex,
required this.changeAddressIndex});
@ -23,6 +25,7 @@ class ElectrumWallletSnapshot {
String mnemonic;
List<BitcoinAddressRecord> addresses;
ElectrumBalance balance;
bitcoin.NetworkType networkType;
int regularAddressIndex;
int changeAddressIndex;
@ -38,6 +41,7 @@ class ElectrumWallletSnapshot {
.toList();
final balance = ElectrumBalance.fromJSON(data['balance'] as String) ??
ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0);
final networkType = bitcoin.testnet;
var regularAddressIndex = 0;
var changeAddressIndex = 0;
@ -53,6 +57,7 @@ class ElectrumWallletSnapshot {
mnemonic: mnemonic,
addresses: addresses,
balance: balance,
networkType: networkType,
regularAddressIndex: regularAddressIndex,
changeAddressIndex: changeAddressIndex);
}

View file

@ -27,7 +27,7 @@ class LitecoinWalletService extends WalletService<
WalletType getType() => WalletType.litecoin;
@override
Future<LitecoinWallet> create(BitcoinNewWalletCredentials credentials) async {
Future<LitecoinWallet> create(BitcoinNewWalletCredentials credentials, {bool? isTestnet}) async {
final wallet = await LitecoinWalletBase.create(
mnemonic: await generateMnemonic(),
password: credentials.password!,

View file

@ -66,15 +66,31 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.6"
bitcoin_base:
dependency: transitive
description:
path: "."
ref: main
resolved-ref: "9a8db71a18ef011759cbc20f30a1c80122b77147"
url: "https://github.com/saltrafael/bitcoin_base.git"
source: git
version: "1.1.0"
bitcoin_flutter:
dependency: "direct main"
description:
path: "."
ref: cake-update-v3
resolved-ref: df9204144011ed9419eff7d9ef3143102a40252d
url: "https://github.com/cake-tech/bitcoin_flutter.git"
source: git
path: "/home/rafael/Storage/Repositories/btc-silent-payments/bitcoin_flutter"
relative: false
source: path
version: "2.0.2"
blockchain_utils:
dependency: transitive
description:
path: "."
ref: main
resolved-ref: "722663eab280c09bbec216dc4ab93904865d4a81"
url: "https://github.com/saltrafael/blockchain_utils.git"
source: git
version: "0.4.0"
boolean_selector:
dependency: transitive
description:
@ -196,6 +212,15 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.4.0"
coinlib:
dependency: transitive
description:
path: coinlib
ref: silent-payments
resolved-ref: "1e34ceac9e3165a495910e1ea122ac35b72c374b"
url: "https://github.com/saltrafael/coinlib.git"
source: git
version: "1.0.0"
collection:
dependency: transitive
description:
@ -243,6 +268,22 @@ packages:
relative: true
source: path
version: "0.0.1"
dart_base_x:
dependency: transitive
description:
name: dart_base_x
sha256: c8af4f6a6518daab4aa85bb27ee148221644e80446bb44117052b6f4674cdb23
url: "https://pub.dev"
source: hosted
version: "1.0.0"
dart_bech32:
dependency: transitive
description:
name: dart_bech32
sha256: "0e1dc1ff39c9669c9ffeafd5d675104918f7b50799692491badfea7e1fb40888"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
dart_style:
dependency: transitive
description:
@ -251,6 +292,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.4"
elliptic:
dependency: transitive
description:
name: elliptic
sha256: "98e2fa89a714c649174553c823db2612dc9581814477fe1264a499d448237b6b"
url: "https://pub.dev"
source: hosted
version: "0.3.10"
encrypt:
dependency: "direct main"
description:
@ -271,10 +320,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.1.0"
file:
dependency: transitive
description:
@ -553,10 +602,10 @@ packages:
dependency: transitive
description:
name: pointycastle
sha256: db7306cf0249f838d1a24af52b5a5887c5bf7f31d8bb4e827d071dc0939ad346
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c"
url: "https://pub.dev"
source: hosted
version: "3.6.2"
version: "3.7.3"
pool:
dependency: transitive
description:
@ -710,10 +759,10 @@ packages:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.3.2"
unorm_dart:
dependency: "direct main"
description:
@ -730,6 +779,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
wasm_interop:
dependency: transitive
description:
name: wasm_interop
sha256: b1b378f07a4cf0103c25faf34d9a64d2c3312135b9efb47e0ec116ec3b14e48f
url: "https://pub.dev"
source: hosted
version: "2.0.1"
watcher:
dependency: transitive
description:

View file

@ -22,7 +22,7 @@ dependencies:
bitcoin_flutter:
git:
url: https://github.com/cake-tech/bitcoin_flutter.git
ref: cake-update-v3
ref: silent-payments
rxdart: ^0.27.5
unorm_dart: ^0.2.0
cryptography: ^2.0.5

View file

@ -8,7 +8,7 @@ abstract class WalletService<N extends WalletCredentials, RFS extends WalletCred
RFK extends WalletCredentials> {
WalletType getType();
Future<WalletBase> create(N credentials);
Future<WalletBase> create(N credentials, {bool? isTestnet});
Future<WalletBase> restoreFromSeed(RFS credentials);

View file

@ -21,7 +21,7 @@ class EthereumWalletService extends WalletService<EthereumNewWalletCredentials,
final bool isDirect;
@override
Future<EthereumWallet> create(EthereumNewWalletCredentials credentials) async {
Future<EthereumWallet> create(EthereumNewWalletCredentials credentials, {bool? isTestnet}) async {
final mnemonic = bip39.generateMnemonic();
final wallet = EthereumWallet(
walletInfo: credentials.walletInfo!,

View file

@ -68,7 +68,7 @@ class HavenWalletService extends WalletService<
WalletType getType() => WalletType.haven;
@override
Future<HavenWallet> create(HavenNewWalletCredentials credentials) async {
Future<HavenWallet> create(HavenNewWalletCredentials credentials, {bool? isTestnet}) async {
try {
final path = await pathForWallet(name: credentials.name, type: getType());
await haven_wallet_manager.createWallet(

View file

@ -65,7 +65,7 @@ class MoneroWalletService extends WalletService<
WalletType getType() => WalletType.monero;
@override
Future<MoneroWallet> create(MoneroNewWalletCredentials credentials) async {
Future<MoneroWallet> create(MoneroNewWalletCredentials credentials, {bool? isTestnet}) async {
try {
final path = await pathForWallet(name: credentials.name, type: getType());
await monero_wallet_manager.createWallet(

View file

@ -28,7 +28,7 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
WalletType getType() => WalletType.nano;
@override
Future<WalletBase> create(NanoNewWalletCredentials credentials) async {
Future<WalletBase> create(NanoNewWalletCredentials credentials, {bool? isTestnet}) async {
// nano standard:
DerivationType derivationType = DerivationType.nano;
String seedKey = NanoSeeds.generateSeed();

View file

@ -105,6 +105,16 @@ class CWBitcoin extends Bitcoin {
return bitcoinWallet.walletAddresses.address;
}
String getReceiveAddress(Object wallet) {
final bitcoinWallet = wallet as ElectrumWallet;
return bitcoinWallet.walletAddresses.receiveAddress;
}
btc.SilentPaymentAddress? getSilentAddress(Object wallet) {
final bitcoinWallet = wallet as ElectrumWallet;
return bitcoinWallet.walletAddresses.silentAddress;
}
@override
String formatterBitcoinAmountToString({required int amount})
=> bitcoinAmountToString(amount: amount);

View file

@ -25,7 +25,10 @@ class AddressValidator extends TextValidator {
return '^[0-9a-zA-Z]{59}\$|^[0-9a-zA-Z]{92}\$|^[0-9a-zA-Z]{104}\$'
'|^[0-9a-zA-Z]{105}\$|^addr1[0-9a-zA-Z]{98}\$';
case CryptoCurrency.btc:
return '^3[0-9a-zA-Z]{32}\$|^3[0-9a-zA-Z]{33}\$|^bc1[0-9a-zA-Z]{59}\$';
final p2sh = '^3[0-9a-zA-Z]{32}\$|^3[0-9a-zA-Z]{33}\$';
final testnet = '^tb1[0-9a-zA-Z]{59}\$';
final silentpayments = '^sprt1[0-9a-zA-Z]{113}\$|^sp1[0-9a-zA-Z]{113}\$|^tsp1[0-9a-zA-Z]{113}\$';
return '^bc1[0-9a-zA-Z]{59}\$|$p2sh|$testnet|$silentpayments';
case CryptoCurrency.nano:
return '[0-9a-zA-Z_]';
case CryptoCurrency.banano:

View file

@ -49,7 +49,7 @@ class WalletCreationService {
}
}
Future<WalletBase> create(WalletCredentials credentials) async {
Future<WalletBase> create(WalletCredentials credentials, {bool? isTestnet}) async {
checkIfExists(credentials.name);
if (credentials.password == null) {
@ -58,7 +58,7 @@ class WalletCreationService {
password: credentials.password!, walletName: credentials.name);
}
final wallet = await _service!.create(credentials);
final wallet = await _service!.create(credentials, isTestnet: isTestnet);
if (wallet.type == WalletType.monero) {
await sharedPreferences.setBool(

View file

@ -1148,7 +1148,7 @@ Future<void> setup({
IoniaPaymentStatusPage(
getIt.get<IoniaPaymentStatusViewModel>(param1: paymentInfo, param2: committedInfo)));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, void Function(), void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactoryParam<WalletUnlockLoadableViewModel, WalletUnlockArguments, void>((args, _) {

123
lib/nano/nano.dart Normal file
View file

@ -0,0 +1,123 @@
import 'package:cw_core/cake_hive.dart';
import 'package:cw_core/nano_account.dart';
import 'package:cw_core/account.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/output_info.dart';
import 'package:cw_core/nano_account_info_response.dart';
import 'package:mobx/mobx.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_nano/nano_client.dart';
import 'package:cw_nano/nano_mnemonic.dart';
import 'package:cw_nano/nano_wallet.dart';
import 'package:cw_nano/nano_wallet_service.dart';
import 'package:cw_nano/nano_transaction_info.dart';
import 'package:cw_nano/nano_transaction_credentials.dart';
import 'package:cw_nano/nano_wallet_creation_credentials.dart';
// needed for nano_util:
import 'dart:convert';
import 'dart:typed_data';
import 'package:convert/convert.dart';
import "package:ed25519_hd_key/ed25519_hd_key.dart";
import 'package:libcrypto/libcrypto.dart';
import 'package:nanodart/nanodart.dart' as ND;
import 'package:decimal/decimal.dart';
part 'cw_nano.dart';
Nano? nano = CWNano();
NanoUtil? nanoUtil = CWNanoUtil();
abstract class Nano {
NanoAccountList getAccountList(Object wallet);
Account getCurrentAccount(Object wallet);
void setCurrentAccount(Object wallet, int id, String label, String? balance);
WalletService createNanoWalletService(Box<WalletInfo> walletInfoSource, bool isDirect);
WalletCredentials createNanoNewWalletCredentials({
required String name,
String? password,
});
WalletCredentials createNanoRestoreWalletFromSeedCredentials({
required String name,
required String password,
required String mnemonic,
DerivationType? derivationType,
});
WalletCredentials createNanoRestoreWalletFromKeysCredentials({
required String name,
required String password,
required String seedKey,
DerivationType? derivationType,
});
List<String> getNanoWordList(String language);
Map<String, String> getKeys(Object wallet);
Object createNanoTransactionCredentials(List<Output> outputs);
Future<void> changeRep(Object wallet, String address);
Future<void> updateTransactions(Object wallet);
BigInt getTransactionAmountRaw(TransactionInfo transactionInfo);
}
abstract class NanoAccountList {
ObservableList<NanoAccount> get accounts;
void update(Object wallet);
void refresh(Object wallet);
Future<List<NanoAccount>> getAll(Object wallet);
Future<void> addAccount(Object wallet, {required String label});
Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
}
abstract class NanoUtil {
String seedToPrivate(String seed, int index);
String seedToAddress(String seed, int index);
String seedToMnemonic(String seed);
Future<String> mnemonicToSeed(String mnemonic);
String privateKeyToPublic(String privateKey);
String addressToPublicKey(String publicAddress);
String privateKeyToAddress(String privateKey);
String publicKeyToAddress(String publicKey);
bool isValidSeed(String seed);
Future<String> hdMnemonicListToSeed(List<String> words);
Future<String> hdSeedToPrivate(String seed, int index);
Future<String> hdSeedToAddress(String seed, int index);
Future<String> uniSeedToAddress(String seed, int index, String type);
Future<String> uniSeedToPrivate(String seed, int index, String type);
bool isValidBip39Seed(String seed);
static const int maxDecimalDigits = 6; // Max digits after decimal
BigInt rawPerNano = BigInt.parse("1000000000000000000000000000000");
BigInt rawPerNyano = BigInt.parse("1000000000000000000000000");
BigInt rawPerBanano = BigInt.parse("100000000000000000000000000000");
BigInt rawPerXMR = BigInt.parse("1000000000000");
BigInt convertXMRtoNano = BigInt.parse("1000000000000000000");
Decimal getRawAsDecimal(String? raw, BigInt? rawPerCur);
String truncateDecimal(Decimal input, {int digits = maxDecimalDigits});
String getRawAsUsableString(String? raw, BigInt rawPerCur);
String getRawAccuracy(String? raw, BigInt rawPerCur);
String getAmountAsRaw(String amount, BigInt rawPerCur);
// derivationInfo:
Future<AccountInfoResponse?> getInfoFromSeedOrMnemonic(
DerivationType derivationType, {
String? seedKey,
String? mnemonic,
required Node node,
});
Future<List<DerivationType>> compareDerivationMethods({
String? mnemonic,
String? privateKey,
required Node node,
});
}

View file

@ -559,11 +559,13 @@ Route<dynamic> createRoute(RouteSettings settings) {
builder: (_) => getIt.get<WebViewPage>(param1: title, param2: url));
case Routes.advancedPrivacySettings:
final type = settings.arguments as WalletType;
final args = settings.arguments as List;
final type = args.first as WalletType;
final func = args[1] as void Function();
return CupertinoPageRoute<void>(
builder: (_) => AdvancedPrivacySettingsPage(
getIt.get<AdvancedPrivacySettingsViewModel>(param1: type),
getIt.get<AdvancedPrivacySettingsViewModel>(param1: func),
getIt.get<NodeCreateOrEditViewModel>(param1: type, param2: false),
));

View file

@ -152,8 +152,7 @@ class AddressPage extends BasePage {
return GestureDetector(
onTap: () async => dashboardViewModel.isAutoGenerateSubaddressesEnabled
? await showPopUp<void>(
context: context,
builder: (_) => getIt.get<MoneroAccountListPage>())
context: context, builder: (_) => getIt.get<MoneroAccountListPage>())
: Navigator.of(context).pushNamed(Routes.receive),
child: Container(
height: 50,
@ -174,7 +173,9 @@ class AddressPage extends BasePage {
children: <Widget>[
Observer(
builder: (_) {
String label = addressListViewModel.hasAccounts
String label = addressListViewModel.hasSilentAddresses
? S.of(context).address_and_silent_addresses
: addressListViewModel.hasAccounts
? S.of(context).accounts_subaddresses
: S.of(context).addresses;
@ -192,7 +193,8 @@ class AddressPage extends BasePage {
.extension<SyncIndicatorTheme>()!
.textColor),
);
},),
},
),
Icon(
Icons.arrow_forward_ios,
size: 14,
@ -202,7 +204,8 @@ class AddressPage extends BasePage {
),
),
);
} else if (dashboardViewModel.isAutoGenerateSubaddressesEnabled || addressListViewModel.showElectrumAddressDisclaimer) {
} else if (dashboardViewModel.isAutoGenerateSubaddressesEnabled ||
addressListViewModel.showElectrumAddressDisclaimer) {
return Text(S.of(context).electrum_address_disclaimer,
textAlign: TextAlign.center,
style: TextStyle(

View file

@ -75,6 +75,18 @@ class _AdvancedPrivacySettingsBodyState extends State<AdvancedPrivacySettingsBod
),
);
}),
if (widget.nodeViewModel.hasTestnetSupport)
Observer(builder: (_) {
return Column(
children: [
SettingsSwitcherCell(
title: S.current.use_testnet,
value: widget.privacySettingsViewModel.useTestnet,
onValueChange: (_, __) => widget.privacySettingsViewModel.toggleUseTestnet(),
),
],
);
}),
Observer(builder: (_) {
return Column(
children: [

View file

@ -297,8 +297,8 @@ class _WalletNameFormState extends State<WalletNameForm> {
const SizedBox(height: 25),
GestureDetector(
onTap: () {
Navigator.of(context)
.pushNamed(Routes.advancedPrivacySettings, arguments: _walletNewVM.type);
Navigator.of(context).pushNamed(Routes.advancedPrivacySettings,
arguments: [_walletNewVM.type, _walletNewVM.toggleUseTestnet]);
},
child: Text(S.of(context).advanced_privacy_settings),
),

View file

@ -67,8 +67,7 @@ class ReceivePage extends BasePage {
@override
Widget Function(BuildContext, Widget) get rootWrapper =>
(BuildContext context, Widget scaffold) =>
GradientBackground(scaffold: scaffold);
(BuildContext context, Widget scaffold) => GradientBackground(scaffold: scaffold);
@override
Widget trailing(BuildContext context) {
@ -99,7 +98,8 @@ class ReceivePage extends BasePage {
@override
Widget body(BuildContext context) {
return (addressListViewModel.type == WalletType.monero ||
return (addressListViewModel.type == WalletType.bitcoin ||
addressListViewModel.type == WalletType.monero ||
addressListViewModel.type == WalletType.haven ||
addressListViewModel.type == WalletType.nano ||
addressListViewModel.type == WalletType.banano)
@ -156,7 +156,8 @@ class ReceivePage extends BasePage {
icon: Icon(
Icons.arrow_forward_ios,
size: 14,
color: Theme.of(context).extension<ReceivePageTheme>()!.iconsColor,
color:
Theme.of(context).extension<ReceivePageTheme>()!.iconsColor,
));
}
@ -164,11 +165,12 @@ class ReceivePage extends BasePage {
cell = HeaderTile(
onTap: () =>
Navigator.of(context).pushNamed(Routes.newSubaddress),
title: S.of(context).addresses,
title: S.of(context).silent_addresses,
icon: Icon(
Icons.add,
size: 20,
color: Theme.of(context).extension<ReceivePageTheme>()!.iconsColor,
color:
Theme.of(context).extension<ReceivePageTheme>()!.iconsColor,
));
}
@ -177,11 +179,19 @@ class ReceivePage extends BasePage {
final isCurrent =
item.address == addressListViewModel.address.address;
final backgroundColor = isCurrent
? Theme.of(context).extension<ReceivePageTheme>()!.currentTileBackgroundColor
: Theme.of(context).extension<ReceivePageTheme>()!.tilesBackgroundColor;
? Theme.of(context)
.extension<ReceivePageTheme>()!
.currentTileBackgroundColor
: Theme.of(context)
.extension<ReceivePageTheme>()!
.tilesBackgroundColor;
final textColor = isCurrent
? Theme.of(context).extension<ReceivePageTheme>()!.currentTileTextColor
: Theme.of(context).extension<ReceivePageTheme>()!.tilesTextColor;
? Theme.of(context)
.extension<ReceivePageTheme>()!
.currentTileTextColor
: Theme.of(context)
.extension<ReceivePageTheme>()!
.tilesTextColor;
return AddressCell.fromItem(item,
isCurrent: isCurrent,
@ -202,6 +212,15 @@ class ReceivePage extends BasePage {
child: cell,
);
})),
Padding(
padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
child: Text(S.of(context).electrum_address_disclaimer,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color:
Theme.of(context).extension<BalancePageTheme>()!.labelTextColor)),
),
],
),
))

View file

@ -2,7 +2,7 @@ import 'package:cake_wallet/core/seed_validator.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
class Annotation extends Comparable<Annotation> {
class Annotation implements Comparable<Annotation> {
Annotation({required this.range, required this.style});
final TextRange range;

View file

@ -1,7 +1,6 @@
import 'package:cake_wallet/entities/exchange_api_mode.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
part 'advanced_privacy_settings_view_model.g.dart';
@ -10,7 +9,8 @@ class AdvancedPrivacySettingsViewModel = AdvancedPrivacySettingsViewModelBase
with _$AdvancedPrivacySettingsViewModel;
abstract class AdvancedPrivacySettingsViewModelBase with Store {
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore) : _addCustomNode = false;
AdvancedPrivacySettingsViewModelBase(this.changeUseTestnet, this._settingsStore)
: _addCustomNode = false;
@computed
ExchangeApiMode get exchangeStatus => _settingsStore.exchangeStatus;
@ -21,13 +21,20 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
@observable
bool _addCustomNode = false;
final WalletType type;
@observable
bool _useTestnet = false;
// TODO: electrum's node as default for testnet
final void Function() changeUseTestnet;
final SettingsStore _settingsStore;
@computed
bool get addCustomNode => _addCustomNode;
@computed
bool get useTestnet => _useTestnet;
@action
void setFiatApiMode(FiatApiMode fiatApiMode) => _settingsStore.fiatApiMode = fiatApiMode;
@ -36,4 +43,10 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
@action
void toggleAddCustomNode() => _addCustomNode = !_addCustomNode;
@action
void toggleUseTestnet() {
_useTestnet = !_useTestnet;
changeUseTestnet();
}
}

View file

@ -62,6 +62,8 @@ abstract class NodeCreateOrEditViewModelBase with Store {
bool get hasAuthCredentials =>
_walletType == WalletType.monero || _walletType == WalletType.haven;
bool get hasTestnetSupport => _walletType == WalletType.bitcoin;
String get uri {
var uri = address;

View file

@ -131,8 +131,9 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
}) : _baseItems = <ListItem>[],
selectedCurrency = walletTypeToCryptoCurrency(appStore.wallet!.type),
_cryptoNumberFormat = NumberFormat(_cryptoNumberPattern),
hasAccounts =
appStore.wallet!.type == WalletType.monero || appStore.wallet!.type == WalletType.haven,
hasAccounts = appStore.wallet!.type == WalletType.bitcoin ||
appStore.wallet!.type == WalletType.monero ||
appStore.wallet!.type == WalletType.haven,
amount = '',
super(appStore: appStore) {
_init();
@ -143,7 +144,9 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
_init();
selectedCurrency = walletTypeToCryptoCurrency(wallet.type);
hasAccounts = wallet.type == WalletType.monero || wallet.type == WalletType.haven;
hasAccounts = wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.monero ||
wallet.type == WalletType.haven;
}
static const String _cryptoNumberPattern = '0.00000000';
@ -237,9 +240,10 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
}
if (wallet.type == WalletType.bitcoin) {
final primaryAddress = bitcoin!.getAddress(wallet);
final bitcoinAddresses = bitcoin!.getAddresses(wallet).map((addr) {
final isPrimary = addr == primaryAddress;
final receiveAddress = bitcoin!.getReceiveAddress(wallet);
final silentAddress = bitcoin!.getSilentAddress(wallet).toString();
final bitcoinAddresses = [receiveAddress, silentAddress].map((addr) {
final isPrimary = addr == receiveAddress;
return WalletAddressListItem(isPrimary: isPrimary, name: null, address: addr);
});
@ -271,10 +275,16 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
return '';
}
@computed
bool get hasSilentAddresses => wallet.type == WalletType.bitcoin;
@computed
bool get hasAddressList =>
wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.monero ||
wallet.type == WalletType.haven;/* ||
wallet.type ==
WalletType
.haven; /* ||
wallet.type == WalletType.nano ||
wallet.type == WalletType.banano;*/ // TODO: nano accounts are disabled for now
@ -294,9 +304,12 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
_baseItems = [];
if (wallet.type == WalletType.monero ||
wallet.type == WalletType.haven /*||
wallet.type ==
WalletType
.haven /*||
wallet.type == WalletType.nano ||
wallet.type == WalletType.banano*/) {
wallet.type == WalletType.banano*/
) {
_baseItems.add(WalletAccountListHeader());
}

View file

@ -49,7 +49,7 @@ abstract class WalletCreationVMBase with Store {
bool typeExists(WalletType type) => walletCreationService.typeExists(type);
Future<void> create({dynamic options, RestoredWallet? restoreWallet}) async {
Future<void> create({dynamic options, RestoredWallet? restoreWallet, bool? isTestnet}) async {
final type = restoreWallet?.type ?? this.type;
try {
state = IsExecutingState();

View file

@ -24,6 +24,12 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
: selectedMnemonicLanguage = '',
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false);
@observable
bool _useTestnet = false;
@computed
bool get useTestnet => _useTestnet;
@observable
String selectedMnemonicLanguage;
@ -54,6 +60,9 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
@override
Future<WalletBase> process(WalletCredentials credentials) async {
walletCreationService.changeWalletType(type: type);
return walletCreationService.create(credentials);
return walletCreationService.create(credentials, isTestnet: useTestnet);
}
@action
void toggleUseTestnet() => _useTestnet = !_useTestnet;
}

View file

@ -87,7 +87,7 @@ dependencies:
bitcoin_flutter:
git:
url: https://github.com/cake-tech/bitcoin_flutter.git
ref: cake-update-v3
ref: silent-payments
dev_dependencies:
flutter_test:

View file

@ -723,5 +723,8 @@
"message": "ﺔﻟﺎﺳﺭ",
"do_not_have_enough_gas_asset": "ليس لديك ما يكفي من ${currency} لإجراء معاملة وفقًا لشروط شبكة blockchain الحالية. أنت بحاجة إلى المزيد من ${currency} لدفع رسوم شبكة blockchain، حتى لو كنت ترسل أصلًا مختلفًا.",
"totp_auth_url": "TOTP ﺔﻗﺩﺎﺼﻤﻟ URL ﻥﺍﻮﻨﻋ",
"awaitDAppProcessing": ".ﺔﺠﻟﺎﻌﻤﻟﺍ ﻦﻣ dApp ﻲﻬﺘﻨﻳ ﻰﺘﺣ ﺭﺎﻈﺘﻧﻻﺍ ﻰﺟﺮﻳ"
"awaitDAppProcessing": ".ﺔﺠﻟﺎﻌﻤﻟﺍ ﻦﻣ dApp ﻲﻬﺘﻨﻳ ﻰﺘﺣ ﺭﺎﻈﺘﻧﻻﺍ ﻰﺟﺮﻳ",
"use_testnet": "استخدم testnet",
"address_and_silent_addresses": "العنوان والعناوين الصامتة",
"silent_addresses": "عناوين صامتة"
}

View file

@ -719,5 +719,8 @@
"message": "Съобщение",
"do_not_have_enough_gas_asset": "Нямате достатъчно ${currency}, за да извършите транзакция с текущите условия на блокчейн мрежата. Имате нужда от повече ${currency}, за да платите таксите за блокчейн мрежа, дори ако изпращате различен актив.",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "Моля, изчакайте dApp да завърши обработката."
"awaitDAppProcessing": "Моля, изчакайте dApp да завърши обработката.",
"use_testnet": "Използвайте TestNet",
"address_and_silent_addresses": "Адрес и мълчаливи адреси",
"silent_addresses": "Безшумни адреси"
}

View file

@ -719,5 +719,8 @@
"message": "Zpráva",
"do_not_have_enough_gas_asset": "Nemáte dostatek ${currency} k provedení transakce s aktuálními podmínkami blockchainové sítě. K placení poplatků za blockchainovou síť potřebujete více ${currency}, i když posíláte jiné aktivum.",
"totp_auth_url": "URL AUTH TOTP",
"awaitDAppProcessing": "Počkejte, až dApp dokončí zpracování."
"awaitDAppProcessing": "Počkejte, až dApp dokončí zpracování.",
"use_testnet": "Použijte testNet",
"address_and_silent_addresses": "Adresa a tiché adresy",
"silent_addresses": "Tiché adresy"
}

View file

@ -727,5 +727,8 @@
"message": "Nachricht",
"do_not_have_enough_gas_asset": "Sie verfügen nicht über genügend ${currency}, um eine Transaktion unter den aktuellen Bedingungen des Blockchain-Netzwerks durchzuführen. Sie benötigen mehr ${currency}, um die Gebühren für das Blockchain-Netzwerk zu bezahlen, auch wenn Sie einen anderen Vermögenswert senden.",
"totp_auth_url": "TOTP-Auth-URL",
"awaitDAppProcessing": "Bitte warten Sie, bis die dApp die Verarbeitung abgeschlossen hat."
"awaitDAppProcessing": "Bitte warten Sie, bis die dApp die Verarbeitung abgeschlossen hat.",
"use_testnet": "TESTNET verwenden",
"address_and_silent_addresses": "Adresse und stille Adressen",
"silent_addresses": "Stille Adressen"
}

View file

@ -728,5 +728,8 @@
"message": "Message",
"do_not_have_enough_gas_asset": "You do not have enough ${currency} to make a transaction with the current blockchain network conditions. You need more ${currency} to pay blockchain network fees, even if you are sending a different asset.",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "Kindly wait for the dApp to finish processing."
"awaitDAppProcessing": "Kindly wait for the dApp to finish processing.",
"use_testnet": "Use testnet",
"address_and_silent_addresses": "Address and Silent Addresses",
"silent_addresses": "Silent Addresses"
}

View file

@ -727,5 +727,8 @@
"message": "Mensaje",
"do_not_have_enough_gas_asset": "No tienes suficiente ${currency} para realizar una transacción con las condiciones actuales de la red blockchain. Necesita más ${currency} para pagar las tarifas de la red blockchain, incluso si envía un activo diferente.",
"totp_auth_url": "URL de autenticación TOTP",
"awaitDAppProcessing": "Espere a que la dApp termine de procesarse."
"awaitDAppProcessing": "Espere a que la dApp termine de procesarse.",
"use_testnet": "Use TestNet",
"address_and_silent_addresses": "Dirección y direcciones silenciosas",
"silent_addresses": "Direcciones silenciosas"
}

View file

@ -727,5 +727,8 @@
"message": "Message",
"do_not_have_enough_gas_asset": "Vous n'avez pas assez de ${currency} pour effectuer une transaction avec les conditions actuelles du réseau blockchain. Vous avez besoin de plus de ${currency} pour payer les frais du réseau blockchain, même si vous envoyez un actif différent.",
"totp_auth_url": "URL D'AUTORISATION TOTP",
"awaitDAppProcessing": "Veuillez attendre que le dApp termine le traitement."
"awaitDAppProcessing": "Veuillez attendre que le dApp termine le traitement.",
"use_testnet": "Utiliser TestNet",
"address_and_silent_addresses": "Adresse et adresses silencieuses",
"silent_addresses": "Adresses silencieuses"
}

View file

@ -705,5 +705,8 @@
"message": "Sako",
"do_not_have_enough_gas_asset": "Ba ku da isassun ${currency} don yin ma'amala tare da yanayin cibiyar sadarwar blockchain na yanzu. Kuna buƙatar ƙarin ${currency} don biyan kuɗaɗen cibiyar sadarwar blockchain, koda kuwa kuna aika wata kadara daban.",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "Da fatan za a jira dApp ya gama aiki."
"awaitDAppProcessing": "Da fatan za a jira dApp ya gama aiki.",
"use_testnet": "Amfani da gwaji",
"address_and_silent_addresses": "Adireshin da adreshin shiru",
"silent_addresses": "Adireshin Shiru"
}

View file

@ -727,5 +727,8 @@
"message": "संदेश",
"do_not_have_enough_gas_asset": "वर्तमान ब्लॉकचेन नेटवर्क स्थितियों में लेनदेन करने के लिए आपके पास पर्याप्त ${currency} नहीं है। ब्लॉकचेन नेटवर्क शुल्क का भुगतान करने के लिए आपको अधिक ${currency} की आवश्यकता है, भले ही आप एक अलग संपत्ति भेज रहे हों।",
"totp_auth_url": "TOTP प्रामाणिक यूआरएल",
"awaitDAppProcessing": "कृपया डीएपी की प्रोसेसिंग पूरी होने तक प्रतीक्षा करें।"
"awaitDAppProcessing": "कृपया डीएपी की प्रोसेसिंग पूरी होने तक प्रतीक्षा करें।",
"use_testnet": "टेस्टनेट का उपयोग करें",
"address_and_silent_addresses": "पता और मूक पते",
"silent_addresses": "मूक पते"
}

View file

@ -725,5 +725,8 @@
"message": "Poruka",
"do_not_have_enough_gas_asset": "Nemate dovoljno ${currency} da izvršite transakciju s trenutačnim uvjetima blockchain mreže. Trebate više ${currency} da platite naknade za blockchain mrežu, čak i ako šaljete drugu imovinu.",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "Molimo pričekajte da dApp završi obradu."
"awaitDAppProcessing": "Molimo pričekajte da dApp završi obradu.",
"use_testnet": "Koristite TestNet",
"address_and_silent_addresses": "Adresa i tihe adrese",
"silent_addresses": "Tihe adrese"
}

View file

@ -715,5 +715,8 @@
"message": "Pesan",
"do_not_have_enough_gas_asset": "Anda tidak memiliki cukup ${currency} untuk melakukan transaksi dengan kondisi jaringan blockchain saat ini. Anda memerlukan lebih banyak ${currency} untuk membayar biaya jaringan blockchain, meskipun Anda mengirimkan aset yang berbeda.",
"totp_auth_url": "URL Otentikasi TOTP",
"awaitDAppProcessing": "Mohon tunggu hingga dApp menyelesaikan pemrosesan."
"awaitDAppProcessing": "Mohon tunggu hingga dApp menyelesaikan pemrosesan.",
"use_testnet": "Gunakan TestNet",
"address_and_silent_addresses": "Alamat dan alamat diam",
"silent_addresses": "Alamat diam"
}

View file

@ -727,5 +727,8 @@
"message": "Messaggio",
"do_not_have_enough_gas_asset": "Non hai abbastanza ${currency} per effettuare una transazione con le attuali condizioni della rete blockchain. Hai bisogno di più ${currency} per pagare le commissioni della rete blockchain, anche se stai inviando una risorsa diversa.",
"totp_auth_url": "URL DI AUT. TOTP",
"awaitDAppProcessing": "Attendi gentilmente che la dApp termini l'elaborazione."
"awaitDAppProcessing": "Attendi gentilmente che la dApp termini l'elaborazione.",
"use_testnet": "Usa TestNet",
"address_and_silent_addresses": "Indirizzo e indirizzi silenziosi",
"silent_addresses": "Indirizzi silenziosi"
}

View file

@ -727,5 +727,8 @@
"message": "メッセージ",
"do_not_have_enough_gas_asset": "現在のブロックチェーン ネットワークの状況では、トランザクションを行うのに十分な ${currency} がありません。別のアセットを送信する場合でも、ブロックチェーン ネットワーク料金を支払うにはさらに ${currency} が必要です。",
"totp_auth_url": "TOTP認証URL",
"awaitDAppProcessing": "dAppの処理が完了するまでお待ちください。"
"awaitDAppProcessing": "dAppの処理が完了するまでお待ちください。",
"use_testnet": "TestNetを使用します",
"address_and_silent_addresses": "住所とサイレントアドレス",
"silent_addresses": "サイレントアドレス"
}

View file

@ -725,5 +725,8 @@
"message": "메시지",
"do_not_have_enough_gas_asset": "현재 블록체인 네트워크 조건으로 거래를 하기에는 ${currency}이(가) 충분하지 않습니다. 다른 자산을 보내더라도 블록체인 네트워크 수수료를 지불하려면 ${currency}가 더 필요합니다.",
"totp_auth_url": "TOTP 인증 URL",
"awaitDAppProcessing": "dApp이 처리를 마칠 때까지 기다려주세요."
"awaitDAppProcessing": "dApp이 처리를 마칠 때까지 기다려주세요.",
"use_testnet": "TestNet을 사용하십시오",
"address_and_silent_addresses": "주소 및 조용한 주소",
"silent_addresses": "조용한 주소"
}

View file

@ -725,5 +725,8 @@
"message": "မက်ဆေ့ချ်",
"do_not_have_enough_gas_asset": "လက်ရှိ blockchain ကွန်ရက်အခြေအနေများနှင့် အရောင်းအဝယ်ပြုလုပ်ရန် သင့်တွင် ${currency} လုံလောက်မှုမရှိပါ။ သင်သည် မတူညီသော ပိုင်ဆိုင်မှုတစ်ခုကို ပေးပို့နေသော်လည်း blockchain ကွန်ရက်အခကြေးငွေကို ပေးဆောင်ရန် သင်သည် နောက်ထပ် ${currency} လိုအပ်ပါသည်။",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "ကျေးဇူးပြု၍ dApp ကို စီမံလုပ်ဆောင်ခြင်း အပြီးသတ်ရန် စောင့်ပါ။"
"awaitDAppProcessing": "ကျေးဇူးပြု၍ dApp ကို စီမံလုပ်ဆောင်ခြင်း အပြီးသတ်ရန် စောင့်ပါ။",
"use_testnet": "testnet ကိုသုံးပါ",
"address_and_silent_addresses": "လိပ်စာနှင့်အသံတိတ်လိပ်စာများ",
"silent_addresses": "အသံတိတ်လိပ်စာများ"
}

View file

@ -727,5 +727,8 @@
"message": "Bericht",
"do_not_have_enough_gas_asset": "U heeft niet genoeg ${currency} om een transactie uit te voeren met de huidige blockchain-netwerkomstandigheden. U heeft meer ${currency} nodig om blockchain-netwerkkosten te betalen, zelfs als u een ander item verzendt.",
"totp_auth_url": "TOTP AUTH-URL",
"awaitDAppProcessing": "Wacht tot de dApp klaar is met verwerken."
"awaitDAppProcessing": "Wacht tot de dApp klaar is met verwerken.",
"use_testnet": "Gebruik testnet",
"address_and_silent_addresses": "Adres en stille adressen",
"silent_addresses": "Stille adressen"
}

View file

@ -727,5 +727,8 @@
"message": "Wiadomość",
"do_not_have_enough_gas_asset": "Nie masz wystarczającej ilości ${currency}, aby dokonać transakcji przy bieżących warunkach sieci blockchain. Potrzebujesz więcej ${currency}, aby uiścić opłaty za sieć blockchain, nawet jeśli wysyłasz inny zasób.",
"totp_auth_url": "Adres URL TOTP AUTH",
"awaitDAppProcessing": "Poczekaj, aż dApp zakończy przetwarzanie."
"awaitDAppProcessing": "Poczekaj, aż dApp zakończy przetwarzanie.",
"use_testnet": "Użyj testne",
"address_and_silent_addresses": "Adres i ciche adresy",
"silent_addresses": "Ciche adresy"
}

View file

@ -726,5 +726,8 @@
"message": "Mensagem",
"do_not_have_enough_gas_asset": "Você não tem ${currency} suficiente para fazer uma transação com as condições atuais da rede blockchain. Você precisa de mais ${currency} para pagar as taxas da rede blockchain, mesmo se estiver enviando um ativo diferente.",
"totp_auth_url": "URL de autenticação TOTP",
"awaitDAppProcessing": "Aguarde até que o dApp termine o processamento."
"awaitDAppProcessing": "Aguarde até que o dApp termine o processamento.",
"use_testnet": "Use testNet",
"address_and_silent_addresses": "Endereço e endereços silenciosos",
"silent_addresses": "Endereços silenciosos"
}

View file

@ -727,5 +727,8 @@
"message": "Сообщение",
"do_not_have_enough_gas_asset": "У вас недостаточно ${currency} для совершения транзакции при текущих условиях сети блокчейн. Вам нужно больше ${currency} для оплаты комиссий за сеть блокчейна, даже если вы отправляете другой актив.",
"totp_auth_url": "URL-адрес TOTP-АВТОРИЗАЦИИ",
"awaitDAppProcessing": "Пожалуйста, подождите, пока dApp завершит обработку."
"awaitDAppProcessing": "Пожалуйста, подождите, пока dApp завершит обработку.",
"use_testnet": "Используйте Testnet",
"address_and_silent_addresses": "Адрес и молчаливые адреса",
"silent_addresses": "Молчаливые адреса"
}

View file

@ -725,5 +725,8 @@
"message": "ข้อความ",
"do_not_have_enough_gas_asset": "คุณมี ${currency} ไม่เพียงพอที่จะทำธุรกรรมกับเงื่อนไขเครือข่ายบล็อคเชนในปัจจุบัน คุณต้องมี ${currency} เพิ่มขึ้นเพื่อชำระค่าธรรมเนียมเครือข่ายบล็อคเชน แม้ว่าคุณจะส่งสินทรัพย์อื่นก็ตาม",
"totp_auth_url": "URL การตรวจสอบสิทธิ์ TOTP",
"awaitDAppProcessing": "โปรดรอให้ dApp ประมวลผลเสร็จสิ้น"
"awaitDAppProcessing": "โปรดรอให้ dApp ประมวลผลเสร็จสิ้น",
"use_testnet": "ใช้ testnet",
"address_and_silent_addresses": "ที่อยู่และที่อยู่เงียบ",
"silent_addresses": "ที่อยู่เงียบ"
}

View file

@ -725,5 +725,8 @@
"message": "İleti",
"do_not_have_enough_gas_asset": "Mevcut blockchain ağ koşullarıyla işlem yapmak için yeterli ${currency} paranız yok. Farklı bir varlık gönderiyor olsanız bile blockchain ağ ücretlerini ödemek için daha fazla ${currency} miktarına ihtiyacınız var.",
"totp_auth_url": "TOTP YETKİ URL'si",
"awaitDAppProcessing": "Lütfen dApp'in işlemeyi bitirmesini bekleyin."
"awaitDAppProcessing": "Lütfen dApp'in işlemeyi bitirmesini bekleyin.",
"use_testnet": "TestNet kullanın",
"address_and_silent_addresses": "Adres ve sessiz adresler",
"silent_addresses": "Sessiz adresler"
}

View file

@ -727,5 +727,8 @@
"message": "повідомлення",
"do_not_have_enough_gas_asset": "У вас недостатньо ${currency}, щоб здійснити трансакцію з поточними умовами мережі блокчейн. Вам потрібно більше ${currency}, щоб сплатити комісію мережі блокчейн, навіть якщо ви надсилаєте інший актив.",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "Зачекайте, доки dApp завершить обробку."
"awaitDAppProcessing": "Зачекайте, доки dApp завершить обробку.",
"use_testnet": "Використовуйте тестову мережу",
"address_and_silent_addresses": "Адреса та мовчазні адреси",
"silent_addresses": "Мовчазні адреси"
}

View file

@ -719,5 +719,8 @@
"message": "ﻡﺎﻐﯿﭘ",
"do_not_have_enough_gas_asset": "آپ کے پاس موجودہ بلاکچین نیٹ ورک کی شرائط کے ساتھ لین دین کرنے کے لیے کافی ${currency} نہیں ہے۔ آپ کو بلاکچین نیٹ ورک کی فیس ادا کرنے کے لیے مزید ${currency} کی ضرورت ہے، چاہے آپ کوئی مختلف اثاثہ بھیج رہے ہوں۔",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "۔ﮟﯾﺮﮐ ﺭﺎﻈﺘﻧﺍ ﺎﮐ ﮯﻧﻮﮨ ﻞﻤﮑﻣ ﮓﻨﺴﯿﺳﻭﺮﭘ ﮯﮐ dApp ﻡﺮﮐ ﮦﺍﺮﺑ"
"awaitDAppProcessing": "۔ﮟﯾﺮﮐ ﺭﺎﻈﺘﻧﺍ ﺎﮐ ﮯﻧﻮﮨ ﻞﻤﮑﻣ ﮓﻨﺴﯿﺳﻭﺮﭘ ﮯﮐ dApp ﻡﺮﮐ ﮦﺍﺮﺑ",
"use_testnet": "ٹیسٹ نیٹ استعمال کریں",
"address_and_silent_addresses": "پتہ اور خاموش پتے",
"silent_addresses": "خاموش پتے"
}

View file

@ -721,5 +721,8 @@
"message": "Ifiranṣẹ",
"do_not_have_enough_gas_asset": "O ko ni to ${currency} lati ṣe idunadura kan pẹlu awọn ipo nẹtiwọki blockchain lọwọlọwọ. O nilo diẹ sii ${currency} lati san awọn owo nẹtiwọọki blockchain, paapaa ti o ba nfi dukia miiran ranṣẹ.",
"totp_auth_url": "TOTP AUTH URL",
"awaitDAppProcessing": "Fi inurere duro fun dApp lati pari sisẹ."
"awaitDAppProcessing": "Fi inurere duro fun dApp lati pari sisẹ.",
"use_testnet": "Lo tele",
"address_and_silent_addresses": "Adirẹsi ati awọn adirẹsi ipalọlọ",
"silent_addresses": "Awọn adirẹsi ipalọlọ"
}

View file

@ -726,5 +726,8 @@
"message": "信息",
"do_not_have_enough_gas_asset": "您没有足够的 ${currency} 来在当前的区块链网络条件下进行交易。即使您发送的是不同的资产,您也需要更多的 ${currency} 来支付区块链网络费用。",
"totp_auth_url": "TOTP 授权 URL",
"awaitDAppProcessing": "请等待 dApp 处理完成。"
"awaitDAppProcessing": "请等待 dApp 处理完成。",
"use_testnet": "使用TestNet",
"address_and_silent_addresses": "地址和无声地址",
"silent_addresses": "无声地址"
}

View file

@ -71,6 +71,7 @@ import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart';
import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cw_bitcoin/litecoin_wallet_service.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as btc;
""";
const bitcoinCwPart = "part 'cw_bitcoin.dart';";
const bitcoinContent = """
@ -93,6 +94,8 @@ abstract class Bitcoin {
List<String> getAddresses(Object wallet);
String getAddress(Object wallet);
String getReceiveAddress(Object wallet);
btc.SilentPaymentAddress? getSilentAddress(Object wallet);
String formatterBitcoinAmountToString({required int amount});
double formatterBitcoinAmountToDouble({required int amount});