mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-31 15:59:26 +00:00
refactor: enhance ada txs
This commit is contained in:
parent
56dcc0ba4a
commit
e3d040b9b8
3 changed files with 31 additions and 29 deletions
|
@ -353,10 +353,11 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
||||||
await updateProvider();
|
await updateProvider();
|
||||||
|
|
||||||
final addressUtxos = await blockfrostProvider!.request(
|
final addressUtxos = await blockfrostProvider!.request(
|
||||||
BlockfrostRequestAddressUTXOs(
|
BlockfrostRequestAddressUTXOsOfAGivenAsset(
|
||||||
ADAAddress.fromAddress(
|
address: ADAAddress.fromAddress(
|
||||||
(await getCurrentReceivingAddress())!.value,
|
(await getCurrentReceivingAddress())!.value,
|
||||||
),
|
),
|
||||||
|
asset: "lovelace",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -402,7 +403,7 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
||||||
|
|
||||||
await info.updateCachedChainHeight(
|
await info.updateCachedChainHeight(
|
||||||
newHeight: latestBlock.height == null ? 0 : latestBlock.height!,
|
newHeight: latestBlock.height == null ? 0 : latestBlock.height!,
|
||||||
isar: mainDB.isar);
|
isar: mainDB.isar,);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"Error updating transactions in cardano_wallet.dart: $e\n$s",
|
"Error updating transactions in cardano_wallet.dart: $e\n$s",
|
||||||
|
@ -443,55 +444,56 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
||||||
);
|
);
|
||||||
var txType = isar.TransactionType.unknown;
|
var txType = isar.TransactionType.unknown;
|
||||||
|
|
||||||
var txOutputIndex = -1;
|
|
||||||
|
|
||||||
for (final input in utxoInfo.inputs) {
|
for (final input in utxoInfo.inputs) {
|
||||||
if (input.address == currentAddr) {
|
if (input.address == currentAddr) {
|
||||||
txType = isar.TransactionType.outgoing;
|
txType = isar.TransactionType.outgoing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (txType == isar.TransactionType.outgoing) {
|
||||||
|
var isSelfTx = true;
|
||||||
|
for (final output in utxoInfo.outputs) {
|
||||||
|
if (output.address != currentAddr) {
|
||||||
|
isSelfTx = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSelfTx) {
|
||||||
|
txType = isar.TransactionType.sentToSelf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (txType == isar.TransactionType.unknown) {
|
if (txType == isar.TransactionType.unknown) {
|
||||||
for (final output in utxoInfo.outputs) {
|
for (final output in utxoInfo.outputs) {
|
||||||
if (output.address == currentAddr) {
|
if (output.address == currentAddr) {
|
||||||
txType = isar.TransactionType.incoming;
|
txType = isar.TransactionType.incoming;
|
||||||
txOutputIndex = output.outputIndex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var receiverAddr = "Unknown?";
|
var receiverAddr = "Unknown?";
|
||||||
|
var amount = 0;
|
||||||
|
|
||||||
if (txType == isar.TransactionType.incoming) {
|
if (txType == isar.TransactionType.incoming) {
|
||||||
receiverAddr = currentAddr;
|
receiverAddr = currentAddr;
|
||||||
|
for (final output in utxoInfo.outputs) {
|
||||||
|
if (output.address == currentAddr) {
|
||||||
|
amount += int.parse(output.amount.first.quantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (txType == isar.TransactionType.outgoing) {
|
} else if (txType == isar.TransactionType.outgoing) {
|
||||||
for (final output in utxoInfo.outputs) {
|
for (final output in utxoInfo.outputs) {
|
||||||
if (output.address != currentAddr) {
|
if (output.address != currentAddr) {
|
||||||
receiverAddr = output.address;
|
receiverAddr = output.address;
|
||||||
txOutputIndex = output.outputIndex;
|
amount += int.parse(output.amount.first.quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (txType == isar.TransactionType.sentToSelf) {
|
||||||
|
receiverAddr = currentAddr;
|
||||||
|
for (final output in utxoInfo.outputs) {
|
||||||
|
amount += int.parse(output.amount.first.quantity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount = 0;
|
|
||||||
|
|
||||||
// Temporary solution until https://github.com/mrtnetwork/On_chain/issues/9 is solved.
|
|
||||||
// Use the library when the mentioned issue is solved.
|
|
||||||
final currentNode = getCurrentNode();
|
|
||||||
final response = await _httpClient.get(
|
|
||||||
url: Uri.parse(
|
|
||||||
"${currentNode.host}:${currentNode.port}/api/v0/txs/${tx.txHash}/utxos",),
|
|
||||||
proxyInfo: Prefs.instance.useTor
|
|
||||||
? TorService.sharedInstance.getProxyInfo()
|
|
||||||
: null,
|
|
||||||
);
|
|
||||||
final json = jsonDecode(response.body);
|
|
||||||
if (txOutputIndex != -1) {
|
|
||||||
amount = int.parse(json["outputs"][txOutputIndex]["amount"][0]
|
|
||||||
["quantity"]! as String,);
|
|
||||||
}
|
|
||||||
// Temporary solution part end.
|
|
||||||
|
|
||||||
final transaction = isar.Transaction(
|
final transaction = isar.Transaction(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
txid: txInfo.hash,
|
txid: txInfo.hash,
|
||||||
|
|
|
@ -1289,10 +1289,10 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: on_chain
|
name: on_chain
|
||||||
sha256: "53a17cc19c722e3cdef7a34931e7cd07c490443a92bf538f08cc755b854dfb59"
|
sha256: "4040c187be82f6f6414110139f6e70fe304f23f63111c3ee60438c539b1a1dce"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.9.0"
|
version: "4.0.1"
|
||||||
package_config:
|
package_config:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -199,7 +199,7 @@ dependencies:
|
||||||
camera_platform_interface: ^2.8.0
|
camera_platform_interface: ^2.8.0
|
||||||
camera_macos: ^0.0.8
|
camera_macos: ^0.0.8
|
||||||
blockchain_utils: ^3.3.0
|
blockchain_utils: ^3.3.0
|
||||||
on_chain: ^3.7.0
|
on_chain: ^4.0.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue