From 0dfaf069b4d20b9a9de99e9c697f94cac854b0c1 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Fri, 26 Jul 2024 22:43:40 +0200 Subject: [PATCH] feat: :sparkles: Add `TransactionUtil.isSCCallExecuted` method to check is a SC has been executed --- CHANGELOG.md | 3 +++ lib/src/util/transaction_util.dart | 39 ++++++++++++++++++++++++++++++ pubspec.lock | 8 +++--- pubspec.yaml | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b5b20..bf2f1b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +#### Version 1.2.9 +* Add `TransactionUtil.isSCCallExecuted` method to check is a SC has been executed + #### Version 1.2.8 * Update dependencies diff --git a/lib/src/util/transaction_util.dart b/lib/src/util/transaction_util.dart index 7c4613d..bb7009b 100644 --- a/lib/src/util/transaction_util.dart +++ b/lib/src/util/transaction_util.dart @@ -223,6 +223,45 @@ mixin TransactionMixin { return; } + Future isSCCallExecuted( + String contractAddress, + String txAddress, + ) async { + var executed = false; + final apiService = sl.get(); + + final transactionChainResult = await apiService.getTransactionChain( + {contractAddress: ''}, + orderAsc: false, + request: + 'validationStamp {ledgerOperations { consumedInputs { from, type } } }', + ); + + if (transactionChainResult[contractAddress] != null) { + final transactions = transactionChainResult[contractAddress]; + for (final transaction in transactions!) { + if (transaction.validationStamp != null && + transaction.validationStamp!.ledgerOperations != null && + transaction + .validationStamp!.ledgerOperations!.consumedInputs.isNotEmpty) { + for (final consumedInput in transaction + .validationStamp!.ledgerOperations!.consumedInputs) { + if (consumedInput.type == 'call' && + consumedInput.from != null && + consumedInput.from!.toUpperCase() == txAddress.toUpperCase()) { + executed = true; + break; + } + } + } + if (executed) { + break; + } + } + } + return executed; + } + Future getAmountFromTxInput( String txAddress, String? tokenAddress, diff --git a/pubspec.lock b/pubspec.lock index 523b358..d5bb92c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -660,10 +660,10 @@ packages: dependency: transitive description: name: path_provider_android - sha256: "30c5aa827a6ae95ce2853cdc5fe3971daaac00f6f081c419c013f7f57bff2f5e" + sha256: e84c8a53fe1510ef4582f118c7b4bdf15b03002b51d7c2b66983c65843d61193 url: "https://pub.dev" source: hosted - version: "2.2.7" + version: "2.2.8" path_provider_foundation: dependency: transitive description: @@ -1009,10 +1009,10 @@ packages: dependency: transitive description: name: url_launcher_android - sha256: "95d8027db36a0e52caf55680f91e33ea6aa12a3ce608c90b06f4e429a21067ac" + sha256: c24484594a8dea685610569ab0f2547de9c7a1907500a9bc5e37e4c9a3cbfb23 url: "https://pub.dev" source: hosted - version: "6.3.5" + version: "6.3.6" url_launcher_ios: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b8b0f0c..ce12670 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: archethic_dapp_framework_flutter description: An internal framework for archethic flutter development homepage: https://github.com/archethic-foundation/archethic-dapp-framework-flutter -version: 1.2.8 +version: 1.2.9 environment: sdk: ">=3.3.0 <4.0.0"