mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-09 12:19:24 +00:00
mark transactions as fusion txns and use txV2 throughout bch
This commit is contained in:
parent
ad14c16bcc
commit
f96306cb76
3 changed files with 83 additions and 55 deletions
|
@ -386,6 +386,8 @@ class MainDB {
|
||||||
//
|
//
|
||||||
Future<void> deleteWalletBlockchainData(String walletId) async {
|
Future<void> deleteWalletBlockchainData(String walletId) async {
|
||||||
final transactionCount = await getTransactions(walletId).count();
|
final transactionCount = await getTransactions(walletId).count();
|
||||||
|
final transactionCountV2 =
|
||||||
|
await isar.transactionV2s.where().walletIdEqualTo(walletId).count();
|
||||||
final addressCount = await getAddresses(walletId).count();
|
final addressCount = await getAddresses(walletId).count();
|
||||||
final utxoCount = await getUTXOs(walletId).count();
|
final utxoCount = await getUTXOs(walletId).count();
|
||||||
final lelantusCoinCount =
|
final lelantusCoinCount =
|
||||||
|
@ -404,6 +406,18 @@ class MainDB {
|
||||||
await isar.transactions.deleteAll(txnIds);
|
await isar.transactions.deleteAll(txnIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transactions V2
|
||||||
|
for (int i = 0; i < transactionCountV2; i += paginateLimit) {
|
||||||
|
final txnIds = await isar.transactionV2s
|
||||||
|
.where()
|
||||||
|
.walletIdEqualTo(walletId)
|
||||||
|
.offset(i)
|
||||||
|
.limit(paginateLimit)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
|
await isar.transactionV2s.deleteAll(txnIds);
|
||||||
|
}
|
||||||
|
|
||||||
// addresses
|
// addresses
|
||||||
for (int i = 0; i < addressCount; i += paginateLimit) {
|
for (int i = 0; i < addressCount; i += paginateLimit) {
|
||||||
final addressIds = await getAddresses(walletId)
|
final addressIds = await getAddresses(walletId)
|
||||||
|
|
|
@ -367,7 +367,6 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
late final TransactionType txType;
|
late final TransactionType txType;
|
||||||
|
|
||||||
String whatIsIt(
|
String whatIsIt(
|
||||||
TransactionType type,
|
|
||||||
Coin coin,
|
Coin coin,
|
||||||
int currentHeight,
|
int currentHeight,
|
||||||
) {
|
) {
|
||||||
|
@ -376,7 +375,15 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
coin.requiredConfirmations,
|
coin.requiredConfirmations,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (type == TransactionType.incoming) {
|
if (_transaction.subType == TransactionSubType.cashFusion) {
|
||||||
|
if (confirmedStatus) {
|
||||||
|
return "Anonymized";
|
||||||
|
} else {
|
||||||
|
return "Anonymizing";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_transaction.type == TransactionType.incoming) {
|
||||||
// if (_transaction.isMinting) {
|
// if (_transaction.isMinting) {
|
||||||
// return "Minting";
|
// return "Minting";
|
||||||
// } else
|
// } else
|
||||||
|
@ -385,16 +392,16 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
} else {
|
} else {
|
||||||
return "Receiving";
|
return "Receiving";
|
||||||
}
|
}
|
||||||
} else if (type == TransactionType.outgoing) {
|
} else if (_transaction.type == TransactionType.outgoing) {
|
||||||
if (confirmedStatus) {
|
if (confirmedStatus) {
|
||||||
return "Sent";
|
return "Sent";
|
||||||
} else {
|
} else {
|
||||||
return "Sending";
|
return "Sending";
|
||||||
}
|
}
|
||||||
} else if (type == TransactionType.sentToSelf) {
|
} else if (_transaction.type == TransactionType.sentToSelf) {
|
||||||
return "Sent to self";
|
return "Sent to self";
|
||||||
} else {
|
} else {
|
||||||
return type.name;
|
return _transaction.type.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +513,6 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
child: Text(
|
child: Text(
|
||||||
whatIsIt(
|
whatIsIt(
|
||||||
_transaction.type,
|
|
||||||
coin,
|
coin,
|
||||||
currentHeight,
|
currentHeight,
|
||||||
),
|
),
|
||||||
|
|
|
@ -188,6 +188,7 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
@override
|
@override
|
||||||
Future<List<isar_models.UTXO>> get utxos => db.getUTXOs(walletId).findAll();
|
Future<List<isar_models.UTXO>> get utxos => db.getUTXOs(walletId).findAll();
|
||||||
|
|
||||||
|
@Deprecated("V2 soon (tm)")
|
||||||
@override
|
@override
|
||||||
Future<List<isar_models.Transaction>> get transactions =>
|
Future<List<isar_models.Transaction>> get transactions =>
|
||||||
db.getTransactions(walletId).sortByTimestampDesc().findAll();
|
db.getTransactions(walletId).sortByTimestampDesc().findAll();
|
||||||
|
@ -793,18 +794,20 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
|
|
||||||
Future<void> getAllTxsToWatch() async {
|
Future<void> getAllTxsToWatch() async {
|
||||||
if (_hasCalledExit) return;
|
if (_hasCalledExit) return;
|
||||||
List<isar_models.Transaction> unconfirmedTxnsToNotifyPending = [];
|
List<TransactionV2> unconfirmedTxnsToNotifyPending = [];
|
||||||
List<isar_models.Transaction> unconfirmedTxnsToNotifyConfirmed = [];
|
List<TransactionV2> unconfirmedTxnsToNotifyConfirmed = [];
|
||||||
|
|
||||||
final currentChainHeight = await chainHeight;
|
final currentChainHeight = await chainHeight;
|
||||||
|
|
||||||
final txCount = await db.getTransactions(walletId).count();
|
final txCount =
|
||||||
|
await db.isar.transactionV2s.where().walletIdEqualTo(walletId).count();
|
||||||
|
|
||||||
const paginateLimit = 50;
|
const paginateLimit = 50;
|
||||||
|
|
||||||
for (int i = 0; i < txCount; i += paginateLimit) {
|
for (int i = 0; i < txCount; i += paginateLimit) {
|
||||||
final transactions = await db
|
final transactions = await db.isar.transactionV2s
|
||||||
.getTransactions(walletId)
|
.where()
|
||||||
|
.walletIdEqualTo(walletId)
|
||||||
.offset(i)
|
.offset(i)
|
||||||
.limit(paginateLimit)
|
.limit(paginateLimit)
|
||||||
.findAll();
|
.findAll();
|
||||||
|
@ -1282,37 +1285,38 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
// transactions locally in a good way
|
// transactions locally in a good way
|
||||||
@override
|
@override
|
||||||
Future<void> updateSentCachedTxData(Map<String, dynamic> txData) async {
|
Future<void> updateSentCachedTxData(Map<String, dynamic> txData) async {
|
||||||
final transaction = isar_models.Transaction(
|
//. TODO update this to V2 properly
|
||||||
walletId: walletId,
|
// final transaction = TransactionV2(
|
||||||
txid: txData["txid"] as String,
|
// walletId: walletId,
|
||||||
timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
// txid: txData["txid"] as String,
|
||||||
type: isar_models.TransactionType.outgoing,
|
// timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||||
subType: isar_models.TransactionSubType.none,
|
// type: isar_models.TransactionType.outgoing,
|
||||||
// precision may be lost here hence the following amountString
|
// subType: isar_models.TransactionSubType.none,
|
||||||
amount: (txData["recipientAmt"] as Amount).raw.toInt(),
|
// // precision may be lost here hence the following amountString
|
||||||
amountString: (txData["recipientAmt"] as Amount).toJsonString(),
|
// amount: (txData["recipientAmt"] as Amount).raw.toInt(),
|
||||||
fee: txData["fee"] as int,
|
// amountString: (txData["recipientAmt"] as Amount).toJsonString(),
|
||||||
height: null,
|
// fee: txData["fee"] as int,
|
||||||
isCancelled: false,
|
// height: null,
|
||||||
isLelantus: false,
|
// isCancelled: false,
|
||||||
otherData: null,
|
// isLelantus: false,
|
||||||
slateId: null,
|
// otherData: null,
|
||||||
nonce: null,
|
// slateId: null,
|
||||||
inputs: [],
|
// nonce: null,
|
||||||
outputs: [],
|
// inputs: [],
|
||||||
numberOfMessages: null,
|
// outputs: [],
|
||||||
);
|
// numberOfMessages: null,
|
||||||
|
// );
|
||||||
final address = txData["address"] is String
|
//
|
||||||
? await db.getAddress(walletId, txData["address"] as String)
|
// final address = txData["address"] is String
|
||||||
: null;
|
// ? await db.getAddress(walletId, txData["address"] as String)
|
||||||
|
// : null;
|
||||||
await db.addNewTransactionData(
|
//
|
||||||
[
|
// await db.addNewTransactionData(
|
||||||
Tuple2(transaction, address),
|
// [
|
||||||
],
|
// Tuple2(transaction, address),
|
||||||
walletId,
|
// ],
|
||||||
);
|
// walletId,
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validateCashAddr(String cashAddr) {
|
bool validateCashAddr(String cashAddr) {
|
||||||
|
@ -2060,12 +2064,10 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
final List<TransactionV2> txns = [];
|
final List<TransactionV2> txns = [];
|
||||||
|
|
||||||
for (final txData in allTransactions) {
|
for (final txData in allTransactions) {
|
||||||
Set<String> inputAddresses = {};
|
|
||||||
Set<String> outputAddresses = {};
|
|
||||||
|
|
||||||
// set to true if any inputs were detected as owned by this wallet
|
// set to true if any inputs were detected as owned by this wallet
|
||||||
bool wasSentFromThisWallet = false;
|
bool wasSentFromThisWallet = false;
|
||||||
BigInt amountSentFromThisWallet = BigInt.zero;
|
BigInt amountSentFromThisWallet =
|
||||||
|
BigInt.zero; // unsure if needed. Not used rn
|
||||||
|
|
||||||
// set to true if any outputs were detected as owned by this wallet
|
// set to true if any outputs were detected as owned by this wallet
|
||||||
bool wasReceivedInThisWallet = false;
|
bool wasReceivedInThisWallet = false;
|
||||||
|
@ -2126,8 +2128,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
wasSentFromThisWallet = true;
|
wasSentFromThisWallet = true;
|
||||||
amountSentFromThisWallet += input.value;
|
amountSentFromThisWallet += input.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputAddresses.addAll(input.addresses);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse outputs
|
// parse outputs
|
||||||
|
@ -2141,12 +2141,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final output in outputs) {
|
for (final output in outputs) {
|
||||||
if (allAddressesSet
|
|
||||||
.intersection(output.addresses.toSet())
|
|
||||||
.isNotEmpty) {}
|
|
||||||
|
|
||||||
outputAddresses.addAll(output.addresses);
|
|
||||||
|
|
||||||
// if output was to my wallet, add value to amount received
|
// if output was to my wallet, add value to amount received
|
||||||
if (receivingAddresses
|
if (receivingAddresses
|
||||||
.intersection(output.addresses.toSet())
|
.intersection(output.addresses.toSet())
|
||||||
|
@ -2171,6 +2165,8 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
final fee = totalIn - totalOut;
|
final fee = totalIn - totalOut;
|
||||||
|
|
||||||
isar_models.TransactionType type;
|
isar_models.TransactionType type;
|
||||||
|
isar_models.TransactionSubType subType =
|
||||||
|
isar_models.TransactionSubType.none;
|
||||||
|
|
||||||
// at least one input was owned by this wallet
|
// at least one input was owned by this wallet
|
||||||
if (wasSentFromThisWallet) {
|
if (wasSentFromThisWallet) {
|
||||||
|
@ -2185,6 +2181,18 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
// most likely just a typical send
|
// most likely just a typical send
|
||||||
// do nothing here yet
|
// do nothing here yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check vout 0 for special scripts
|
||||||
|
if (outputs.isNotEmpty) {
|
||||||
|
final output = outputs.first;
|
||||||
|
|
||||||
|
// check for fusion
|
||||||
|
if (BchUtils.isFUZE(output.scriptPubKeyHex.toUint8ListFromHex)) {
|
||||||
|
subType = isar_models.TransactionSubType.cashFusion;
|
||||||
|
} else {
|
||||||
|
// check other cases here such as SLP or cash tokens etc
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (wasReceivedInThisWallet) {
|
} else if (wasReceivedInThisWallet) {
|
||||||
// only found outputs owned by this wallet
|
// only found outputs owned by this wallet
|
||||||
|
@ -2205,7 +2213,7 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
inputs: List.unmodifiable(inputs),
|
inputs: List.unmodifiable(inputs),
|
||||||
outputs: List.unmodifiable(outputs),
|
outputs: List.unmodifiable(outputs),
|
||||||
type: type,
|
type: type,
|
||||||
subType: isar_models.TransactionSubType.none,
|
subType: subType,
|
||||||
);
|
);
|
||||||
|
|
||||||
txns.add(tx);
|
txns.add(tx);
|
||||||
|
|
Loading…
Reference in a new issue