Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 48 additions & 58 deletions lib/db/db_version_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ class DbVersionMigrator with WalletDB {
final count = await MainDB.instance.isar.addresses.count();
// add change/receiving tags to address labels
for (var i = 0; i < count; i += 50) {
final addresses =
await MainDB.instance.isar.addresses
.where()
.offset(i)
.limit(50)
.findAll();
final addresses = await MainDB.instance.isar.addresses
.where()
.offset(i)
.limit(50)
.findAll();

final List<isar_models.AddressLabel> labels = [];
for (final address in addresses) {
Expand Down Expand Up @@ -203,14 +202,13 @@ class DbVersionMigrator with WalletDB {

// update/create label if tags is not empty
if (tags != null) {
isar_models.AddressLabel? label =
await MainDB.instance.isar.addressLabels
.where()
.addressStringWalletIdEqualTo(
address.value,
address.walletId,
)
.findFirst();
isar_models.AddressLabel? label = await MainDB
.instance
.isar
.addressLabels
.where()
.addressStringWalletIdEqualTo(address.value, address.walletId)
.findFirst();
if (label == null) {
label = isar_models.AddressLabel(
walletId: address.walletId,
Expand Down Expand Up @@ -268,13 +266,12 @@ class DbVersionMigrator with WalletDB {
Bitcoincash(CryptoCurrencyNetwork.main).identifier ||
info.coinIdentifier ==
Bitcoincash(CryptoCurrencyNetwork.test).identifier) {
final ids =
await MainDB.instance
.getAddresses(walletId)
.filter()
.typeEqualTo(isar_models.AddressType.p2sh)
.idProperty()
.findAll();
final ids = await MainDB.instance
.getAddresses(walletId)
.filter()
.typeEqualTo(isar_models.AddressType.p2sh)
.idProperty()
.findAll();

await MainDB.instance.isar.writeTxn(() async {
await MainDB.instance.isar.addresses.deleteAll(ids);
Expand Down Expand Up @@ -421,17 +418,15 @@ class DbVersionMigrator with WalletDB {
walletId: walletId,
txid: tx.txid,
timestamp: tx.timestamp,
type:
isIncoming
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing,
type: isIncoming
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing,
subType: isar_models.TransactionSubType.none,
amount: tx.amount,
amountString:
Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: epic.fractionDigits,
).toJsonString(),
amountString: Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: epic.fractionDigits,
).toJsonString(),
fee: tx.fees,
height: tx.height,
isCancelled: tx.isCancelled,
Expand All @@ -453,14 +448,12 @@ class DbVersionMigrator with WalletDB {
publicKey: [],
derivationIndex: isIncoming ? rcvIndex : -1,
derivationPath: null,
type:
isIncoming
? isar_models.AddressType.mimbleWimble
: isar_models.AddressType.unknown,
subType:
isIncoming
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.unknown,
type: isIncoming
? isar_models.AddressType.mimbleWimble
: isar_models.AddressType.unknown,
subType: isIncoming
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.unknown,
);
transactionsData.add(Tuple2(iTx, address));
}
Expand Down Expand Up @@ -518,28 +511,25 @@ class DbVersionMigrator with WalletDB {
final crypto = AppConfig.getCryptoCurrencyFor(info.coinIdentifier)!;

for (var i = 0; i < count; i += 50) {
final txns =
await MainDB.instance
.getTransactions(walletId)
.offset(i)
.limit(50)
.findAll();
final txns = await MainDB.instance
.getTransactions(walletId)
.offset(i)
.limit(50)
.findAll();

// migrate amount to serialized amount string
final txnsData =
txns
.map(
(tx) => Tuple2(
tx
..amountString =
Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: crypto.fractionDigits,
).toJsonString(),
tx.address.value,
),
)
.toList();
final txnsData = txns
.map(
(tx) => Tuple2(
tx
..amountString = Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: crypto.fractionDigits,
).toJsonString(),
tx.address.value,
),
)
.toList();

// update db records
await MainDB.instance.addNewTransactionData(txnsData, walletId);
Expand Down
14 changes: 6 additions & 8 deletions lib/electrumx_rpc/cached_electrumx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ class CachedElectrumXClient {
required ElectrumXClient electrumXClient,
}) => CachedElectrumXClient(electrumXClient: electrumXClient);

String base64ToHex(String source) =>
base64Decode(
LineSplitter.split(source).join(),
).map((e) => e.toRadixString(16).padLeft(2, '0')).join();
String base64ToHex(String source) => base64Decode(
LineSplitter.split(source).join(),
).map((e) => e.toRadixString(16).padLeft(2, '0')).join();

String base64ToReverseHex(String source) =>
base64Decode(
LineSplitter.split(source).join(),
).reversed.map((e) => e.toRadixString(16).padLeft(2, '0')).join();
String base64ToReverseHex(String source) => base64Decode(
LineSplitter.split(source).join(),
).reversed.map((e) => e.toRadixString(16).padLeft(2, '0')).join();

/// Call electrumx getTransaction on a per coin basis, storing the result in local db if not already there.
///
Expand Down
20 changes: 10 additions & 10 deletions lib/models/balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class Balance {
}

String toJsonIgnoreCoin() => jsonEncode({
"total": total.toJsonString(),
"spendable": spendable.toJsonString(),
"blockedTotal": blockedTotal.toJsonString(),
"pendingSpendable": pendingSpendable.toJsonString(),
});
"total": total.toJsonString(),
"spendable": spendable.toJsonString(),
"blockedTotal": blockedTotal.toJsonString(),
"pendingSpendable": pendingSpendable.toJsonString(),
});

// need to fall back to parsing from int due to cached balances being previously
// stored as int values instead of Amounts
Expand Down Expand Up @@ -82,11 +82,11 @@ class Balance {
}

Map<String, dynamic> toMap() => {
"total": total,
"spendable": spendable,
"blockedTotal": blockedTotal,
"pendingSpendable": pendingSpendable,
};
"total": total,
"spendable": spendable,
"blockedTotal": blockedTotal,
"pendingSpendable": pendingSpendable,
};

@override
String toString() {
Expand Down
14 changes: 6 additions & 8 deletions lib/models/isar/models/blockchain_data/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,12 @@ class Transaction {
slateId: json["slateId"] as String?,
otherData: json["otherData"] as String?,
nonce: json["nonce"] as int?,
inputs:
List<String>.from(
json["inputs"] as List,
).map((e) => Input.fromJsonString(e)).toList(),
outputs:
List<String>.from(
json["outputs"] as List,
).map((e) => Output.fromJsonString(e)).toList(),
inputs: List<String>.from(
json["inputs"] as List,
).map((e) => Input.fromJsonString(e)).toList(),
outputs: List<String>.from(
json["outputs"] as List,
).map((e) => Output.fromJsonString(e)).toList(),
numberOfMessages: json["numberOfMessages"] as int,
);
if (json["address"] == null) {
Expand Down
23 changes: 9 additions & 14 deletions lib/models/isar/models/ethereum/eth_contract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,16 @@ class EthContract extends Contract {
List<String>? walletIds,
String? abi,
String? otherData,
}) =>
EthContract(
address: address ?? this.address,
name: name ?? this.name,
symbol: symbol ?? this.symbol,
decimals: decimals ?? this.decimals,
type: type ?? this.type,
abi: abi ?? this.abi,
)..id = id ?? this.id;
}) => EthContract(
address: address ?? this.address,
name: name ?? this.name,
symbol: symbol ?? this.symbol,
decimals: decimals ?? this.decimals,
type: type ?? this.type,
abi: abi ?? this.abi,
)..id = id ?? this.id;
}

// Used in Isar db and stored there as int indexes so adding/removing values
// in this definition should be done extremely carefully in production
enum EthContractType {
unknown,
erc20,
erc721;
}
enum EthContractType { unknown, erc20, erc721 }
44 changes: 14 additions & 30 deletions lib/models/keys/view_only_wallet_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ import '../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dar
import 'key_data_interface.dart';

// do not remove or change the order of these enum values
enum ViewOnlyWalletType {
cryptonote,
addressOnly,
xPub;
}
enum ViewOnlyWalletType { cryptonote, addressOnly, xPub }

sealed class ViewOnlyWalletData with KeyDataInterface {
@override
final String walletId;

ViewOnlyWalletType get type;

ViewOnlyWalletData({
required this.walletId,
});
ViewOnlyWalletData({required this.walletId});

static ViewOnlyWalletData fromJsonEncodedString(
String jsonEncodedString, {
Expand Down Expand Up @@ -81,10 +75,10 @@ class CryptonoteViewOnlyWalletData extends ViewOnlyWalletData {

@override
String toJsonEncodedString() => jsonEncode({
"type": type.index,
"address": address,
"privateViewKey": privateViewKey,
});
"type": type.index,
"address": address,
"privateViewKey": privateViewKey,
});
}

class AddressViewOnlyWalletData extends ViewOnlyWalletData {
Expand All @@ -93,10 +87,7 @@ class AddressViewOnlyWalletData extends ViewOnlyWalletData {

final String address;

AddressViewOnlyWalletData({
required super.walletId,
required this.address,
});
AddressViewOnlyWalletData({required super.walletId, required this.address});

static AddressViewOnlyWalletData fromJsonEncodedString(
String jsonEncodedString, {
Expand All @@ -112,10 +103,8 @@ class AddressViewOnlyWalletData extends ViewOnlyWalletData {
}

@override
String toJsonEncodedString() => jsonEncode({
"type": type.index,
"address": address,
});
String toJsonEncodedString() =>
jsonEncode({"type": type.index, "address": address});
}

class ExtendedKeysViewOnlyWalletData extends ViewOnlyWalletData {
Expand Down Expand Up @@ -151,14 +140,9 @@ class ExtendedKeysViewOnlyWalletData extends ViewOnlyWalletData {

@override
String toJsonEncodedString() => jsonEncode({
"type": type.index,
"xPubs": [
...xPubs.map(
(e) => {
"path": e.path,
"encoded": e.encoded,
},
),
],
});
"type": type.index,
"xPubs": [
...xPubs.map((e) => {"path": e.path, "encoded": e.encoded}),
],
});
}
Loading