From 9eb74f7155b531696cdc6bb5491a95a5553dca6b Mon Sep 17 00:00:00 2001 From: M Date: Thu, 24 Sep 2020 18:11:29 +0300 Subject: [PATCH] Added displaying of transaction key. --- cw_monero/ios/Classes/monero_api.cpp | 7 ++++++- cw_monero/lib/signatures.dart | 4 +++- cw_monero/lib/transaction_history.dart | 18 ++++++++++++++++++ cw_monero/lib/types.dart | 2 ++ lib/monero/monero_transaction_info.dart | 10 ++++++++-- .../transaction_details_page.dart | 5 +++++ 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp index 6393eaea9..b4fa5cc0a 100644 --- a/cw_monero/ios/Classes/monero_api.cpp +++ b/cw_monero/ios/Classes/monero_api.cpp @@ -5,8 +5,8 @@ #include #include #include "thread" -#include "../External/android/monero/include/wallet2_api.h" #include "CwWalletListener.h" +#include "../External/android/monero/include/wallet2_api.h" using namespace std::chrono_literals; @@ -684,6 +684,11 @@ extern "C" m_wallet->rescanBlockchainAsync(); } + char * get_tx_key(char * txId) + { + return strdup(m_wallet->getTxKey(std::string(txId)).c_str()); + } + #ifdef __cplusplus } #endif diff --git a/cw_monero/lib/signatures.dart b/cw_monero/lib/signatures.dart index c7db41159..5e9c4fa9d 100644 --- a/cw_monero/lib/signatures.dart +++ b/cw_monero/lib/signatures.dart @@ -76,7 +76,9 @@ typedef account_add_new = Void Function(Pointer label); typedef account_set_label = Void Function( Int32 accountIndex, Pointer label); - typedef transactions_refresh = Void Function(); +typedef transactions_refresh = Void Function(); + +typedef get_tx_key = Pointer Function(Pointer txId); typedef transactions_count = Int64 Function(); diff --git a/cw_monero/lib/transaction_history.dart b/cw_monero/lib/transaction_history.dart index 2eacbb744..7e6f94c23 100644 --- a/cw_monero/lib/transaction_history.dart +++ b/cw_monero/lib/transaction_history.dart @@ -1,4 +1,5 @@ import 'dart:ffi'; +import 'package:cw_monero/convert_utf8_to_string.dart'; import 'package:cw_monero/structs/ut8_box.dart'; import 'package:ffi/ffi.dart'; import 'package:flutter/foundation.dart'; @@ -29,6 +30,23 @@ final transactionCommitNative = moneroApi .lookup>('transaction_commit') .asFunction(); +final getTxKeyNative = moneroApi + .lookup>('get_tx_key') + .asFunction(); + +String getTxKey(String txId) { + final txIdPointer = Utf8.toUtf8(txId); + final keyPointer = getTxKeyNative(txIdPointer); + + free(txIdPointer); + + if (keyPointer != null) { + return convertUTF8ToString(pointer: keyPointer); + } + + return null; +} + void refreshTransactions() => transactionsRefreshNative(); int countOfTransactions() => transactionsCountNative(); diff --git a/cw_monero/lib/types.dart b/cw_monero/lib/types.dart index e2602ce91..602a33572 100644 --- a/cw_monero/lib/types.dart +++ b/cw_monero/lib/types.dart @@ -76,6 +76,8 @@ typedef AccountSetLabel = void Function(int accountIndex, Pointer label); typedef TransactionsRefresh = void Function(); +typedef GetTxKey = Pointer Function(Pointer txId); + typedef TransactionsCount = int Function(); typedef TransactionsGetAll = Pointer Function(); diff --git a/lib/monero/monero_transaction_info.dart b/lib/monero/monero_transaction_info.dart index 7b05a9598..dab34838e 100644 --- a/lib/monero/monero_transaction_info.dart +++ b/lib/monero/monero_transaction_info.dart @@ -4,6 +4,7 @@ import 'package:cw_monero/structs/transaction_info_row.dart'; import 'package:cake_wallet/entities/parseBoolFromString.dart'; import 'package:cake_wallet/entities/transaction_direction.dart'; import 'package:cake_wallet/entities/format_amount.dart'; +import 'package:cw_monero/transaction_history.dart'; class MoneroTransactionInfo extends TransactionInfo { MoneroTransactionInfo(this.id, this.height, this.direction, this.date, @@ -19,7 +20,8 @@ class MoneroTransactionInfo extends TransactionInfo { (int.parse(map['timestamp'] as String) ?? 0) * 1000), isPending = parseBoolFromString(map['isPending'] as String), amount = map['amount'] as int, - accountIndex = int.parse(map['accountIndex'] as String); + accountIndex = int.parse(map['accountIndex'] as String), + key = getTxKey((map['hash'] ?? '') as String); MoneroTransactionInfo.fromRow(TransactionInfoRow row) : id = row.getHash(), @@ -29,7 +31,8 @@ class MoneroTransactionInfo extends TransactionInfo { date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000), isPending = row.isPending != 0, amount = row.getAmount(), - accountIndex = row.subaddrAccount; + accountIndex = row.subaddrAccount, + key = getTxKey(row.getHash()); final String id; final int height; @@ -39,11 +42,14 @@ class MoneroTransactionInfo extends TransactionInfo { final bool isPending; final int amount; String recipientAddress; + String key; String _fiatAmount; + @override String amountFormatted() => '${formatAmount(moneroAmountToString(amount: amount))} XMR'; + @override String fiatAmount() => _fiatAmount ?? ''; void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount); diff --git a/lib/src/screens/transaction_details/transaction_details_page.dart b/lib/src/screens/transaction_details/transaction_details_page.dart index 635946b4e..78bc9bd7c 100644 --- a/lib/src/screens/transaction_details/transaction_details_page.dart +++ b/lib/src/screens/transaction_details/transaction_details_page.dart @@ -35,6 +35,11 @@ class TransactionDetailsPage extends BasePage { // value: tx.recipientAddress)); // } + if (tx.key?.isNotEmpty) { + // FIXME: add translation + items.add(StandartListItem(title: 'Transaction Key', value: tx.key)); + } + _items.addAll(items); }