diff --git a/lib/models/isar/models/address/address.dart b/lib/models/isar/models/address/address.dart new file mode 100644 index 000000000..15f09df6f --- /dev/null +++ b/lib/models/isar/models/address/address.dart @@ -0,0 +1,56 @@ +import 'package:isar/isar.dart'; +import 'package:stackwallet/models/isar/models/address/crypto_currency_address.dart'; +import 'package:stackwallet/services/coins/coin_paynym_extension.dart'; + +part 'address.g.dart'; + +class AddressException extends SWException { + AddressException(super.message); +} + +@Collection(inheritance: true) +class Address extends CryptoCurrencyAddress { + Id id = Isar.autoIncrement; + + late List publicKey; + + late int derivationIndex; + + @enumerated + late AddressType type; + + @enumerated + late AddressSubType subType; + + int derivationChain() { + if (subType == AddressSubType.receiving) { + return 0; // 0 for receiving (external) + } else if (subType == AddressSubType.change) { + return 1; // 1 for change (internal) + } else { + throw AddressException("Could not imply derivation chain value"); + } + } + + bool isPaynymAddress() => + subType == AddressSubType.paynymNotification || + subType == AddressSubType.paynymSend || + subType == AddressSubType.paynymReceive; + + @override + String toString() => value; +} + +enum AddressType { + p2pkh, + p2sh, + p2wpkh, +} + +enum AddressSubType { + receiving, + change, + paynymNotification, + paynymSend, + paynymReceive, +} diff --git a/lib/models/isar/models/address/address.g.dart b/lib/models/isar/models/address/address.g.dart new file mode 100644 index 000000000..6ccd5d95d --- /dev/null +++ b/lib/models/isar/models/address/address.g.dart @@ -0,0 +1,916 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'address.dart'; + +// ************************************************************************** +// IsarCollectionGenerator +// ************************************************************************** + +// coverage:ignore-file +// ignore_for_file: duplicate_ignore, non_constant_identifier_names, constant_identifier_names, invalid_use_of_protected_member, unnecessary_cast, prefer_const_constructors, lines_longer_than_80_chars, require_trailing_commas, inference_failure_on_function_invocation, unnecessary_parenthesis, unnecessary_raw_strings, unnecessary_null_checks, join_return_with_assignment, prefer_final_locals, avoid_js_rounded_ints, avoid_positional_boolean_parameters + +extension GetAddressCollection on Isar { + IsarCollection
get address => this.collection(); +} + +const AddressSchema = CollectionSchema( + name: r'Address', + id: 3544600503126319553, + properties: { + r'derivationIndex': PropertySchema( + id: 0, + name: r'derivationIndex', + type: IsarType.long, + ), + r'publicKey': PropertySchema( + id: 1, + name: r'publicKey', + type: IsarType.byteList, + ), + r'subType': PropertySchema( + id: 2, + name: r'subType', + type: IsarType.byte, + enumMap: _AddresssubTypeEnumValueMap, + ), + r'type': PropertySchema( + id: 3, + name: r'type', + type: IsarType.byte, + enumMap: _AddresstypeEnumValueMap, + ), + r'value': PropertySchema( + id: 4, + name: r'value', + type: IsarType.string, + ) + }, + estimateSize: _addressEstimateSize, + serialize: _addressSerialize, + deserialize: _addressDeserialize, + deserializeProp: _addressDeserializeProp, + idName: r'id', + indexes: {}, + links: {}, + embeddedSchemas: {}, + getId: _addressGetId, + getLinks: _addressGetLinks, + attach: _addressAttach, + version: '3.0.5', +); + +int _addressEstimateSize( + Address object, + List offsets, + Map> allOffsets, +) { + var bytesCount = offsets.last; + bytesCount += 3 + object.publicKey.length; + bytesCount += 3 + object.value.length * 3; + return bytesCount; +} + +void _addressSerialize( + Address object, + IsarWriter writer, + List offsets, + Map> allOffsets, +) { + writer.writeLong(offsets[0], object.derivationIndex); + writer.writeByteList(offsets[1], object.publicKey); + writer.writeByte(offsets[2], object.subType.index); + writer.writeByte(offsets[3], object.type.index); + writer.writeString(offsets[4], object.value); +} + +Address _addressDeserialize( + Id id, + IsarReader reader, + List offsets, + Map> allOffsets, +) { + final object = Address(); + object.derivationIndex = reader.readLong(offsets[0]); + object.id = id; + object.publicKey = reader.readByteList(offsets[1]) ?? []; + object.subType = + _AddresssubTypeValueEnumMap[reader.readByteOrNull(offsets[2])] ?? + AddressSubType.receiving; + object.type = _AddresstypeValueEnumMap[reader.readByteOrNull(offsets[3])] ?? + AddressType.p2pkh; + object.value = reader.readString(offsets[4]); + return object; +} + +P _addressDeserializeProp

( + IsarReader reader, + int propertyId, + int offset, + Map> allOffsets, +) { + switch (propertyId) { + case 0: + return (reader.readLong(offset)) as P; + case 1: + return (reader.readByteList(offset) ?? []) as P; + case 2: + return (_AddresssubTypeValueEnumMap[reader.readByteOrNull(offset)] ?? + AddressSubType.receiving) as P; + case 3: + return (_AddresstypeValueEnumMap[reader.readByteOrNull(offset)] ?? + AddressType.p2pkh) as P; + case 4: + return (reader.readString(offset)) as P; + default: + throw IsarError('Unknown property with id $propertyId'); + } +} + +const _AddresssubTypeEnumValueMap = { + 'receiving': 0, + 'change': 1, + 'paynymNotification': 2, + 'paynymSend': 3, + 'paynymReceive': 4, +}; +const _AddresssubTypeValueEnumMap = { + 0: AddressSubType.receiving, + 1: AddressSubType.change, + 2: AddressSubType.paynymNotification, + 3: AddressSubType.paynymSend, + 4: AddressSubType.paynymReceive, +}; +const _AddresstypeEnumValueMap = { + 'p2pkh': 0, + 'p2sh': 1, + 'p2wpkh': 2, +}; +const _AddresstypeValueEnumMap = { + 0: AddressType.p2pkh, + 1: AddressType.p2sh, + 2: AddressType.p2wpkh, +}; + +Id _addressGetId(Address object) { + return object.id; +} + +List> _addressGetLinks(Address object) { + return []; +} + +void _addressAttach(IsarCollection col, Id id, Address object) { + object.id = id; +} + +extension AddressQueryWhereSort on QueryBuilder { + QueryBuilder anyId() { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(const IdWhereClause.any()); + }); + } +} + +extension AddressQueryWhere on QueryBuilder { + QueryBuilder idEqualTo(Id id) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(IdWhereClause.between( + lower: id, + upper: id, + )); + }); + } + + QueryBuilder idNotEqualTo(Id id) { + return QueryBuilder.apply(this, (query) { + if (query.whereSort == Sort.asc) { + return query + .addWhereClause( + IdWhereClause.lessThan(upper: id, includeUpper: false), + ) + .addWhereClause( + IdWhereClause.greaterThan(lower: id, includeLower: false), + ); + } else { + return query + .addWhereClause( + IdWhereClause.greaterThan(lower: id, includeLower: false), + ) + .addWhereClause( + IdWhereClause.lessThan(upper: id, includeUpper: false), + ); + } + }); + } + + QueryBuilder idGreaterThan(Id id, + {bool include = false}) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause( + IdWhereClause.greaterThan(lower: id, includeLower: include), + ); + }); + } + + QueryBuilder idLessThan(Id id, + {bool include = false}) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause( + IdWhereClause.lessThan(upper: id, includeUpper: include), + ); + }); + } + + QueryBuilder idBetween( + Id lowerId, + Id upperId, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(IdWhereClause.between( + lower: lowerId, + includeLower: includeLower, + upper: upperId, + includeUpper: includeUpper, + )); + }); + } +} + +extension AddressQueryFilter + on QueryBuilder { + QueryBuilder derivationIndexEqualTo( + int value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'derivationIndex', + value: value, + )); + }); + } + + QueryBuilder + derivationIndexGreaterThan( + int value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'derivationIndex', + value: value, + )); + }); + } + + QueryBuilder derivationIndexLessThan( + int value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'derivationIndex', + value: value, + )); + }); + } + + QueryBuilder derivationIndexBetween( + int lower, + int upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'derivationIndex', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + )); + }); + } + + QueryBuilder idEqualTo(Id value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'id', + value: value, + )); + }); + } + + QueryBuilder idGreaterThan( + Id value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'id', + value: value, + )); + }); + } + + QueryBuilder idLessThan( + Id value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'id', + value: value, + )); + }); + } + + QueryBuilder idBetween( + Id lower, + Id upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'id', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + )); + }); + } + + QueryBuilder publicKeyElementEqualTo( + int value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'publicKey', + value: value, + )); + }); + } + + QueryBuilder + publicKeyElementGreaterThan( + int value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'publicKey', + value: value, + )); + }); + } + + QueryBuilder + publicKeyElementLessThan( + int value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'publicKey', + value: value, + )); + }); + } + + QueryBuilder publicKeyElementBetween( + int lower, + int upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'publicKey', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + )); + }); + } + + QueryBuilder publicKeyLengthEqualTo( + int length) { + return QueryBuilder.apply(this, (query) { + return query.listLength( + r'publicKey', + length, + true, + length, + true, + ); + }); + } + + QueryBuilder publicKeyIsEmpty() { + return QueryBuilder.apply(this, (query) { + return query.listLength( + r'publicKey', + 0, + true, + 0, + true, + ); + }); + } + + QueryBuilder publicKeyIsNotEmpty() { + return QueryBuilder.apply(this, (query) { + return query.listLength( + r'publicKey', + 0, + false, + 999999, + true, + ); + }); + } + + QueryBuilder publicKeyLengthLessThan( + int length, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.listLength( + r'publicKey', + 0, + true, + length, + include, + ); + }); + } + + QueryBuilder + publicKeyLengthGreaterThan( + int length, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.listLength( + r'publicKey', + length, + include, + 999999, + true, + ); + }); + } + + QueryBuilder publicKeyLengthBetween( + int lower, + int upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.listLength( + r'publicKey', + lower, + includeLower, + upper, + includeUpper, + ); + }); + } + + QueryBuilder subTypeEqualTo( + AddressSubType value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'subType', + value: value, + )); + }); + } + + QueryBuilder subTypeGreaterThan( + AddressSubType value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'subType', + value: value, + )); + }); + } + + QueryBuilder subTypeLessThan( + AddressSubType value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'subType', + value: value, + )); + }); + } + + QueryBuilder subTypeBetween( + AddressSubType lower, + AddressSubType upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'subType', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + )); + }); + } + + QueryBuilder typeEqualTo( + AddressType value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'type', + value: value, + )); + }); + } + + QueryBuilder typeGreaterThan( + AddressType value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'type', + value: value, + )); + }); + } + + QueryBuilder typeLessThan( + AddressType value, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'type', + value: value, + )); + }); + } + + QueryBuilder typeBetween( + AddressType lower, + AddressType upper, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'type', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + )); + }); + } + + QueryBuilder valueEqualTo( + String value, { + bool caseSensitive = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'value', + value: value, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueGreaterThan( + String value, { + bool include = false, + bool caseSensitive = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + include: include, + property: r'value', + value: value, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueLessThan( + String value, { + bool include = false, + bool caseSensitive = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.lessThan( + include: include, + property: r'value', + value: value, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueBetween( + String lower, + String upper, { + bool includeLower = true, + bool includeUpper = true, + bool caseSensitive = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.between( + property: r'value', + lower: lower, + includeLower: includeLower, + upper: upper, + includeUpper: includeUpper, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueStartsWith( + String value, { + bool caseSensitive = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.startsWith( + property: r'value', + value: value, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueEndsWith( + String value, { + bool caseSensitive = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.endsWith( + property: r'value', + value: value, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueContains( + String value, + {bool caseSensitive = true}) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.contains( + property: r'value', + value: value, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueMatches( + String pattern, + {bool caseSensitive = true}) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.matches( + property: r'value', + wildcard: pattern, + caseSensitive: caseSensitive, + )); + }); + } + + QueryBuilder valueIsEmpty() { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'value', + value: '', + )); + }); + } + + QueryBuilder valueIsNotEmpty() { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.greaterThan( + property: r'value', + value: '', + )); + }); + } +} + +extension AddressQueryObject + on QueryBuilder {} + +extension AddressQueryLinks + on QueryBuilder {} + +extension AddressQuerySortBy on QueryBuilder { + QueryBuilder sortByDerivationIndex() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'derivationIndex', Sort.asc); + }); + } + + QueryBuilder sortByDerivationIndexDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'derivationIndex', Sort.desc); + }); + } + + QueryBuilder sortBySubType() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'subType', Sort.asc); + }); + } + + QueryBuilder sortBySubTypeDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'subType', Sort.desc); + }); + } + + QueryBuilder sortByType() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'type', Sort.asc); + }); + } + + QueryBuilder sortByTypeDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'type', Sort.desc); + }); + } + + QueryBuilder sortByValue() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'value', Sort.asc); + }); + } + + QueryBuilder sortByValueDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'value', Sort.desc); + }); + } +} + +extension AddressQuerySortThenBy + on QueryBuilder { + QueryBuilder thenByDerivationIndex() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'derivationIndex', Sort.asc); + }); + } + + QueryBuilder thenByDerivationIndexDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'derivationIndex', Sort.desc); + }); + } + + QueryBuilder thenById() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'id', Sort.asc); + }); + } + + QueryBuilder thenByIdDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'id', Sort.desc); + }); + } + + QueryBuilder thenBySubType() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'subType', Sort.asc); + }); + } + + QueryBuilder thenBySubTypeDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'subType', Sort.desc); + }); + } + + QueryBuilder thenByType() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'type', Sort.asc); + }); + } + + QueryBuilder thenByTypeDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'type', Sort.desc); + }); + } + + QueryBuilder thenByValue() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'value', Sort.asc); + }); + } + + QueryBuilder thenByValueDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'value', Sort.desc); + }); + } +} + +extension AddressQueryWhereDistinct + on QueryBuilder { + QueryBuilder distinctByDerivationIndex() { + return QueryBuilder.apply(this, (query) { + return query.addDistinctBy(r'derivationIndex'); + }); + } + + QueryBuilder distinctByPublicKey() { + return QueryBuilder.apply(this, (query) { + return query.addDistinctBy(r'publicKey'); + }); + } + + QueryBuilder distinctBySubType() { + return QueryBuilder.apply(this, (query) { + return query.addDistinctBy(r'subType'); + }); + } + + QueryBuilder distinctByType() { + return QueryBuilder.apply(this, (query) { + return query.addDistinctBy(r'type'); + }); + } + + QueryBuilder distinctByValue( + {bool caseSensitive = true}) { + return QueryBuilder.apply(this, (query) { + return query.addDistinctBy(r'value', caseSensitive: caseSensitive); + }); + } +} + +extension AddressQueryProperty + on QueryBuilder { + QueryBuilder idProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'id'); + }); + } + + QueryBuilder derivationIndexProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'derivationIndex'); + }); + } + + QueryBuilder, QQueryOperations> publicKeyProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'publicKey'); + }); + } + + QueryBuilder subTypeProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'subType'); + }); + } + + QueryBuilder typeProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'type'); + }); + } + + QueryBuilder valueProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'value'); + }); + } +} diff --git a/lib/models/isar/models/address/crypto_currency_address.dart b/lib/models/isar/models/address/crypto_currency_address.dart new file mode 100644 index 000000000..30b725024 --- /dev/null +++ b/lib/models/isar/models/address/crypto_currency_address.dart @@ -0,0 +1,6 @@ +abstract class CryptoCurrencyAddress { + late String value; + + @override + String toString() => value; +}