Added displaying of transaction key.

This commit is contained in:
M 2020-09-24 18:11:29 +03:00
parent e4b5bcf07e
commit 9eb74f7155
6 changed files with 42 additions and 4 deletions

View file

@ -5,8 +5,8 @@
#include <iostream>
#include <unistd.h>
#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

View file

@ -76,7 +76,9 @@ typedef account_add_new = Void Function(Pointer<Utf8> label);
typedef account_set_label = Void Function(
Int32 accountIndex, Pointer<Utf8> label);
typedef transactions_refresh = Void Function();
typedef transactions_refresh = Void Function();
typedef get_tx_key = Pointer<Utf8> Function(Pointer<Utf8> txId);
typedef transactions_count = Int64 Function();

View file

@ -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<NativeFunction<transaction_commit>>('transaction_commit')
.asFunction<TransactionCommit>();
final getTxKeyNative = moneroApi
.lookup<NativeFunction<get_tx_key>>('get_tx_key')
.asFunction<GetTxKey>();
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();

View file

@ -76,6 +76,8 @@ typedef AccountSetLabel = void Function(int accountIndex, Pointer<Utf8> label);
typedef TransactionsRefresh = void Function();
typedef GetTxKey = Pointer<Utf8> Function(Pointer<Utf8> txId);
typedef TransactionsCount = int Function();
typedef TransactionsGetAll = Pointer<Int64> Function();

View file

@ -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);

View file

@ -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);
}