explicit isar model constructors

This commit is contained in:
julian 2023-01-16 16:37:00 -06:00
parent 5562c14527
commit d1f237ae51
23 changed files with 663 additions and 540 deletions

View file

@ -11,6 +11,15 @@ class AddressException extends SWException {
@Collection(accessor: "addresses") @Collection(accessor: "addresses")
class Address extends CryptoCurrencyAddress { class Address extends CryptoCurrencyAddress {
Address({
required this.walletId,
required this.value,
required this.publicKey,
required this.derivationIndex,
required this.type,
required this.subType,
});
Id id = Isar.autoIncrement; Id id = Isar.autoIncrement;
@Index() @Index()
@ -56,6 +65,7 @@ enum AddressType {
p2sh, p2sh,
p2wpkh, p2wpkh,
cryptonote, cryptonote,
mimbleWimble,
nonWallet, nonWallet,
} }
@ -65,5 +75,6 @@ enum AddressSubType {
paynymNotification, paynymNotification,
paynymSend, paynymSend,
paynymReceive, paynymReceive,
unknown,
nonWallet, nonWallet,
} }

View file

@ -148,17 +148,17 @@ Address _addressDeserialize(
List<int> offsets, List<int> offsets,
Map<Type, List<int>> allOffsets, Map<Type, List<int>> allOffsets,
) { ) {
final object = Address(); final object = Address(
object.derivationIndex = reader.readLong(offsets[0]); derivationIndex: reader.readLong(offsets[0]),
publicKey: reader.readByteList(offsets[1]) ?? [],
subType: _AddresssubTypeValueEnumMap[reader.readByteOrNull(offsets[2])] ??
AddressSubType.receiving,
type: _AddresstypeValueEnumMap[reader.readByteOrNull(offsets[3])] ??
AddressType.p2pkh,
value: reader.readString(offsets[4]),
walletId: reader.readString(offsets[5]),
);
object.id = id; 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]);
object.walletId = reader.readString(offsets[5]);
return object; return object;
} }
@ -194,7 +194,8 @@ const _AddresssubTypeEnumValueMap = {
'paynymNotification': 2, 'paynymNotification': 2,
'paynymSend': 3, 'paynymSend': 3,
'paynymReceive': 4, 'paynymReceive': 4,
'nonWallet': 5, 'unknown': 5,
'nonWallet': 6,
}; };
const _AddresssubTypeValueEnumMap = { const _AddresssubTypeValueEnumMap = {
0: AddressSubType.receiving, 0: AddressSubType.receiving,
@ -202,21 +203,24 @@ const _AddresssubTypeValueEnumMap = {
2: AddressSubType.paynymNotification, 2: AddressSubType.paynymNotification,
3: AddressSubType.paynymSend, 3: AddressSubType.paynymSend,
4: AddressSubType.paynymReceive, 4: AddressSubType.paynymReceive,
5: AddressSubType.nonWallet, 5: AddressSubType.unknown,
6: AddressSubType.nonWallet,
}; };
const _AddresstypeEnumValueMap = { const _AddresstypeEnumValueMap = {
'p2pkh': 0, 'p2pkh': 0,
'p2sh': 1, 'p2sh': 1,
'p2wpkh': 2, 'p2wpkh': 2,
'cryptonote': 3, 'cryptonote': 3,
'nonWallet': 4, 'mimbleWimble': 4,
'nonWallet': 5,
}; };
const _AddresstypeValueEnumMap = { const _AddresstypeValueEnumMap = {
0: AddressType.p2pkh, 0: AddressType.p2pkh,
1: AddressType.p2sh, 1: AddressType.p2sh,
2: AddressType.p2wpkh, 2: AddressType.p2wpkh,
3: AddressType.cryptonote, 3: AddressType.cryptonote,
4: AddressType.nonWallet, 4: AddressType.mimbleWimble,
5: AddressType.nonWallet,
}; };
Id _addressGetId(Address object) { Id _addressGetId(Address object) {

View file

@ -6,6 +6,17 @@ part 'input.g.dart';
@Collection() @Collection()
class Input { class Input {
Input({
required this.walletId,
required this.txid,
required this.vout,
required this.scriptSig,
required this.scriptSigAsm,
required this.isCoinbase,
required this.sequence,
required this.innerRedeemScriptAsm,
});
Id id = Isar.autoIncrement; Id id = Isar.autoIncrement;
@Index() @Index()

View file

@ -151,16 +151,17 @@ Input _inputDeserialize(
List<int> offsets, List<int> offsets,
Map<Type, List<int>> allOffsets, Map<Type, List<int>> allOffsets,
) { ) {
final object = Input(); final object = Input(
innerRedeemScriptAsm: reader.readStringOrNull(offsets[0]),
isCoinbase: reader.readBoolOrNull(offsets[1]),
scriptSig: reader.readStringOrNull(offsets[2]),
scriptSigAsm: reader.readStringOrNull(offsets[3]),
sequence: reader.readLongOrNull(offsets[4]),
txid: reader.readString(offsets[5]),
vout: reader.readLong(offsets[6]),
walletId: reader.readString(offsets[7]),
);
object.id = id; object.id = id;
object.innerRedeemScriptAsm = reader.readStringOrNull(offsets[0]);
object.isCoinbase = reader.readBoolOrNull(offsets[1]);
object.scriptSig = reader.readStringOrNull(offsets[2]);
object.scriptSigAsm = reader.readStringOrNull(offsets[3]);
object.sequence = reader.readLongOrNull(offsets[4]);
object.txid = reader.readString(offsets[5]);
object.vout = reader.readLong(offsets[6]);
object.walletId = reader.readString(offsets[7]);
return object; return object;
} }

View file

@ -5,6 +5,15 @@ part 'output.g.dart';
@Collection() @Collection()
class Output { class Output {
Output({
required this.walletId,
required this.scriptPubKey,
required this.scriptPubKeyAsm,
required this.scriptPubKeyType,
required this.scriptPubKeyAddress,
required this.value,
});
Id id = Isar.autoIncrement; Id id = Isar.autoIncrement;
@Index() @Index()

View file

@ -133,14 +133,15 @@ Output _outputDeserialize(
List<int> offsets, List<int> offsets,
Map<Type, List<int>> allOffsets, Map<Type, List<int>> allOffsets,
) { ) {
final object = Output(); final object = Output(
scriptPubKey: reader.readStringOrNull(offsets[0]),
scriptPubKeyAddress: reader.readString(offsets[1]),
scriptPubKeyAsm: reader.readStringOrNull(offsets[2]),
scriptPubKeyType: reader.readStringOrNull(offsets[3]),
value: reader.readLong(offsets[4]),
walletId: reader.readString(offsets[5]),
);
object.id = id; object.id = id;
object.scriptPubKey = reader.readStringOrNull(offsets[0]);
object.scriptPubKeyAddress = reader.readString(offsets[1]);
object.scriptPubKeyAsm = reader.readStringOrNull(offsets[2]);
object.scriptPubKeyType = reader.readStringOrNull(offsets[3]);
object.value = reader.readLong(offsets[4]);
object.walletId = reader.readString(offsets[5]);
return object; return object;
} }

View file

@ -9,6 +9,21 @@ part 'transaction.g.dart';
@Collection() @Collection()
class Transaction { class Transaction {
Transaction({
required this.walletId,
required this.txid,
required this.timestamp,
required this.type,
required this.subType,
required this.amount,
required this.fee,
required this.height,
required this.isCancelled,
required this.isLelantus,
required this.slateId,
required this.otherData,
});
Id id = Isar.autoIncrement; Id id = Isar.autoIncrement;
@Index() @Index()

View file

@ -208,24 +208,24 @@ Transaction _transactionDeserialize(
List<int> offsets, List<int> offsets,
Map<Type, List<int>> allOffsets, Map<Type, List<int>> allOffsets,
) { ) {
final object = Transaction(); final object = Transaction(
object.amount = reader.readLong(offsets[0]); amount: reader.readLong(offsets[0]),
object.fee = reader.readLong(offsets[1]); fee: reader.readLong(offsets[1]),
object.height = reader.readLongOrNull(offsets[2]); height: reader.readLongOrNull(offsets[2]),
isCancelled: reader.readBool(offsets[3]),
isLelantus: reader.readBoolOrNull(offsets[4]),
otherData: reader.readStringOrNull(offsets[5]),
slateId: reader.readStringOrNull(offsets[6]),
subType:
_TransactionsubTypeValueEnumMap[reader.readByteOrNull(offsets[7])] ??
TransactionSubType.none,
timestamp: reader.readLong(offsets[8]),
txid: reader.readString(offsets[9]),
type: _TransactiontypeValueEnumMap[reader.readByteOrNull(offsets[10])] ??
TransactionType.outgoing,
walletId: reader.readString(offsets[11]),
);
object.id = id; object.id = id;
object.isCancelled = reader.readBool(offsets[3]);
object.isLelantus = reader.readBoolOrNull(offsets[4]);
object.otherData = reader.readStringOrNull(offsets[5]);
object.slateId = reader.readStringOrNull(offsets[6]);
object.subType =
_TransactionsubTypeValueEnumMap[reader.readByteOrNull(offsets[7])] ??
TransactionSubType.none;
object.timestamp = reader.readLong(offsets[8]);
object.txid = reader.readString(offsets[9]);
object.type =
_TransactiontypeValueEnumMap[reader.readByteOrNull(offsets[10])] ??
TransactionType.outgoing;
object.walletId = reader.readString(offsets[11]);
return object; return object;
} }

View file

@ -6,6 +6,20 @@ part 'utxo.g.dart';
@Collection(accessor: "utxos") @Collection(accessor: "utxos")
class UTXO { class UTXO {
UTXO({
required this.walletId,
required this.txid,
required this.vout,
required this.value,
required this.name,
required this.isBlocked,
required this.blockedReason,
required this.isCoinbase,
required this.blockHash,
required this.blockHeight,
required this.blockTime,
});
Id id = Isar.autoIncrement; Id id = Isar.autoIncrement;
@Index() @Index()

View file

@ -181,19 +181,20 @@ UTXO _uTXODeserialize(
List<int> offsets, List<int> offsets,
Map<Type, List<int>> allOffsets, Map<Type, List<int>> allOffsets,
) { ) {
final object = UTXO(); final object = UTXO(
object.blockHash = reader.readStringOrNull(offsets[0]); blockHash: reader.readStringOrNull(offsets[0]),
object.blockHeight = reader.readLongOrNull(offsets[1]); blockHeight: reader.readLongOrNull(offsets[1]),
object.blockTime = reader.readLongOrNull(offsets[2]); blockTime: reader.readLongOrNull(offsets[2]),
object.blockedReason = reader.readStringOrNull(offsets[3]); blockedReason: reader.readStringOrNull(offsets[3]),
isBlocked: reader.readBool(offsets[4]),
isCoinbase: reader.readBool(offsets[5]),
name: reader.readString(offsets[6]),
txid: reader.readString(offsets[7]),
value: reader.readLong(offsets[8]),
vout: reader.readLong(offsets[9]),
walletId: reader.readString(offsets[10]),
);
object.id = id; object.id = id;
object.isBlocked = reader.readBool(offsets[4]);
object.isCoinbase = reader.readBool(offsets[5]);
object.name = reader.readString(offsets[6]);
object.txid = reader.readString(offsets[7]);
object.value = reader.readLong(offsets[8]);
object.vout = reader.readLong(offsets[9]);
object.walletId = reader.readString(offsets[10]);
return object; return object;
} }

View file

@ -4,6 +4,12 @@ part 'transaction_note.g.dart';
@Collection() @Collection()
class TransactionNote { class TransactionNote {
TransactionNote({
required this.walletId,
required this.txid,
required this.value,
});
Id id = Isar.autoIncrement; Id id = Isar.autoIncrement;
@Index() @Index()

View file

@ -108,11 +108,12 @@ TransactionNote _transactionNoteDeserialize(
List<int> offsets, List<int> offsets,
Map<Type, List<int>> allOffsets, Map<Type, List<int>> allOffsets,
) { ) {
final object = TransactionNote(); final object = TransactionNote(
txid: reader.readString(offsets[0]),
value: reader.readString(offsets[1]),
walletId: reader.readString(offsets[2]),
);
object.id = id; object.id = id;
object.txid = reader.readString(offsets[0]);
object.value = reader.readString(offsets[1]);
object.walletId = reader.readString(offsets[2]);
return object; return object;
} }

View file

@ -402,14 +402,16 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists"); throw Exception("No Path type $type exists");
} }
final address = isar_models.Address() final address = isar_models.Address(
..subType = chain == 0 walletId: walletId,
value: addressString,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = addrType );
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
receivingNodes.addAll({ receivingNodes.addAll({
"${_id}_$j": { "${_id}_$j": {
@ -1507,14 +1509,16 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType, derivePathType: derivePathType,
); );
return isar_models.Address() return isar_models.Address(
..derivationIndex = index walletId: walletId,
..value = address value: address,
..publicKey = node.publicKey publicKey: node.publicKey,
..type = addrType type: addrType,
..subType = chain == 0 derivationIndex: index,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
/// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain] /// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain]
@ -1739,21 +1743,20 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO();
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;

View file

@ -387,15 +387,16 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists"); throw Exception("No Path type $type exists");
} }
final address = isar_models.Address() final address = isar_models.Address(
..walletId = walletId walletId: walletId,
..subType = chain == 0 value: addressString,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = addrType );
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
receivingNodes.addAll({ receivingNodes.addAll({
"${_id}_$j": { "${_id}_$j": {
@ -1424,15 +1425,16 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType, derivePathType: derivePathType,
); );
return isar_models.Address() return isar_models.Address(
..walletId = walletId walletId: walletId,
..derivationIndex = index value: address,
..value = address publicKey: node.publicKey,
..publicKey = node.publicKey type: addrType,
..type = addrType derivationIndex: index,
..subType = chain == 0 subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
/// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain] /// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain]
@ -1615,21 +1617,20 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO()..walletId = walletId;
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;
@ -2068,85 +2069,91 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
final fee = totalInputValue - totalOutputValue; final fee = totalInputValue - totalOutputValue;
final tx = isar_models.Transaction()..walletId = walletId;
tx.txid = txData["txid"] as String;
tx.timestamp = txData["blocktime"] as int? ??
(DateTime.now().millisecondsSinceEpoch ~/ 1000);
// this is the address initially used to fetch the txid // this is the address initially used to fetch the txid
isar_models.Address transactionAddress = isar_models.Address transactionAddress =
txData["address"] as isar_models.Address; txData["address"] as isar_models.Address;
isar_models.TransactionType type;
int amount;
if (mySentFromAddresses.isNotEmpty && myReceivedOnAddresses.isNotEmpty) { if (mySentFromAddresses.isNotEmpty && myReceivedOnAddresses.isNotEmpty) {
// tx is sent to self // tx is sent to self
tx.type = isar_models.TransactionType.sentToSelf; type = isar_models.TransactionType.sentToSelf;
tx.amount = amount =
amountSentFromWallet - amountReceivedInWallet - fee - changeAmount; amountSentFromWallet - amountReceivedInWallet - fee - changeAmount;
} else if (mySentFromAddresses.isNotEmpty) { } else if (mySentFromAddresses.isNotEmpty) {
// outgoing tx // outgoing tx
tx.type = isar_models.TransactionType.outgoing; type = isar_models.TransactionType.outgoing;
tx.amount = amountSentFromWallet - changeAmount - fee; amount = amountSentFromWallet - changeAmount - fee;
final possible = final possible =
outputAddresses.difference(myChangeReceivedOnAddresses).first; outputAddresses.difference(myChangeReceivedOnAddresses).first;
if (transactionAddress.value != possible) { if (transactionAddress.value != possible) {
transactionAddress = isar_models.Address() transactionAddress = isar_models.Address(
..walletId = walletId walletId: walletId,
..value = possible value: possible,
..derivationIndex = -1 publicKey: [],
..subType = AddressSubType.nonWallet type: AddressType.nonWallet,
..type = AddressType.nonWallet derivationIndex: -1,
..publicKey = []; subType: AddressSubType.nonWallet,
);
} }
} else { } else {
// incoming tx // incoming tx
tx.type = isar_models.TransactionType.incoming; type = isar_models.TransactionType.incoming;
tx.amount = amountReceivedInWallet; amount = amountReceivedInWallet;
} }
// TODO: other subtypes final tx = isar_models.Transaction(
tx.subType = isar_models.TransactionSubType.none; walletId: walletId,
txid: txData["txid"] as String,
tx.fee = fee; timestamp: txData["blocktime"] as int? ??
(DateTime.now().millisecondsSinceEpoch ~/ 1000),
type: type,
subType: isar_models.TransactionSubType.none,
amount: amount,
fee: fee,
height: txData["height"] as int?,
isCancelled: false,
isLelantus: false,
slateId: null,
otherData: null,
);
List<isar_models.Input> inputs = []; List<isar_models.Input> inputs = [];
List<isar_models.Output> outputs = []; List<isar_models.Output> outputs = [];
for (final json in txData["vin"] as List) { for (final json in txData["vin"] as List) {
bool isCoinBase = json['coinbase'] != null; bool isCoinBase = json['coinbase'] != null;
final input = isar_models.Input(); final input = isar_models.Input(
input.txid = json['txid'] as String; walletId: walletId,
input.vout = json['vout'] as int? ?? -1; txid: json['txid'] as String,
input.scriptSig = json['scriptSig']?['hex'] as String?; vout: json['vout'] as int? ?? -1,
input.scriptSigAsm = json['scriptSig']?['asm'] as String?; scriptSig: json['scriptSig']?['hex'] as String?,
input.isCoinbase = scriptSigAsm: json['scriptSig']?['asm'] as String?,
isCoinBase ? isCoinBase : json['is_coinbase'] as bool?; isCoinbase: isCoinBase ? isCoinBase : json['is_coinbase'] as bool?,
input.sequence = json['sequence'] as int?; sequence: json['sequence'] as int?,
input.innerRedeemScriptAsm = json['innerRedeemscriptAsm'] as String?; innerRedeemScriptAsm: json['innerRedeemscriptAsm'] as String?,
);
inputs.add(input); inputs.add(input);
} }
for (final json in txData["vout"] as List) { for (final json in txData["vout"] as List) {
final output = isar_models.Output(); final output = isar_models.Output(
output.scriptPubKey = json['scriptPubKey']?['hex'] as String?; walletId: walletId,
output.scriptPubKeyAsm = json['scriptPubKey']?['asm'] as String?; scriptPubKey: json['scriptPubKey']?['hex'] as String?,
output.scriptPubKeyType = json['scriptPubKey']?['type'] as String?; scriptPubKeyAsm: json['scriptPubKey']?['asm'] as String?,
output.scriptPubKeyAddress = scriptPubKeyType: json['scriptPubKey']?['type'] as String?,
json["scriptPubKey"]?["addresses"]?[0] as String? ?? scriptPubKeyAddress:
json['scriptPubKey']['type'] as String; json["scriptPubKey"]?["addresses"]?[0] as String? ??
output.value = Format.decimalAmountToSatoshis( json['scriptPubKey']['type'] as String,
Decimal.parse(json["value"].toString()), value: Format.decimalAmountToSatoshis(
coin, Decimal.parse(json["value"].toString()),
coin,
),
); );
outputs.add(output); outputs.add(output);
} }
tx.height = txData["height"] as int?;
tx.isCancelled = false;
tx.slateId = null;
tx.otherData = null;
txns.add(Tuple4(tx, outputs, inputs, transactionAddress)); txns.add(Tuple4(tx, outputs, inputs, transactionAddress));
} }

View file

@ -667,87 +667,90 @@ Future<Tuple4<Transaction, List<Output>, List<Input>, Address>>
final fee = totalInputValue - totalOutputValue; final fee = totalInputValue - totalOutputValue;
final tx = Transaction()..walletId = walletId;
tx.txid = txData["txid"] as String;
tx.timestamp = txData["blocktime"] as int? ??
(DateTime.now().millisecondsSinceEpoch ~/ 1000);
// this is the address initially used to fetch the txid // this is the address initially used to fetch the txid
Address transactionAddress = txData["address"] as Address; Address transactionAddress = txData["address"] as Address;
TransactionType type;
int amount;
if (mySentFromAddresses.isNotEmpty && myReceivedOnAddresses.isNotEmpty) { if (mySentFromAddresses.isNotEmpty && myReceivedOnAddresses.isNotEmpty) {
// tx is sent to self // tx is sent to self
tx.type = TransactionType.sentToSelf; type = TransactionType.sentToSelf;
// should be 0 // should be 0
tx.amount = amount = amountSentFromWallet - amountReceivedInWallet - fee - changeAmount;
amountSentFromWallet - amountReceivedInWallet - fee - changeAmount;
} else if (mySentFromAddresses.isNotEmpty) { } else if (mySentFromAddresses.isNotEmpty) {
// outgoing tx // outgoing tx
tx.type = TransactionType.outgoing; type = TransactionType.outgoing;
tx.amount = amountSentFromWallet - changeAmount - fee; amount = amountSentFromWallet - changeAmount - fee;
final possible = final possible =
outputAddresses.difference(myChangeReceivedOnAddresses).first; outputAddresses.difference(myChangeReceivedOnAddresses).first;
if (transactionAddress.value != possible) { if (transactionAddress.value != possible) {
transactionAddress = Address() transactionAddress = Address(
..walletId = walletId walletId: walletId,
..value = possible value: possible,
..derivationIndex = -1 derivationIndex: -1,
..subType = AddressSubType.nonWallet subType: AddressSubType.nonWallet,
..type = AddressType.nonWallet type: AddressType.nonWallet,
..publicKey = []; publicKey: [],
);
} }
} else { } else {
// incoming tx // incoming tx
tx.type = TransactionType.incoming; type = TransactionType.incoming;
tx.amount = amountReceivedInWallet; amount = amountReceivedInWallet;
} }
// TODO: other subtypes final tx = Transaction(
tx.subType = TransactionSubType.none; walletId: walletId,
txid: txData["txid"] as String,
tx.fee = fee; timestamp: txData["blocktime"] as int? ??
(DateTime.now().millisecondsSinceEpoch ~/ 1000),
type: type,
subType: TransactionSubType.none,
amount: amount,
fee: fee,
height: txData["height"] as int?,
isCancelled: false,
isLelantus: false,
slateId: null,
otherData: null,
);
List<Output> outs = []; List<Output> outs = [];
List<Input> ins = []; List<Input> ins = [];
for (final json in txData["vin"] as List) { for (final json in txData["vin"] as List) {
bool isCoinBase = json['coinbase'] != null; bool isCoinBase = json['coinbase'] != null;
final input = Input()..walletId = walletId; final input = Input(
input.txid = json['txid'] as String; walletId: walletId,
input.vout = json['vout'] as int? ?? -1; txid: json['txid'] as String,
input.scriptSig = json['scriptSig']?['hex'] as String?; vout: json['vout'] as int? ?? -1,
input.scriptSigAsm = json['scriptSig']?['asm'] as String?; scriptSig: json['scriptSig']?['hex'] as String?,
input.isCoinbase = isCoinBase ? isCoinBase : json['is_coinbase'] as bool?; scriptSigAsm: json['scriptSig']?['asm'] as String?,
input.sequence = json['sequence'] as int?; isCoinbase: isCoinBase ? isCoinBase : json['is_coinbase'] as bool?,
input.innerRedeemScriptAsm = json['innerRedeemscriptAsm'] as String?; sequence: json['sequence'] as int?,
innerRedeemScriptAsm: json['innerRedeemscriptAsm'] as String?,
);
ins.add(input); ins.add(input);
} }
for (final json in txData["vout"] as List) { for (final json in txData["vout"] as List) {
final output = Output()..walletId = walletId; final output = Output(
output.scriptPubKey = json['scriptPubKey']?['hex'] as String?; walletId: walletId,
output.scriptPubKeyAsm = json['scriptPubKey']?['asm'] as String?; scriptPubKey: json['scriptPubKey']?['hex'] as String?,
output.scriptPubKeyType = json['scriptPubKey']?['type'] as String?; scriptPubKeyAsm: json['scriptPubKey']?['asm'] as String?,
output.scriptPubKeyAddress = scriptPubKeyType: json['scriptPubKey']?['type'] as String?,
json["scriptPubKey"]?["addresses"]?[0] as String? ?? scriptPubKeyAddress: json["scriptPubKey"]?["addresses"]?[0] as String? ??
json['scriptPubKey']['type'] as String; json['scriptPubKey']['type'] as String,
output.value = Format.decimalAmountToSatoshis( value: Format.decimalAmountToSatoshis(
Decimal.parse(json["value"].toString()), Decimal.parse(json["value"].toString()),
coin, coin,
),
); );
outs.add(output); outs.add(output);
} }
tx.height = txData["height"] as int?;
//TODO: change these for epic (or other coins that need it)
tx.isCancelled = false;
tx.slateId = null;
tx.otherData = null;
tx.isLelantus = null;
return Tuple4(tx, outs, ins, transactionAddress); return Tuple4(tx, outs, ins, transactionAddress);
} }

View file

@ -354,15 +354,16 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
data: PaymentData(pubkey: node.publicKey), network: network) data: PaymentData(pubkey: node.publicKey), network: network)
.data .data
.address!; .address!;
address = isar_models.Address() address = isar_models.Address(
..walletId = walletId walletId: walletId,
..subType = chain == 0 value: addressString,
publicKey: node.publicKey,
type: isar_models.AddressType.p2pkh,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = isar_models.AddressType.p2pkh );
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
break; break;
default: default:
throw Exception("No Path type $type exists"); throw Exception("No Path type $type exists");
@ -1278,16 +1279,16 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
wif: node.toWIF(), wif: node.toWIF(),
derivePathType: derivePathType, derivePathType: derivePathType,
); );
return isar_models.Address(
return isar_models.Address() walletId: walletId,
..walletId = walletId value: address,
..derivationIndex = index publicKey: node.publicKey,
..value = address type: isar_models.AddressType.p2pkh,
..publicKey = node.publicKey derivationIndex: index,
..type = isar_models.AddressType.p2pkh subType: chain == 0
..subType = chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
/// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain] /// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain]
@ -1494,21 +1495,20 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO()..walletId = walletId;
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;

View file

@ -2025,30 +2025,31 @@ class EpicCashWallet extends CoinServiceAPI
DateTime dt = DateTime.parse(tx["creation_ts"] as String); DateTime dt = DateTime.parse(tx["creation_ts"] as String);
final txn = isar_models.Transaction();
txn.type = (tx["tx_type"] == "TxReceived" ||
tx["tx_type"] == "TxReceivedCancelled")
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing;
String? slateId = tx['tx_slate_id'] as String?; String? slateId = tx['tx_slate_id'] as String?;
String? address = slatesToCommits[slateId] String address = slatesToCommits[slateId]
?[tx["tx_type"] == "TxReceived" ? "from" : "to"] as String? ?? ?[tx["tx_type"] == "TxReceived" ? "from" : "to"] as String? ??
""; "";
String? commitId = slatesToCommits[slateId]?['commitId'] as String?; String? commitId = slatesToCommits[slateId]?['commitId'] as String?;
Logging.instance.log(
"commitId: $commitId, slateId: $slateId, id: ${tx["id"]}",
level: LogLevel.Info);
bool isCancelled = tx["tx_type"] == "TxSentCancelled" || final txn = isar_models.Transaction(
tx["tx_type"] == "TxReceivedCancelled"; walletId: walletId,
txid: commitId ?? tx["id"].toString(),
timestamp: (dt.millisecondsSinceEpoch ~/ 1000),
type: (tx["tx_type"] == "TxReceived" ||
tx["tx_type"] == "TxReceivedCancelled")
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing,
subType: isar_models.TransactionSubType.none,
amount: amt,
fee: (tx["fee"] == null) ? 0 : int.parse(tx["fee"] as String),
height: txHeight,
isCancelled: tx["tx_type"] == "TxSentCancelled" ||
tx["tx_type"] == "TxReceivedCancelled",
isLelantus: false,
slateId: slateId,
otherData: tx["id"].toString(),
);
txn.slateId = slateId;
txn.isCancelled = isCancelled;
txn.txid = commitId ?? tx["id"].toString();
txn.timestamp = (dt.millisecondsSinceEpoch ~/ 1000);
txn.amount = amt;
txn.fee = (tx["fee"] == null) ? 0 : int.parse(tx["fee"] as String);
// txn.address = // txn.address =
// ""; // for this when you send a transaction you will just need to save in a hashmap in hive with the key being the txid, and the value being the address it was sent to. then you can look this value up right here in your hashmap. // ""; // for this when you send a transaction you will just need to save in a hashmap in hive with the key being the txid, and the value being the address it was sent to. then you can look this value up right here in your hashmap.
txn.address.value = await db txn.address.value = await db
@ -2056,7 +2057,6 @@ class EpicCashWallet extends CoinServiceAPI
.filter() .filter()
.valueEqualTo(address) .valueEqualTo(address)
.findFirst(); .findFirst();
txn.height = txHeight;
// //
// midSortedTx["inputSize"] = tx["num_inputs"]; // midSortedTx["inputSize"] = tx["num_inputs"];
@ -2068,8 +2068,6 @@ class EpicCashWallet extends CoinServiceAPI
// key id not used afaik? // key id not used afaik?
// midSortedTx["key_id"] = tx["parent_key_id"]; // midSortedTx["key_id"] = tx["parent_key_id"];
txn.otherData = tx["id"].toString();
// if (txHeight >= latestTxnBlockHeight) { // if (txHeight >= latestTxnBlockHeight) {
// latestTxnBlockHeight = txHeight; // latestTxnBlockHeight = txHeight;
// } // }

View file

@ -417,20 +417,23 @@ Future<Map<dynamic, dynamic>> staticProcessRestore(
int mintFee = tx.fee; int mintFee = tx.fee;
int sharedFee = mintFee ~/ inputs.length; int sharedFee = mintFee ~/ inputs.length;
for (var element in inputs) { for (var element in inputs) {
editedTransactions[element.txid] = isar_models.Transaction() editedTransactions[element.txid] = isar_models.Transaction(
..txid = element.txid walletId: element.walletId,
..timestamp = element.timestamp txid: element.txid,
..type = element.type timestamp: element.timestamp,
..amount = element.amount type: element.type,
..fee = sharedFee subType: isar_models.TransactionSubType.mint,
amount: element.amount,
fee: sharedFee,
height: element.height,
isCancelled: false,
isLelantus: true,
slateId: null,
otherData: txid,
)
..inputs.addAll(element.inputs) ..inputs.addAll(element.inputs)
..outputs.addAll(element.outputs) ..outputs.addAll(element.outputs)
..address.value = element.address.value ..address.value = element.address.value;
..height = element.height
..subType = isar_models.TransactionSubType.mint
..otherData = txid
..isLelantus = true
..isCancelled = false;
} }
}); });
} }
@ -2947,31 +2950,39 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
await firoUpdateLelantusCoins(coins); await firoUpdateLelantusCoins(coins);
// add the send transaction // add the send transaction
final transaction = isar_models.Transaction() final transaction = isar_models.Transaction(
..txid = transactionInfo['txid'] as String walletId: walletId,
..timestamp = transactionInfo['timestamp'] as int? ?? txid: transactionInfo['txid'] as String,
(DateTime.now().millisecondsSinceEpoch ~/ 1000) timestamp: transactionInfo['timestamp'] as int? ??
..type = transactionInfo['txType'] == "Received" (DateTime.now().millisecondsSinceEpoch ~/ 1000),
type: transactionInfo['txType'] == "Received"
? isar_models.TransactionType.incoming ? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing : isar_models.TransactionType.outgoing,
..amount = Format.decimalAmountToSatoshis( subType: transactionInfo["subType"] == "mint"
Decimal.parse(transactionInfo["amount"].toString()), coin)
..fee = Format.decimalAmountToSatoshis(
Decimal.parse(transactionInfo["fees"].toString()), coin)
..address.value = await db
.getAddresses(walletId)
.filter()
.valueEqualTo(transactionInfo["address"] as String)
.findFirst()
..height = transactionInfo["height"] as int?
..subType = transactionInfo["subType"] == "mint"
? isar_models.TransactionSubType.mint ? isar_models.TransactionSubType.mint
: transactionInfo["subType"] == "join" : transactionInfo["subType"] == "join"
? isar_models.TransactionSubType.join ? isar_models.TransactionSubType.join
: isar_models.TransactionSubType.none : isar_models.TransactionSubType.none,
..otherData = transactionInfo["otherData"] as String? amount: Format.decimalAmountToSatoshis(
..isLelantus = true Decimal.parse(transactionInfo["amount"].toString()),
..isCancelled = false; coin,
),
fee: Format.decimalAmountToSatoshis(
Decimal.parse(transactionInfo["fees"].toString()),
coin,
),
height: transactionInfo["height"] as int?,
isCancelled: false,
isLelantus: true,
slateId: null,
otherData: transactionInfo["otherData"] as String?,
);
transaction.address.value = await db
.getAddresses(walletId)
.filter()
.valueEqualTo(transactionInfo["address"] as String)
.findFirst();
await db.putTransaction(transaction); await db.putTransaction(transaction);
@ -3344,21 +3355,20 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO();
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;
@ -3507,15 +3517,17 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
level: LogLevel.Info); level: LogLevel.Info);
return _generateAddressForChain(chain, index); return _generateAddressForChain(chain, index);
} }
return isar_models.Address() return isar_models.Address(
..value = derivations["$index"]['address'] as String walletId: walletId,
..publicKey = Format.stringToUint8List( value: derivations["$index"]['address'] as String,
derivations["$index"]['publicKey'] as String) publicKey: Format.stringToUint8List(
..subType = chain == 0 derivations["$index"]['publicKey'] as String),
type: isar_models.AddressType.p2pkh,
derivationIndex: index,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = isar_models.AddressType.p2pkh );
..derivationIndex = index;
} else { } else {
final node = await compute( final node = await compute(
getBip32NodeWrapper, Tuple4(chain, index, mnemonic!, _network)); getBip32NodeWrapper, Tuple4(chain, index, mnemonic!, _network));
@ -3524,14 +3536,16 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
.data .data
.address!; .address!;
return isar_models.Address() return isar_models.Address(
..value = address walletId: walletId,
..publicKey = node.publicKey value: address,
..subType = chain == 0 publicKey: node.publicKey,
type: isar_models.AddressType.p2pkh,
derivationIndex: index,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = isar_models.AddressType.p2pkh );
..derivationIndex = index;
} }
} }
@ -3921,13 +3935,15 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
int numTxs = await futureNumTxs; int numTxs = await futureNumTxs;
if (numTxs >= 1) { if (numTxs >= 1) {
receivingIndex = i; receivingIndex = i;
final addr = isar_models.Address() final addr = isar_models.Address(
..value = address walletId: walletId,
..type = isar_models.AddressType.p2pkh value: address,
..subType = isar_models.AddressSubType.receiving publicKey: Format.stringToUint8List(
..derivationIndex = i receiveDerivation['publicKey'] as String),
..publicKey = Format.stringToUint8List( type: isar_models.AddressType.p2pkh,
receiveDerivation['publicKey'] as String); derivationIndex: i,
subType: isar_models.AddressSubType.receiving,
);
receivingAddressArray.add(addr); receivingAddressArray.add(addr);
} else if (numTxs == 0) { } else if (numTxs == 0) {
receivingGapCounter += 1; receivingGapCounter += 1;
@ -3945,13 +3961,15 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
int numTxs = await _futureNumTxs; int numTxs = await _futureNumTxs;
if (numTxs >= 1) { if (numTxs >= 1) {
changeIndex = i; changeIndex = i;
final addr = isar_models.Address() final addr = isar_models.Address(
..value = address walletId: walletId,
..type = isar_models.AddressType.p2pkh value: address,
..subType = isar_models.AddressSubType.change publicKey: Format.stringToUint8List(
..derivationIndex = i changeDerivation['publicKey'] as String),
..publicKey = Format.stringToUint8List( type: isar_models.AddressType.p2pkh,
changeDerivation['publicKey'] as String); derivationIndex: i,
subType: isar_models.AddressSubType.change,
);
changeAddressArray.add(addr); changeAddressArray.add(addr);
} else if (numTxs == 0) { } else if (numTxs == 0) {
changeGapCounter += 1; changeGapCounter += 1;
@ -4475,24 +4493,33 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
tx["address"] = tx["vout"][sendIndex]["scriptPubKey"]["addresses"][0]; tx["address"] = tx["vout"][sendIndex]["scriptPubKey"]["addresses"][0];
tx["fees"] = tx["vin"][0]["nFees"]; tx["fees"] = tx["vin"][0]["nFees"];
final txn = isar_models.Transaction() final txn = isar_models.Transaction(
..isLelantus = true walletId: walletId,
..txid = tx["txid"] as String txid: tx["txid"] as String,
..timestamp = tx["time"] as int? ?? timestamp: tx["time"] as int? ??
(DateTime.now().millisecondsSinceEpoch ~/ 1000) (DateTime.now().millisecondsSinceEpoch ~/ 1000),
..type = isar_models.TransactionType.outgoing type: isar_models.TransactionType.outgoing,
..subType = isar_models.TransactionSubType.join subType: isar_models.TransactionSubType.join,
..fee = Format.decimalAmountToSatoshis( amount: Format.decimalAmountToSatoshis(
Decimal.parse(tx["fees"].toString()), coin) Decimal.parse(tx["amount"].toString()),
..address.value = await db coin,
.getAddresses(walletId) ),
.filter() fee: Format.decimalAmountToSatoshis(
.valueEqualTo(tx["address"] as String) Decimal.parse(tx["fees"].toString()),
.findFirst() coin,
..amount = Format.decimalAmountToSatoshis( ),
Decimal.parse(tx["amount"].toString()), coin) height: tx["height"] as int?,
..isCancelled = false isCancelled: false,
..height = tx["height"] as int?; isLelantus: true,
slateId: null,
otherData: null,
);
txn.address.value = await db
.getAddresses(walletId)
.filter()
.valueEqualTo(tx["address"] as String)
.findFirst();
txs.add(txn); txs.add(txn);
} catch (e, s) { } catch (e, s) {

View file

@ -419,14 +419,16 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists"); throw Exception("No Path type $type exists");
} }
final address = isar_models.Address() final address = isar_models.Address(
..subType = chain == 0 walletId: walletId,
value: addressString,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = addrType );
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
receivingNodes.addAll({ receivingNodes.addAll({
"${_id}_$j": { "${_id}_$j": {
@ -1533,14 +1535,16 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType, derivePathType: derivePathType,
); );
return isar_models.Address() return isar_models.Address(
..derivationIndex = index walletId: walletId,
..value = address value: address,
..publicKey = node.publicKey publicKey: node.publicKey,
..type = addrType type: addrType,
..subType = chain == 0 derivationIndex: index,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
/// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain] /// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain]
@ -1728,21 +1732,20 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO();
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;

View file

@ -807,14 +807,16 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// //
String address = walletBase!.getTransactionAddress(chain, index); String address = walletBase!.getTransactionAddress(chain, index);
return isar_models.Address() return isar_models.Address(
..derivationIndex = index walletId: walletId,
..value = address derivationIndex: index,
..publicKey = [] value: address,
..type = isar_models.AddressType.cryptonote publicKey: [],
..subType = chain == 0 type: isar_models.AddressType.cryptonote,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
Future<FeeObject> _getFees() async { Future<FeeObject> _getFees() async {
@ -861,12 +863,8 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// " ${tx.value.keyIndex}", // " ${tx.value.keyIndex}",
// level: LogLevel.Info); // level: LogLevel.Info);
final int txHeight = tx.value.height ?? 0;
final txn = isar_models.Transaction();
txn.txid = tx.value.id;
txn.timestamp = (tx.value.date.millisecondsSinceEpoch ~/ 1000);
isar_models.Address? address; isar_models.Address? address;
isar_models.TransactionType type;
if (tx.value.direction == TransactionDirection.incoming) { if (tx.value.direction == TransactionDirection.incoming) {
final addressInfo = tx.value.additionalInfo; final addressInfo = tx.value.additionalInfo;
@ -883,25 +881,26 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
.findFirst(); .findFirst();
} }
txn.type = isar_models.TransactionType.incoming; type = isar_models.TransactionType.incoming;
} else { } else {
// txn.address = ""; // txn.address = "";
txn.type = isar_models.TransactionType.outgoing; type = isar_models.TransactionType.outgoing;
} }
txn.amount = tx.value.amount ?? 0; final txn = isar_models.Transaction(
walletId: walletId,
// TODO: other subtypes txid: tx.value.id,
txn.subType = isar_models.TransactionSubType.none; timestamp: (tx.value.date.millisecondsSinceEpoch ~/ 1000),
type: type,
txn.fee = tx.value.fee ?? 0; subType: isar_models.TransactionSubType.none,
amount: tx.value.amount ?? 0,
txn.height = txHeight; fee: tx.value.fee ?? 0,
height: tx.value.height,
txn.isCancelled = false; isCancelled: false,
txn.isLelantus = null; isLelantus: false,
txn.slateId = null; slateId: null,
txn.otherData = null; otherData: null,
);
txnsData.add(Tuple4(txn, [], [], address)); txnsData.add(Tuple4(txn, [], [], address));
} }

View file

@ -409,14 +409,16 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists"); throw Exception("No Path type $type exists");
} }
final address = isar_models.Address() final address = isar_models.Address(
..subType = chain == 0 walletId: walletId,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = addrType type: addrType,
..publicKey = node.publicKey publicKey: node.publicKey,
..value = addressString value: addressString,
..derivationIndex = index + j; derivationIndex: index + j,
);
receivingNodes.addAll({ receivingNodes.addAll({
"${_id}_$j": { "${_id}_$j": {
@ -1510,14 +1512,16 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType, derivePathType: derivePathType,
); );
return isar_models.Address() return isar_models.Address(
..derivationIndex = index walletId: walletId,
..value = address derivationIndex: index,
..publicKey = node.publicKey value: address,
..type = addrType publicKey: node.publicKey,
..subType = chain == 0 type: addrType,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
/// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain] /// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain]
@ -1707,21 +1711,20 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO();
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;

View file

@ -392,14 +392,16 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists"); throw Exception("No Path type $type exists");
} }
final address = isar_models.Address() final address = isar_models.Address(
..subType = chain == 0 walletId: walletId,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change : isar_models.AddressSubType.change,
..type = addrType type: addrType,
..publicKey = node.publicKey publicKey: node.publicKey,
..value = addressString value: addressString,
..derivationIndex = index + j; derivationIndex: index + j,
);
receivingNodes.addAll({ receivingNodes.addAll({
"${_id}_$j": { "${_id}_$j": {
@ -1407,14 +1409,16 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType, derivePathType: derivePathType,
); );
return isar_models.Address() return isar_models.Address(
..derivationIndex = index walletId: walletId,
..value = address derivationIndex: index,
..publicKey = node.publicKey value: address,
..type = addrType publicKey: node.publicKey,
..subType = chain == 0 type: addrType,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
/// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain] /// Returns the latest receiving/change (external/internal) address for the wallet depending on [chain]
@ -1597,21 +1601,20 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
coin: coin, coin: coin,
); );
final utxo = isar_models.UTXO();
utxo.txid = txn["txid"] as String;
utxo.vout = fetchedUtxoList[i][j]["tx_pos"] as int;
utxo.value = fetchedUtxoList[i][j]["value"] as int;
utxo.name = "";
// todo check here if we should mark as blocked // todo check here if we should mark as blocked
utxo.isBlocked = false; final utxo = isar_models.UTXO(
utxo.blockedReason = null; walletId: walletId,
txid: txn["txid"] as String,
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false; vout: fetchedUtxoList[i][j]["tx_pos"] as int,
utxo.blockHash = txn["blockhash"] as String?; value: fetchedUtxoList[i][j]["value"] as int,
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?; name: "",
utxo.blockTime = txn["blocktime"] as int?; isBlocked: false,
blockedReason: null,
isCoinbase: txn["is_coinbase"] as bool? ?? false,
blockHash: txn["blockhash"] as String?,
blockHeight: fetchedUtxoList[i][j]["height"] as int?,
blockTime: txn["blocktime"] as int?,
);
satoshiBalanceTotal += utxo.value; satoshiBalanceTotal += utxo.value;
@ -2231,25 +2234,32 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
midSortedTx["inputs"] = txObject["vin"]; midSortedTx["inputs"] = txObject["vin"];
midSortedTx["outputs"] = txObject["vout"]; midSortedTx["outputs"] = txObject["vout"];
final int height = txObject["height"] as int;
// midSortedArray.add(midSortedTx); // midSortedArray.add(midSortedTx);
final tx = isar_models.Transaction(); isar_models.TransactionType type;
tx.txid = midSortedTx["txid"] as String; int amount;
tx.timestamp = midSortedTx["timestamp"] as int;
if (foundInSenders) { if (foundInSenders) {
tx.type = isar_models.TransactionType.outgoing; type = isar_models.TransactionType.outgoing;
tx.amount = inputAmtSentFromWallet; amount = inputAmtSentFromWallet;
} else { } else {
tx.type = isar_models.TransactionType.incoming; type = isar_models.TransactionType.incoming;
tx.amount = outputAmtAddressedToWallet; amount = outputAmtAddressedToWallet;
} }
// TODO: other subtypes final tx = isar_models.Transaction(
tx.subType = isar_models.TransactionSubType.none; walletId: walletId,
txid: midSortedTx["txid"] as String,
timestamp: midSortedTx["timestamp"] as int,
type: type,
subType: isar_models.TransactionSubType.none,
amount: amount,
fee: fee,
height: txObject["height"] as int,
isCancelled: false,
isLelantus: false,
slateId: null,
otherData: null,
);
tx.fee = fee;
isar_models.Address? transactionAddress = isar_models.Address? transactionAddress =
midSortedTx["address"] as isar_models.Address?; midSortedTx["address"] as isar_models.Address?;
@ -2258,40 +2268,37 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
for (final json in midSortedTx["vin"] as List) { for (final json in midSortedTx["vin"] as List) {
bool isCoinBase = json['coinbase'] != null; bool isCoinBase = json['coinbase'] != null;
final input = isar_models.Input(); final input = isar_models.Input(
input.txid = json['txid'] as String? ?? ""; walletId: walletId,
input.vout = json['vout'] as int? ?? -1; txid: json['txid'] as String,
input.scriptSig = json['scriptSig']?['hex'] as String?; vout: json['vout'] as int? ?? -1,
input.scriptSigAsm = json['scriptSig']?['asm'] as String?; scriptSig: json['scriptSig']?['hex'] as String?,
input.isCoinbase = scriptSigAsm: json['scriptSig']?['asm'] as String?,
isCoinBase ? isCoinBase : json['is_coinbase'] as bool?; isCoinbase: isCoinBase ? isCoinBase : json['is_coinbase'] as bool?,
input.sequence = json['sequence'] as int?; sequence: json['sequence'] as int?,
input.innerRedeemScriptAsm = json['innerRedeemscriptAsm'] as String?; innerRedeemScriptAsm: json['innerRedeemscriptAsm'] as String?,
);
inputs.add(input); inputs.add(input);
} }
for (final json in midSortedTx["vout"] as List) { for (final json in midSortedTx["vout"] as List) {
final output = isar_models.Output(); final output = isar_models.Output(
output.scriptPubKey = json['scriptPubKey']?['hex'] as String?; walletId: walletId,
output.scriptPubKeyAsm = json['scriptPubKey']?['asm'] as String?; scriptPubKey: json['scriptPubKey']?['hex'] as String?,
output.scriptPubKeyType = json['scriptPubKey']?['type'] as String?; scriptPubKeyAsm: json['scriptPubKey']?['asm'] as String?,
output.scriptPubKeyAddress = scriptPubKeyType: json['scriptPubKey']?['type'] as String?,
json["scriptPubKey"]?["addresses"]?[0] as String? ?? scriptPubKeyAddress:
json['scriptPubKey']?['type'] as String? ?? json["scriptPubKey"]?["addresses"]?[0] as String? ??
""; json['scriptPubKey']['type'] as String? ??
output.value = Format.decimalAmountToSatoshis( "",
Decimal.tryParse(json["value"].toString()) ?? Decimal.zero, value: Format.decimalAmountToSatoshis(
coin, Decimal.parse(json["value"].toString()),
coin,
),
); );
outputs.add(output); outputs.add(output);
} }
tx.height = height;
tx.isCancelled = false;
tx.slateId = null;
tx.otherData = null;
txns.add(Tuple4(tx, outputs, inputs, transactionAddress)); txns.add(Tuple4(tx, outputs, inputs, transactionAddress));
} }

View file

@ -816,14 +816,16 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// //
String address = walletBase!.getTransactionAddress(chain, index); String address = walletBase!.getTransactionAddress(chain, index);
return isar_models.Address() return isar_models.Address(
..derivationIndex = index walletId: walletId,
..value = address derivationIndex: index,
..publicKey = [] value: address,
..type = isar_models.AddressType.cryptonote publicKey: [],
..subType = chain == 0 type: isar_models.AddressType.cryptonote,
subType: chain == 0
? isar_models.AddressSubType.receiving ? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change; : isar_models.AddressSubType.change,
);
} }
Future<FeeObject> _getFees() async { Future<FeeObject> _getFees() async {
@ -930,12 +932,8 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// midSortedTx["outputs"] = <dynamic>[]; // midSortedTx["outputs"] = <dynamic>[];
// midSortedArray.add(midSortedTx); // midSortedArray.add(midSortedTx);
final int txHeight = tx.value.height ?? 0;
final txn = isar_models.Transaction();
txn.txid = tx.value.id;
txn.timestamp = (tx.value.date.millisecondsSinceEpoch ~/ 1000);
isar_models.Address? address; isar_models.Address? address;
isar_models.TransactionType type;
if (tx.value.direction == TransactionDirection.incoming) { if (tx.value.direction == TransactionDirection.incoming) {
final addressInfo = tx.value.additionalInfo; final addressInfo = tx.value.additionalInfo;
@ -952,25 +950,26 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
.findFirst(); .findFirst();
} }
txn.type = isar_models.TransactionType.incoming; type = isar_models.TransactionType.incoming;
} else { } else {
// txn.address = ""; // txn.address = "";
txn.type = isar_models.TransactionType.outgoing; type = isar_models.TransactionType.outgoing;
} }
txn.amount = tx.value.amount ?? 0; final txn = isar_models.Transaction(
walletId: walletId,
// TODO: other subtypes txid: tx.value.id,
txn.subType = isar_models.TransactionSubType.none; timestamp: (tx.value.date.millisecondsSinceEpoch ~/ 1000),
type: type,
txn.fee = tx.value.fee ?? 0; subType: isar_models.TransactionSubType.none,
amount: tx.value.amount ?? 0,
txn.height = txHeight; fee: tx.value.fee ?? 0,
height: tx.value.height,
txn.isCancelled = false; isCancelled: false,
txn.isLelantus = null; isLelantus: false,
txn.slateId = null; slateId: null,
txn.otherData = null; otherData: null,
);
txnsData.add(Tuple4(txn, [], [], address)); txnsData.add(Tuple4(txn, [], [], address));
} }