stack_wallet/lib/wallets/isar/models/spark_coin.dart

144 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:isar/isar.dart';
part 'spark_coin.g.dart';
enum SparkCoinType {
mint(0),
spend(1);
const SparkCoinType(this.value);
final int value;
}
@Collection()
class SparkCoin {
Id id = Isar.autoIncrement;
@Index(
unique: true,
replace: true,
composite: [
CompositeIndex("lTagHash"),
],
)
final String walletId;
@enumerated
final SparkCoinType type;
final bool isUsed;
2023-12-15 14:16:51 +00:00
final List<int>? nonce;
final String address;
final String txHash;
final String valueIntString;
final String? memo;
final List<int>? serialContext;
final String diversifierIntString;
final List<int>? encryptedDiversifier;
final List<int>? serial;
final List<int>? tag;
final String lTagHash;
2023-12-15 14:16:51 +00:00
final int? height;
final String? serializedCoinB64;
final String? contextB64;
@ignore
BigInt get value => BigInt.parse(valueIntString);
@ignore
BigInt get diversifier => BigInt.parse(diversifierIntString);
SparkCoin({
required this.walletId,
required this.type,
required this.isUsed,
2023-12-15 14:16:51 +00:00
this.nonce,
required this.address,
required this.txHash,
required this.valueIntString,
this.memo,
this.serialContext,
required this.diversifierIntString,
this.encryptedDiversifier,
this.serial,
this.tag,
required this.lTagHash,
2023-12-15 14:16:51 +00:00
this.height,
this.serializedCoinB64,
this.contextB64,
});
SparkCoin copyWith({
SparkCoinType? type,
bool? isUsed,
2023-12-15 14:16:51 +00:00
List<int>? nonce,
String? address,
String? txHash,
BigInt? value,
String? memo,
List<int>? serialContext,
BigInt? diversifier,
List<int>? encryptedDiversifier,
List<int>? serial,
List<int>? tag,
String? lTagHash,
2023-12-15 14:16:51 +00:00
int? height,
String? serializedCoinB64,
String? contextB64,
}) {
return SparkCoin(
walletId: walletId,
type: type ?? this.type,
isUsed: isUsed ?? this.isUsed,
2023-12-15 14:16:51 +00:00
nonce: nonce ?? this.nonce,
address: address ?? this.address,
txHash: txHash ?? this.txHash,
valueIntString: value?.toString() ?? this.value.toString(),
memo: memo ?? this.memo,
serialContext: serialContext ?? this.serialContext,
diversifierIntString:
diversifier?.toString() ?? this.diversifier.toString(),
encryptedDiversifier: encryptedDiversifier ?? this.encryptedDiversifier,
serial: serial ?? this.serial,
tag: tag ?? this.tag,
lTagHash: lTagHash ?? this.lTagHash,
2023-12-15 14:16:51 +00:00
height: height ?? this.height,
serializedCoinB64: serializedCoinB64 ?? this.serializedCoinB64,
contextB64: contextB64 ?? this.contextB64,
);
}
@override
String toString() {
return 'SparkCoin('
2023-12-15 14:16:51 +00:00
'walletId: $walletId'
', type: $type'
', isUsed: $isUsed'
2023-12-15 14:16:51 +00:00
', k: $nonce'
', address: $address'
', txHash: $txHash'
', value: $value'
', memo: $memo'
', serialContext: $serialContext'
', diversifier: $diversifier'
', encryptedDiversifier: $encryptedDiversifier'
', serial: $serial'
', tag: $tag'
', lTagHash: $lTagHash'
2023-12-15 14:16:51 +00:00
', height: $height'
', serializedCoinB64: $serializedCoinB64'
', contextB64: $contextB64'
')';
}
}