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")
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;
@Index()
@ -56,6 +65,7 @@ enum AddressType {
p2sh,
p2wpkh,
cryptonote,
mimbleWimble,
nonWallet,
}
@ -65,5 +75,6 @@ enum AddressSubType {
paynymNotification,
paynymSend,
paynymReceive,
unknown,
nonWallet,
}

View file

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

View file

@ -6,6 +6,17 @@ part 'input.g.dart';
@Collection()
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;
@Index()

View file

@ -151,16 +151,17 @@ Input _inputDeserialize(
List<int> offsets,
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.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;
}

View file

@ -5,6 +5,15 @@ part 'output.g.dart';
@Collection()
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;
@Index()

View file

@ -133,14 +133,15 @@ Output _outputDeserialize(
List<int> offsets,
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.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;
}

View file

@ -9,6 +9,21 @@ part 'transaction.g.dart';
@Collection()
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;
@Index()

View file

@ -208,24 +208,24 @@ Transaction _transactionDeserialize(
List<int> offsets,
Map<Type, List<int>> allOffsets,
) {
final object = Transaction();
object.amount = reader.readLong(offsets[0]);
object.fee = reader.readLong(offsets[1]);
object.height = reader.readLongOrNull(offsets[2]);
final object = Transaction(
amount: reader.readLong(offsets[0]),
fee: reader.readLong(offsets[1]),
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.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;
}

View file

@ -6,6 +6,20 @@ part 'utxo.g.dart';
@Collection(accessor: "utxos")
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;
@Index()

View file

@ -181,19 +181,20 @@ UTXO _uTXODeserialize(
List<int> offsets,
Map<Type, List<int>> allOffsets,
) {
final object = UTXO();
object.blockHash = reader.readStringOrNull(offsets[0]);
object.blockHeight = reader.readLongOrNull(offsets[1]);
object.blockTime = reader.readLongOrNull(offsets[2]);
object.blockedReason = reader.readStringOrNull(offsets[3]);
final object = UTXO(
blockHash: reader.readStringOrNull(offsets[0]),
blockHeight: reader.readLongOrNull(offsets[1]),
blockTime: reader.readLongOrNull(offsets[2]),
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.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;
}

View file

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

View file

@ -108,11 +108,12 @@ TransactionNote _transactionNoteDeserialize(
List<int> offsets,
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.txid = reader.readString(offsets[0]);
object.value = reader.readString(offsets[1]);
object.walletId = reader.readString(offsets[2]);
return object;
}

View file

@ -402,14 +402,16 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists");
}
final address = isar_models.Address()
..subType = chain == 0
final address = isar_models.Address(
walletId: walletId,
value: addressString,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change
..type = addrType
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
: isar_models.AddressSubType.change,
);
receivingNodes.addAll({
"${_id}_$j": {
@ -1507,14 +1509,16 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType,
);
return isar_models.Address()
..derivationIndex = index
..value = address
..publicKey = node.publicKey
..type = addrType
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
value: address,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index,
subType: chain == 0
? 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]
@ -1739,21 +1743,20 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
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
utxo.isBlocked = false;
utxo.blockedReason = null;
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false;
utxo.blockHash = txn["blockhash"] as String?;
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?;
utxo.blockTime = txn["blocktime"] as int?;
final utxo = isar_models.UTXO(
walletId: walletId,
txid: txn["txid"] as String,
vout: fetchedUtxoList[i][j]["tx_pos"] as int,
value: fetchedUtxoList[i][j]["value"] as int,
name: "",
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;

View file

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

View file

@ -667,87 +667,90 @@ Future<Tuple4<Transaction, List<Output>, List<Input>, Address>>
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
Address transactionAddress = txData["address"] as Address;
TransactionType type;
int amount;
if (mySentFromAddresses.isNotEmpty && myReceivedOnAddresses.isNotEmpty) {
// tx is sent to self
tx.type = TransactionType.sentToSelf;
type = TransactionType.sentToSelf;
// should be 0
tx.amount =
amountSentFromWallet - amountReceivedInWallet - fee - changeAmount;
amount = amountSentFromWallet - amountReceivedInWallet - fee - changeAmount;
} else if (mySentFromAddresses.isNotEmpty) {
// outgoing tx
tx.type = TransactionType.outgoing;
tx.amount = amountSentFromWallet - changeAmount - fee;
type = TransactionType.outgoing;
amount = amountSentFromWallet - changeAmount - fee;
final possible =
outputAddresses.difference(myChangeReceivedOnAddresses).first;
if (transactionAddress.value != possible) {
transactionAddress = Address()
..walletId = walletId
..value = possible
..derivationIndex = -1
..subType = AddressSubType.nonWallet
..type = AddressType.nonWallet
..publicKey = [];
transactionAddress = Address(
walletId: walletId,
value: possible,
derivationIndex: -1,
subType: AddressSubType.nonWallet,
type: AddressType.nonWallet,
publicKey: [],
);
}
} else {
// incoming tx
tx.type = TransactionType.incoming;
tx.amount = amountReceivedInWallet;
type = TransactionType.incoming;
amount = amountReceivedInWallet;
}
// TODO: other subtypes
tx.subType = TransactionSubType.none;
tx.fee = fee;
final tx = Transaction(
walletId: walletId,
txid: txData["txid"] as String,
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<Input> ins = [];
for (final json in txData["vin"] as List) {
bool isCoinBase = json['coinbase'] != null;
final input = Input()..walletId = walletId;
input.txid = json['txid'] as String;
input.vout = json['vout'] as int? ?? -1;
input.scriptSig = json['scriptSig']?['hex'] as String?;
input.scriptSigAsm = json['scriptSig']?['asm'] as String?;
input.isCoinbase = isCoinBase ? isCoinBase : json['is_coinbase'] as bool?;
input.sequence = json['sequence'] as int?;
input.innerRedeemScriptAsm = json['innerRedeemscriptAsm'] as String?;
final input = Input(
walletId: walletId,
txid: json['txid'] as String,
vout: json['vout'] as int? ?? -1,
scriptSig: json['scriptSig']?['hex'] as String?,
scriptSigAsm: json['scriptSig']?['asm'] as String?,
isCoinbase: isCoinBase ? isCoinBase : json['is_coinbase'] as bool?,
sequence: json['sequence'] as int?,
innerRedeemScriptAsm: json['innerRedeemscriptAsm'] as String?,
);
ins.add(input);
}
for (final json in txData["vout"] as List) {
final output = Output()..walletId = walletId;
output.scriptPubKey = json['scriptPubKey']?['hex'] as String?;
output.scriptPubKeyAsm = json['scriptPubKey']?['asm'] as String?;
output.scriptPubKeyType = json['scriptPubKey']?['type'] as String?;
output.scriptPubKeyAddress =
json["scriptPubKey"]?["addresses"]?[0] as String? ??
json['scriptPubKey']['type'] as String;
output.value = Format.decimalAmountToSatoshis(
Decimal.parse(json["value"].toString()),
coin,
final output = Output(
walletId: walletId,
scriptPubKey: json['scriptPubKey']?['hex'] as String?,
scriptPubKeyAsm: json['scriptPubKey']?['asm'] as String?,
scriptPubKeyType: json['scriptPubKey']?['type'] as String?,
scriptPubKeyAddress: json["scriptPubKey"]?["addresses"]?[0] as String? ??
json['scriptPubKey']['type'] as String,
value: Format.decimalAmountToSatoshis(
Decimal.parse(json["value"].toString()),
coin,
),
);
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);
}

View file

@ -354,15 +354,16 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
data: PaymentData(pubkey: node.publicKey), network: network)
.data
.address!;
address = isar_models.Address()
..walletId = walletId
..subType = chain == 0
address = isar_models.Address(
walletId: walletId,
value: addressString,
publicKey: node.publicKey,
type: isar_models.AddressType.p2pkh,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change
..type = isar_models.AddressType.p2pkh
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
: isar_models.AddressSubType.change,
);
break;
default:
throw Exception("No Path type $type exists");
@ -1278,16 +1279,16 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
wif: node.toWIF(),
derivePathType: derivePathType,
);
return isar_models.Address()
..walletId = walletId
..derivationIndex = index
..value = address
..publicKey = node.publicKey
..type = isar_models.AddressType.p2pkh
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
value: address,
publicKey: node.publicKey,
type: isar_models.AddressType.p2pkh,
derivationIndex: index,
subType: chain == 0
? 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]
@ -1494,21 +1495,20 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
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
utxo.isBlocked = false;
utxo.blockedReason = null;
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false;
utxo.blockHash = txn["blockhash"] as String?;
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?;
utxo.blockTime = txn["blocktime"] as int?;
final utxo = isar_models.UTXO(
walletId: walletId,
txid: txn["txid"] as String,
vout: fetchedUtxoList[i][j]["tx_pos"] as int,
value: fetchedUtxoList[i][j]["value"] as int,
name: "",
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;

View file

@ -2025,30 +2025,31 @@ class EpicCashWallet extends CoinServiceAPI
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? address = slatesToCommits[slateId]
String address = slatesToCommits[slateId]
?[tx["tx_type"] == "TxReceived" ? "from" : "to"] 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" ||
tx["tx_type"] == "TxReceivedCancelled";
final txn = isar_models.Transaction(
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 =
// ""; // 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
@ -2056,7 +2057,6 @@ class EpicCashWallet extends CoinServiceAPI
.filter()
.valueEqualTo(address)
.findFirst();
txn.height = txHeight;
//
// midSortedTx["inputSize"] = tx["num_inputs"];
@ -2068,8 +2068,6 @@ class EpicCashWallet extends CoinServiceAPI
// key id not used afaik?
// midSortedTx["key_id"] = tx["parent_key_id"];
txn.otherData = tx["id"].toString();
// if (txHeight >= latestTxnBlockHeight) {
// latestTxnBlockHeight = txHeight;
// }

View file

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

View file

@ -419,14 +419,16 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists");
}
final address = isar_models.Address()
..subType = chain == 0
final address = isar_models.Address(
walletId: walletId,
value: addressString,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index + j,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change
..type = addrType
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
: isar_models.AddressSubType.change,
);
receivingNodes.addAll({
"${_id}_$j": {
@ -1533,14 +1535,16 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType,
);
return isar_models.Address()
..derivationIndex = index
..value = address
..publicKey = node.publicKey
..type = addrType
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
value: address,
publicKey: node.publicKey,
type: addrType,
derivationIndex: index,
subType: chain == 0
? 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]
@ -1728,21 +1732,20 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
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
utxo.isBlocked = false;
utxo.blockedReason = null;
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false;
utxo.blockHash = txn["blockhash"] as String?;
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?;
utxo.blockTime = txn["blocktime"] as int?;
final utxo = isar_models.UTXO(
walletId: walletId,
txid: txn["txid"] as String,
vout: fetchedUtxoList[i][j]["tx_pos"] as int,
value: fetchedUtxoList[i][j]["value"] as int,
name: "",
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;

View file

@ -807,14 +807,16 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
//
String address = walletBase!.getTransactionAddress(chain, index);
return isar_models.Address()
..derivationIndex = index
..value = address
..publicKey = []
..type = isar_models.AddressType.cryptonote
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
derivationIndex: index,
value: address,
publicKey: [],
type: isar_models.AddressType.cryptonote,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change;
: isar_models.AddressSubType.change,
);
}
Future<FeeObject> _getFees() async {
@ -861,12 +863,8 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// " ${tx.value.keyIndex}",
// 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.TransactionType type;
if (tx.value.direction == TransactionDirection.incoming) {
final addressInfo = tx.value.additionalInfo;
@ -883,25 +881,26 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
.findFirst();
}
txn.type = isar_models.TransactionType.incoming;
type = isar_models.TransactionType.incoming;
} else {
// txn.address = "";
txn.type = isar_models.TransactionType.outgoing;
type = isar_models.TransactionType.outgoing;
}
txn.amount = tx.value.amount ?? 0;
// TODO: other subtypes
txn.subType = isar_models.TransactionSubType.none;
txn.fee = tx.value.fee ?? 0;
txn.height = txHeight;
txn.isCancelled = false;
txn.isLelantus = null;
txn.slateId = null;
txn.otherData = null;
final txn = isar_models.Transaction(
walletId: walletId,
txid: tx.value.id,
timestamp: (tx.value.date.millisecondsSinceEpoch ~/ 1000),
type: type,
subType: isar_models.TransactionSubType.none,
amount: tx.value.amount ?? 0,
fee: tx.value.fee ?? 0,
height: tx.value.height,
isCancelled: false,
isLelantus: false,
slateId: null,
otherData: null,
);
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");
}
final address = isar_models.Address()
..subType = chain == 0
final address = isar_models.Address(
walletId: walletId,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change
..type = addrType
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
: isar_models.AddressSubType.change,
type: addrType,
publicKey: node.publicKey,
value: addressString,
derivationIndex: index + j,
);
receivingNodes.addAll({
"${_id}_$j": {
@ -1510,14 +1512,16 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType,
);
return isar_models.Address()
..derivationIndex = index
..value = address
..publicKey = node.publicKey
..type = addrType
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
derivationIndex: index,
value: address,
publicKey: node.publicKey,
type: addrType,
subType: chain == 0
? 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]
@ -1707,21 +1711,20 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
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
utxo.isBlocked = false;
utxo.blockedReason = null;
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false;
utxo.blockHash = txn["blockhash"] as String?;
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?;
utxo.blockTime = txn["blocktime"] as int?;
final utxo = isar_models.UTXO(
walletId: walletId,
txid: txn["txid"] as String,
vout: fetchedUtxoList[i][j]["tx_pos"] as int,
value: fetchedUtxoList[i][j]["value"] as int,
name: "",
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;

View file

@ -392,14 +392,16 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
throw Exception("No Path type $type exists");
}
final address = isar_models.Address()
..subType = chain == 0
final address = isar_models.Address(
walletId: walletId,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change
..type = addrType
..publicKey = node.publicKey
..value = addressString
..derivationIndex = index + j;
: isar_models.AddressSubType.change,
type: addrType,
publicKey: node.publicKey,
value: addressString,
derivationIndex: index + j,
);
receivingNodes.addAll({
"${_id}_$j": {
@ -1407,14 +1409,16 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
derivePathType: derivePathType,
);
return isar_models.Address()
..derivationIndex = index
..value = address
..publicKey = node.publicKey
..type = addrType
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
derivationIndex: index,
value: address,
publicKey: node.publicKey,
type: addrType,
subType: chain == 0
? 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]
@ -1597,21 +1601,20 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
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
utxo.isBlocked = false;
utxo.blockedReason = null;
utxo.isCoinbase = txn["is_coinbase"] as bool? ?? false;
utxo.blockHash = txn["blockhash"] as String?;
utxo.blockHeight = fetchedUtxoList[i][j]["height"] as int?;
utxo.blockTime = txn["blocktime"] as int?;
final utxo = isar_models.UTXO(
walletId: walletId,
txid: txn["txid"] as String,
vout: fetchedUtxoList[i][j]["tx_pos"] as int,
value: fetchedUtxoList[i][j]["value"] as int,
name: "",
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;
@ -2231,25 +2234,32 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
midSortedTx["inputs"] = txObject["vin"];
midSortedTx["outputs"] = txObject["vout"];
final int height = txObject["height"] as int;
// midSortedArray.add(midSortedTx);
final tx = isar_models.Transaction();
tx.txid = midSortedTx["txid"] as String;
tx.timestamp = midSortedTx["timestamp"] as int;
isar_models.TransactionType type;
int amount;
if (foundInSenders) {
tx.type = isar_models.TransactionType.outgoing;
tx.amount = inputAmtSentFromWallet;
type = isar_models.TransactionType.outgoing;
amount = inputAmtSentFromWallet;
} else {
tx.type = isar_models.TransactionType.incoming;
tx.amount = outputAmtAddressedToWallet;
type = isar_models.TransactionType.incoming;
amount = outputAmtAddressedToWallet;
}
// TODO: other subtypes
tx.subType = isar_models.TransactionSubType.none;
final tx = isar_models.Transaction(
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 =
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) {
bool isCoinBase = json['coinbase'] != null;
final input = isar_models.Input();
input.txid = json['txid'] as String? ?? "";
input.vout = json['vout'] as int? ?? -1;
input.scriptSig = json['scriptSig']?['hex'] as String?;
input.scriptSigAsm = json['scriptSig']?['asm'] as String?;
input.isCoinbase =
isCoinBase ? isCoinBase : json['is_coinbase'] as bool?;
input.sequence = json['sequence'] as int?;
input.innerRedeemScriptAsm = json['innerRedeemscriptAsm'] as String?;
final input = isar_models.Input(
walletId: walletId,
txid: json['txid'] as String,
vout: json['vout'] as int? ?? -1,
scriptSig: json['scriptSig']?['hex'] as String?,
scriptSigAsm: json['scriptSig']?['asm'] as String?,
isCoinbase: isCoinBase ? isCoinBase : json['is_coinbase'] as bool?,
sequence: json['sequence'] as int?,
innerRedeemScriptAsm: json['innerRedeemscriptAsm'] as String?,
);
inputs.add(input);
}
for (final json in midSortedTx["vout"] as List) {
final output = isar_models.Output();
output.scriptPubKey = json['scriptPubKey']?['hex'] as String?;
output.scriptPubKeyAsm = json['scriptPubKey']?['asm'] as String?;
output.scriptPubKeyType = json['scriptPubKey']?['type'] as String?;
output.scriptPubKeyAddress =
json["scriptPubKey"]?["addresses"]?[0] as String? ??
json['scriptPubKey']?['type'] as String? ??
"";
output.value = Format.decimalAmountToSatoshis(
Decimal.tryParse(json["value"].toString()) ?? Decimal.zero,
coin,
final output = isar_models.Output(
walletId: walletId,
scriptPubKey: json['scriptPubKey']?['hex'] as String?,
scriptPubKeyAsm: json['scriptPubKey']?['asm'] as String?,
scriptPubKeyType: json['scriptPubKey']?['type'] as String?,
scriptPubKeyAddress:
json["scriptPubKey"]?["addresses"]?[0] as String? ??
json['scriptPubKey']['type'] as String? ??
"",
value: Format.decimalAmountToSatoshis(
Decimal.parse(json["value"].toString()),
coin,
),
);
outputs.add(output);
}
tx.height = height;
tx.isCancelled = false;
tx.slateId = null;
tx.otherData = null;
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);
return isar_models.Address()
..derivationIndex = index
..value = address
..publicKey = []
..type = isar_models.AddressType.cryptonote
..subType = chain == 0
return isar_models.Address(
walletId: walletId,
derivationIndex: index,
value: address,
publicKey: [],
type: isar_models.AddressType.cryptonote,
subType: chain == 0
? isar_models.AddressSubType.receiving
: isar_models.AddressSubType.change;
: isar_models.AddressSubType.change,
);
}
Future<FeeObject> _getFees() async {
@ -930,12 +932,8 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// midSortedTx["outputs"] = <dynamic>[];
// 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.TransactionType type;
if (tx.value.direction == TransactionDirection.incoming) {
final addressInfo = tx.value.additionalInfo;
@ -952,25 +950,26 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
.findFirst();
}
txn.type = isar_models.TransactionType.incoming;
type = isar_models.TransactionType.incoming;
} else {
// txn.address = "";
txn.type = isar_models.TransactionType.outgoing;
type = isar_models.TransactionType.outgoing;
}
txn.amount = tx.value.amount ?? 0;
// TODO: other subtypes
txn.subType = isar_models.TransactionSubType.none;
txn.fee = tx.value.fee ?? 0;
txn.height = txHeight;
txn.isCancelled = false;
txn.isLelantus = null;
txn.slateId = null;
txn.otherData = null;
final txn = isar_models.Transaction(
walletId: walletId,
txid: tx.value.id,
timestamp: (tx.value.date.millisecondsSinceEpoch ~/ 1000),
type: type,
subType: isar_models.TransactionSubType.none,
amount: tx.value.amount ?? 0,
fee: tx.value.fee ?? 0,
height: tx.value.height,
isCancelled: false,
isLelantus: false,
slateId: null,
otherData: null,
);
txnsData.add(Tuple4(txn, [], [], address));
}