2023-12-04 15:35:59 +00:00
|
|
|
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;
|
2023-12-04 15:35:59 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2023-12-18 20:05:22 +00:00
|
|
|
final String? serializedCoinB64;
|
|
|
|
final String? contextB64;
|
|
|
|
|
2023-12-04 15:35:59 +00:00
|
|
|
@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,
|
2023-12-04 15:35:59 +00:00
|
|
|
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,
|
2023-12-18 20:05:22 +00:00
|
|
|
this.serializedCoinB64,
|
|
|
|
this.contextB64,
|
2023-12-04 15:35:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
SparkCoin copyWith({
|
|
|
|
SparkCoinType? type,
|
|
|
|
bool? isUsed,
|
2023-12-15 14:16:51 +00:00
|
|
|
List<int>? nonce,
|
2023-12-04 15:35:59 +00:00
|
|
|
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,
|
2023-12-18 20:05:22 +00:00
|
|
|
String? serializedCoinB64,
|
|
|
|
String? contextB64,
|
2023-12-04 15:35:59 +00:00
|
|
|
}) {
|
|
|
|
return SparkCoin(
|
|
|
|
walletId: walletId,
|
|
|
|
type: type ?? this.type,
|
|
|
|
isUsed: isUsed ?? this.isUsed,
|
2023-12-15 14:16:51 +00:00
|
|
|
nonce: nonce ?? this.nonce,
|
2023-12-04 15:35:59 +00:00
|
|
|
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,
|
2023-12-18 20:05:22 +00:00
|
|
|
serializedCoinB64: serializedCoinB64 ?? this.serializedCoinB64,
|
|
|
|
contextB64: contextB64 ?? this.contextB64,
|
2023-12-04 15:35:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return 'SparkCoin('
|
2023-12-15 14:16:51 +00:00
|
|
|
'walletId: $walletId'
|
2023-12-04 15:35:59 +00:00
|
|
|
', type: $type'
|
|
|
|
', isUsed: $isUsed'
|
2023-12-15 14:16:51 +00:00
|
|
|
', k: $nonce'
|
2023-12-04 15:35:59 +00:00
|
|
|
', 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'
|
2023-12-18 20:05:22 +00:00
|
|
|
', serializedCoinB64: $serializedCoinB64'
|
|
|
|
', contextB64: $contextB64'
|
2023-12-04 15:35:59 +00:00
|
|
|
')';
|
|
|
|
}
|
|
|
|
}
|