mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-28 10:08:46 +00:00
make fields final and other small QOL changes
This commit is contained in:
parent
0a3c001845
commit
f507f6a60a
6 changed files with 102 additions and 53 deletions
lib
db
models/isar/models
|
@ -45,12 +45,12 @@ class MainDB {
|
|||
Future<void> updateAddress(Address oldAddress, Address newAddress) =>
|
||||
isar.writeTxn(() async {
|
||||
newAddress.id = oldAddress.id;
|
||||
await oldAddress.transaction.load();
|
||||
final txns = oldAddress.transaction.toList();
|
||||
await oldAddress.transactions.load();
|
||||
final txns = oldAddress.transactions.toList();
|
||||
await isar.addresses.delete(oldAddress.id);
|
||||
await isar.addresses.put(newAddress);
|
||||
newAddress.transaction.addAll(txns);
|
||||
await newAddress.transaction.save();
|
||||
newAddress.transactions.addAll(txns);
|
||||
await newAddress.transactions.save();
|
||||
});
|
||||
|
||||
// transactions
|
||||
|
|
|
@ -18,28 +18,31 @@ class Address extends CryptoCurrencyAddress {
|
|||
required this.derivationIndex,
|
||||
required this.type,
|
||||
required this.subType,
|
||||
this.otherData,
|
||||
});
|
||||
|
||||
Id id = Isar.autoIncrement;
|
||||
|
||||
@Index()
|
||||
late String walletId;
|
||||
late final String walletId;
|
||||
|
||||
@Index(unique: true, composite: [CompositeIndex("walletId")])
|
||||
late String value;
|
||||
late final String value;
|
||||
|
||||
late List<byte> publicKey;
|
||||
late final List<byte> publicKey;
|
||||
|
||||
@Index()
|
||||
late int derivationIndex; // -1 generally means unknown
|
||||
late final int derivationIndex; // -1 generally means unknown
|
||||
|
||||
@enumerated
|
||||
late AddressType type;
|
||||
late final AddressType type;
|
||||
|
||||
@enumerated
|
||||
late AddressSubType subType;
|
||||
late final AddressSubType subType;
|
||||
|
||||
final transaction = IsarLinks<Transaction>();
|
||||
late final String? otherData;
|
||||
|
||||
final transactions = IsarLinks<Transaction>();
|
||||
|
||||
int derivationChain() {
|
||||
if (subType == AddressSubType.receiving) {
|
||||
|
@ -57,7 +60,17 @@ class Address extends CryptoCurrencyAddress {
|
|||
subType == AddressSubType.paynymReceive;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
String toString() => "{ "
|
||||
"id: $id, "
|
||||
"walletId: $walletId, "
|
||||
"value: $value, "
|
||||
"publicKey: $publicKey, "
|
||||
"derivationIndex: $derivationIndex, "
|
||||
"type: ${type.name}, "
|
||||
"subType: ${subType.name}, "
|
||||
"transactionsLength: ${transactions.length} "
|
||||
"otherData: $otherData, "
|
||||
"}";
|
||||
}
|
||||
|
||||
enum AddressType {
|
||||
|
|
|
@ -20,24 +20,24 @@ class Input {
|
|||
Id id = Isar.autoIncrement;
|
||||
|
||||
@Index()
|
||||
late String walletId;
|
||||
late final String walletId;
|
||||
|
||||
late String txid;
|
||||
late final String txid;
|
||||
|
||||
late int vout;
|
||||
late final int vout;
|
||||
|
||||
late String? scriptSig;
|
||||
late final String? scriptSig;
|
||||
|
||||
late String? scriptSigAsm;
|
||||
late final String? scriptSigAsm;
|
||||
|
||||
// TODO: find witness type // is it even used?
|
||||
// late List<dynamic>? witness;
|
||||
|
||||
late bool? isCoinbase;
|
||||
late final bool? isCoinbase;
|
||||
|
||||
late int? sequence;
|
||||
late final int? sequence;
|
||||
|
||||
late String? innerRedeemScriptAsm;
|
||||
late final String? innerRedeemScriptAsm;
|
||||
|
||||
final prevOut = IsarLink<Output>();
|
||||
|
||||
|
|
|
@ -17,17 +17,17 @@ class Output {
|
|||
Id id = Isar.autoIncrement;
|
||||
|
||||
@Index()
|
||||
late String walletId;
|
||||
late final String walletId;
|
||||
|
||||
late String? scriptPubKey;
|
||||
late final String? scriptPubKey;
|
||||
|
||||
late String? scriptPubKeyAsm;
|
||||
late final String? scriptPubKeyAsm;
|
||||
|
||||
late String? scriptPubKeyType;
|
||||
late final String? scriptPubKeyType;
|
||||
|
||||
late String scriptPubKeyAddress;
|
||||
late final String scriptPubKeyAddress;
|
||||
|
||||
late int value;
|
||||
late final int value;
|
||||
|
||||
@Backlink(to: 'outputs')
|
||||
final transaction = IsarLink<Transaction>();
|
||||
|
|
|
@ -27,38 +27,35 @@ class Transaction {
|
|||
Id id = Isar.autoIncrement;
|
||||
|
||||
@Index()
|
||||
late String walletId;
|
||||
late final String walletId;
|
||||
|
||||
@Index(unique: true, composite: [CompositeIndex("walletId")])
|
||||
late String txid;
|
||||
late final String txid;
|
||||
|
||||
@Index()
|
||||
late int timestamp;
|
||||
late final int timestamp;
|
||||
|
||||
@enumerated
|
||||
late TransactionType type;
|
||||
late final TransactionType type;
|
||||
|
||||
@enumerated
|
||||
late TransactionSubType subType;
|
||||
late final TransactionSubType subType;
|
||||
|
||||
late int amount;
|
||||
late final int amount;
|
||||
|
||||
// TODO: do we need this?
|
||||
// late List<dynamic> aliens;
|
||||
late final int fee;
|
||||
|
||||
late int fee;
|
||||
late final int? height;
|
||||
|
||||
late int? height;
|
||||
late final bool isCancelled;
|
||||
|
||||
late bool isCancelled;
|
||||
late final bool? isLelantus;
|
||||
|
||||
late bool? isLelantus;
|
||||
late final String? slateId;
|
||||
|
||||
late String? slateId;
|
||||
late final String? otherData;
|
||||
|
||||
late String? otherData;
|
||||
|
||||
@Backlink(to: "transaction")
|
||||
@Backlink(to: "transactions")
|
||||
final address = IsarLink<Address>();
|
||||
|
||||
final inputs = IsarLinks<Input>();
|
||||
|
@ -74,6 +71,26 @@ class Transaction {
|
|||
final confirmations = getConfirmations(currentChainHeight);
|
||||
return confirmations >= minimumConfirms;
|
||||
}
|
||||
|
||||
@override
|
||||
toString() => "{ "
|
||||
"id: $id, "
|
||||
"walletId: $walletId, "
|
||||
"txid: $txid, "
|
||||
"timestamp: $timestamp, "
|
||||
"type: ${type.name}, "
|
||||
"subType: ${subType.name}, "
|
||||
"amount: $amount, "
|
||||
"fee: $fee, "
|
||||
"height: $height, "
|
||||
"isCancelled: $isCancelled, "
|
||||
"isLelantus: $isLelantus, "
|
||||
"slateId: $slateId, "
|
||||
"otherData: $otherData, "
|
||||
"address: ${address.value}, "
|
||||
"inputsLength: ${inputs.length}, "
|
||||
"outputsLength: ${outputs.length}, "
|
||||
"}";
|
||||
}
|
||||
|
||||
// Used in Isar db and stored there as int indexes so adding/removing values
|
||||
|
|
|
@ -18,34 +18,37 @@ class UTXO {
|
|||
required this.blockHash,
|
||||
required this.blockHeight,
|
||||
required this.blockTime,
|
||||
this.otherData,
|
||||
});
|
||||
|
||||
Id id = Isar.autoIncrement;
|
||||
|
||||
@Index()
|
||||
late String walletId;
|
||||
late final String walletId;
|
||||
|
||||
@Index(unique: true, replace: true, composite: [CompositeIndex("walletId")])
|
||||
late String txid;
|
||||
late final String txid;
|
||||
|
||||
late int vout;
|
||||
late final int vout;
|
||||
|
||||
late int value;
|
||||
late final int value;
|
||||
|
||||
late String name;
|
||||
late final String name;
|
||||
|
||||
@Index()
|
||||
late bool isBlocked;
|
||||
late final bool isBlocked;
|
||||
|
||||
late String? blockedReason;
|
||||
late final String? blockedReason;
|
||||
|
||||
late bool isCoinbase;
|
||||
late final bool isCoinbase;
|
||||
|
||||
late String? blockHash;
|
||||
late final String? blockHash;
|
||||
|
||||
late int? blockHeight;
|
||||
late final int? blockHeight;
|
||||
|
||||
late int? blockTime;
|
||||
late final int? blockTime;
|
||||
|
||||
late final String? otherData;
|
||||
|
||||
int getConfirmations(int currentChainHeight) {
|
||||
if (blockTime == null || blockHash == null) return 0;
|
||||
|
@ -57,4 +60,20 @@ class UTXO {
|
|||
final confirmations = getConfirmations(currentChainHeight);
|
||||
return confirmations >= minimumConfirms;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => "{ "
|
||||
"id: $id, "
|
||||
"walletId: $walletId, "
|
||||
"txid: $txid, "
|
||||
"vout: $vout, "
|
||||
"value: $value, "
|
||||
"name: $name, "
|
||||
"isBlocked: $isBlocked, "
|
||||
"blockedReason: $blockedReason, "
|
||||
"isCoinbase: $isCoinbase, "
|
||||
"blockHash: $blockHash, "
|
||||
"blockHeight: $blockHeight, "
|
||||
"blockTime: $blockTime, "
|
||||
"}";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue