summaryrefslogtreecommitdiff
path: root/monero_libwallet2_api_c
diff options
context:
space:
mode:
authorCzarek Nakamoto <cyjan@mrcyjanek.net>2026-05-08 19:41:31 -0400
committerCzarek Nakamoto <cyjan@mrcyjanek.net>2026-05-08 19:41:31 -0400
commit15b46af9e2ad37edb79f7be5ea301206361d53b2 (patch)
treec01de9d183e6c4c3d205814cd678bfce37edc102 /monero_libwallet2_api_c
parentbc8d1a0b75b97156d71579581b4cdfe58c777ed2 (diff)
wip twip2
Diffstat (limited to 'monero_libwallet2_api_c')
-rw-r--r--monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp336
-rw-r--r--monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h3
2 files changed, 83 insertions, 256 deletions
diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp
index b9ff95f..db56643 100644
--- a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp
+++ b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp
@@ -85,10 +85,7 @@ const char* MONERO_PendingTransaction_errorString(void* pendingTx_ptr) {
DEBUG_START()
Monero::PendingTransaction *pendingTx = reinterpret_cast<Monero::PendingTransaction*>(pendingTx_ptr);
std::string str = pendingTx->errorString();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
bool MONERO_PendingTransaction_commit(void* pendingTx_ptr, const char* filename, bool overwrite) {
@@ -101,10 +98,7 @@ const char* MONERO_PendingTransaction_commitUR(void* pendingTx_ptr, int max_frag
DEBUG_START()
Monero::PendingTransaction *pendingTx = reinterpret_cast<Monero::PendingTransaction*>(pendingTx_ptr);
std::string str = pendingTx->commitUR(max_fragment_length);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
uint64_t MONERO_PendingTransaction_amount(void* pendingTx_ptr) {
@@ -156,10 +150,7 @@ const char* MONERO_PendingTransaction_multisigSignData(void* pendingTx_ptr) {
DEBUG_START()
Monero::PendingTransaction *pendingTx = reinterpret_cast<Monero::PendingTransaction*>(pendingTx_ptr);
std::string str = pendingTx->multisigSignData();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
void MONERO_PendingTransaction_signMultisigTx(void* pendingTx_ptr) {
@@ -208,10 +199,7 @@ const char* MONERO_UnsignedTransaction_errorString(void* unsignedTx_ptr) {
DEBUG_START()
Monero::UnsignedTransaction *unsignedTx = reinterpret_cast<Monero::UnsignedTransaction*>(unsignedTx_ptr);
std::string str = unsignedTx->errorString();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
const char* MONERO_UnsignedTransaction_amount(void* unsignedTx_ptr, const char* separator) {
@@ -236,10 +224,7 @@ const char* MONERO_UnsignedTransaction_confirmationMessage(void* unsignedTx_ptr)
DEBUG_START()
Monero::UnsignedTransaction *unsignedTx = reinterpret_cast<Monero::UnsignedTransaction*>(unsignedTx_ptr);
std::string str = unsignedTx->confirmationMessage();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
const char* MONERO_UnsignedTransaction_paymentId(void* unsignedTx_ptr, const char* separator) {
@@ -276,10 +261,7 @@ const char* MONERO_UnsignedTransaction_signUR(void* unsignedTx_ptr, int max_frag
DEBUG_START()
Monero::UnsignedTransaction *unsignedTx = reinterpret_cast<Monero::UnsignedTransaction*>(unsignedTx_ptr);
std::string str = unsignedTx->signUR(max_fragment_length);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// TransactionInfo
@@ -332,10 +314,7 @@ const char* MONERO_TransactionInfo_description(void* txInfo_ptr) {
DEBUG_START()
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
std::string str = txInfo->description();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
const char* MONERO_TransactionInfo_subaddrIndex(void* txInfo_ptr, const char* separator) {
@@ -355,10 +334,7 @@ const char* MONERO_TransactionInfo_label(void* txInfo_ptr) {
DEBUG_START()
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
std::string str = txInfo->label();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
uint64_t MONERO_TransactionInfo_confirmations(void* txInfo_ptr) {
@@ -377,10 +353,7 @@ const char* MONERO_TransactionInfo_hash(void* txInfo_ptr) {
DEBUG_START()
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
std::string str = txInfo->hash();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
uint64_t MONERO_TransactionInfo_timestamp(void* txInfo_ptr) {
@@ -393,10 +366,7 @@ const char* MONERO_TransactionInfo_paymentId(void* txInfo_ptr) {
DEBUG_START()
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
std::string str = txInfo->paymentId();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -418,10 +388,7 @@ const char* MONERO_TransactionInfo_transfers_address(void* txInfo_ptr, int index
DEBUG_START()
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
std::string str = txInfo->transfers()[index].address;
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -468,10 +435,7 @@ const char* MONERO_AddressBookRow_extra(void* addressBookRow_ptr) {
DEBUG_START()
Monero::AddressBookRow *addressBookRow = reinterpret_cast<Monero::AddressBookRow*>(addressBookRow_ptr);
std::string str = addressBookRow->extra;
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getAddress() const {return m_address;}
@@ -479,10 +443,7 @@ const char* MONERO_AddressBookRow_getAddress(void* addressBookRow_ptr) {
DEBUG_START()
Monero::AddressBookRow *addressBookRow = reinterpret_cast<Monero::AddressBookRow*>(addressBookRow_ptr);
std::string str = addressBookRow->getAddress();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getDescription() const {return m_description;}
@@ -490,10 +451,7 @@ const char* MONERO_AddressBookRow_getDescription(void* addressBookRow_ptr) {
DEBUG_START()
Monero::AddressBookRow *addressBookRow = reinterpret_cast<Monero::AddressBookRow*>(addressBookRow_ptr);
std::string str = addressBookRow->getDescription();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getPaymentId() const {return m_paymentId;}
@@ -501,10 +459,7 @@ const char* MONERO_AddressBookRow_getPaymentId(void* addressBookRow_ptr) {
DEBUG_START()
Monero::AddressBookRow *addressBookRow = reinterpret_cast<Monero::AddressBookRow*>(addressBookRow_ptr);
std::string str = addressBookRow->getPaymentId();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::size_t getRowId() const {return m_rowId;}
@@ -568,10 +523,7 @@ const char* MONERO_AddressBook_errorString(void* addressBook_ptr) {
DEBUG_START()
Monero::AddressBook *addressBook = reinterpret_cast<Monero::AddressBook*>(addressBook_ptr);
std::string str = addressBook->errorString();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual int errorCode() const = 0;
@@ -601,10 +553,7 @@ const char* MONERO_CoinsInfo_hash(void* coinsInfo_ptr) {
DEBUG_START()
Monero::CoinsInfo *coinsInfo = reinterpret_cast<Monero::CoinsInfo*>(coinsInfo_ptr);
std::string str = coinsInfo->hash();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual size_t internalOutputIndex() const = 0;
@@ -689,10 +638,7 @@ const char* MONERO_CoinsInfo_address(void* coinsInfo_ptr) {
DEBUG_START()
Monero::CoinsInfo *coinsInfo = reinterpret_cast<Monero::CoinsInfo*>(coinsInfo_ptr);
std::string str = coinsInfo->address();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual std::string addressLabel() const = 0;
@@ -700,10 +646,7 @@ const char* MONERO_CoinsInfo_addressLabel(void* coinsInfo_ptr) {
DEBUG_START()
Monero::CoinsInfo *coinsInfo = reinterpret_cast<Monero::CoinsInfo*>(coinsInfo_ptr);
std::string str = coinsInfo->addressLabel();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual std::string keyImage() const = 0;
@@ -711,10 +654,7 @@ const char* MONERO_CoinsInfo_keyImage(void* coinsInfo_ptr) {
DEBUG_START()
Monero::CoinsInfo *coinsInfo = reinterpret_cast<Monero::CoinsInfo*>(coinsInfo_ptr);
std::string str = coinsInfo->keyImage();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual uint64_t unlockTime() const = 0;
@@ -736,10 +676,7 @@ const char* MONERO_CoinsInfo_pubKey(void* coinsInfo_ptr) {
DEBUG_START()
Monero::CoinsInfo *coinsInfo = reinterpret_cast<Monero::CoinsInfo*>(coinsInfo_ptr);
std::string str = coinsInfo->pubKey();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual bool coinbase() const = 0;
@@ -754,10 +691,7 @@ const char* MONERO_CoinsInfo_description(void* coinsInfo_ptr) {
DEBUG_START()
Monero::CoinsInfo *coinsInfo = reinterpret_cast<Monero::CoinsInfo*>(coinsInfo_ptr);
std::string str = coinsInfo->description();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -851,10 +785,7 @@ const char* MONERO_SubaddressRow_extra(void* subaddressRow_ptr) {
DEBUG_START()
Monero::SubaddressRow *subaddressRow = reinterpret_cast<Monero::SubaddressRow*>(subaddressRow_ptr);
std::string str = subaddressRow->extra;
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getAddress() const {return m_address;}
@@ -862,10 +793,7 @@ const char* MONERO_SubaddressRow_getAddress(void* subaddressRow_ptr) {
DEBUG_START()
Monero::SubaddressRow *subaddressRow = reinterpret_cast<Monero::SubaddressRow*>(subaddressRow_ptr);
std::string str = subaddressRow->getAddress();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getLabel() const {return m_label;}
@@ -873,10 +801,7 @@ const char* MONERO_SubaddressRow_getLabel(void* subaddressRow_ptr) {
DEBUG_START()
Monero::SubaddressRow *subaddressRow = reinterpret_cast<Monero::SubaddressRow*>(subaddressRow_ptr);
std::string str = subaddressRow->getLabel();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::size_t getRowId() const {return m_rowId;}
@@ -930,10 +855,7 @@ const char* MONERO_SubaddressAccountRow_extra(void* subaddressAccountRow_ptr) {
DEBUG_START()
Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast<Monero::SubaddressAccountRow*>(subaddressAccountRow_ptr);
std::string str = subaddressAccountRow->extra;
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getAddress() const {return m_address;}
@@ -941,10 +863,7 @@ const char* MONERO_SubaddressAccountRow_getAddress(void* subaddressAccountRow_pt
DEBUG_START()
Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast<Monero::SubaddressAccountRow*>(subaddressAccountRow_ptr);
std::string str = subaddressAccountRow->getAddress();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getLabel() const {return m_label;}
@@ -952,10 +871,7 @@ const char* MONERO_SubaddressAccountRow_getLabel(void* subaddressAccountRow_ptr)
DEBUG_START()
Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast<Monero::SubaddressAccountRow*>(subaddressAccountRow_ptr);
std::string str = subaddressAccountRow->getLabel();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getBalance() const {return m_balance;}
@@ -963,10 +879,7 @@ const char* MONERO_SubaddressAccountRow_getBalance(void* subaddressAccountRow_pt
DEBUG_START()
Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast<Monero::SubaddressAccountRow*>(subaddressAccountRow_ptr);
std::string str = subaddressAccountRow->getBalance();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::string getUnlockedBalance() const {return m_unlockedBalance;}
@@ -974,10 +887,7 @@ const char* MONERO_SubaddressAccountRow_getUnlockedBalance(void* subaddressAccou
DEBUG_START()
Monero::SubaddressAccountRow *subaddressAccountRow = reinterpret_cast<Monero::SubaddressAccountRow*>(subaddressAccountRow_ptr);
std::string str = subaddressAccountRow->getUnlockedBalance();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// std::size_t getRowId() const {return m_rowId;}
@@ -1094,10 +1004,7 @@ const char* MONERO_Wallet_seed(void* wallet_ptr, const char* seed_offset) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->seed(std::string(seed_offset));
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1105,10 +1012,7 @@ const char* MONERO_Wallet_getSeedLanguage(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getSeedLanguage();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1130,10 +1034,7 @@ const char* MONERO_Wallet_errorString(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->errorString();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1149,10 +1050,7 @@ const char* MONERO_Wallet_getPassword(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getPassword();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1174,10 +1072,7 @@ const char* MONERO_Wallet_address(void* wallet_ptr, uint64_t accountIndex, uint6
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->address(accountIndex, addressIndex);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1185,10 +1080,7 @@ const char* MONERO_Wallet_path(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->path();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
int MONERO_Wallet_nettype(void* wallet_ptr) {
@@ -1207,10 +1099,7 @@ const char* MONERO_Wallet_integratedAddress(void* wallet_ptr, const char* paymen
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->integratedAddress(std::string(payment_id));
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1218,10 +1107,7 @@ const char* MONERO_Wallet_secretViewKey(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->secretViewKey();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1229,10 +1115,7 @@ const char* MONERO_Wallet_publicViewKey(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->publicViewKey();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1240,10 +1123,7 @@ const char* MONERO_Wallet_secretSpendKey(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->secretSpendKey();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1251,20 +1131,14 @@ const char* MONERO_Wallet_publicSpendKey(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->publicSpendKey();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
const char* MONERO_Wallet_publicMultisigSignerKey(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->publicMultisigSignerKey();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1285,20 +1159,14 @@ const char* MONERO_Wallet_filename(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->filename();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
const char* MONERO_Wallet_keysFilename(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->keysFilename();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1464,10 +1332,7 @@ bool MONERO_Wallet_synchronized(void* wallet_ptr) {
const char* MONERO_Wallet_displayAmount(uint64_t amount) {
DEBUG_START()
std::string str = Monero::Wallet::displayAmount(amount);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1487,10 +1352,7 @@ uint64_t MONERO_Wallet_amountFromDouble(double amount) {
const char* MONERO_Wallet_genPaymentId() {
DEBUG_START()
std::string str = Monero::Wallet::genPaymentId();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// static bool paymentIdValid(const std::string &paiment_id);
@@ -1516,20 +1378,14 @@ const char* MONERO_Wallet_keyValid_error(const char* secret_key_string, const ch
DEBUG_START()
std::string str;
Monero::Wallet::keyValid(std::string(secret_key_string), std::string(address_string), isViewKey, nettype, str);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
const char* MONERO_Wallet_paymentIdFromAddress(const char* strarg, int nettype) {
DEBUG_START()
std::string str = Monero::Wallet::paymentIdFromAddress(std::string(strarg), nettype);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
uint64_t MONERO_Wallet_maximumAllowedAmount() {
@@ -1551,10 +1407,7 @@ const char* MONERO_Wallet_getPolyseed(void* wallet_ptr, const char* passphrase)
std::string _passphrase = std::string(passphrase);
wallet->getPolyseed(seed, _passphrase);
std::string str = seed;
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// static bool createPolyseed(std::string &seed_words, std::string &err, const std::string &language = "English");
@@ -1564,10 +1417,7 @@ const char* MONERO_Wallet_createPolyseed(const char* language) {
std::string err;
Monero::Wallet::createPolyseed(seed_words, err, std::string(language));
std::string str = seed_words;
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1647,10 +1497,7 @@ const char* MONERO_Wallet_getSubaddressLabel(void* wallet_ptr, uint32_t accountI
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getSubaddressLabel(accountIndex, addressIndex);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1673,10 +1520,7 @@ const char* MONERO_Wallet_getMultisigInfo(void* wallet_ptr) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getMultisigInfo();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1684,10 +1528,7 @@ const char* MONERO_Wallet_makeMultisig(void* wallet_ptr, const char* info, const
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->makeMultisig(splitStringVector(std::string(info), std::string(info_separator)), threshold);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1695,10 +1536,7 @@ const char* MONERO_Wallet_exchangeMultisigKeys(void* wallet_ptr, const char* inf
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->exchangeMultisigKeys(splitStringVector(std::string(info), std::string(info_separator)), force_update_use_with_caution);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1707,10 +1545,7 @@ const char* MONERO_Wallet_exportMultisigImages(void* wallet_ptr, const char* sep
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str;
wallet->exportMultisigImages(str);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -1835,10 +1670,7 @@ const char* MONERO_Wallet_exportKeyImagesUR(void* wallet_ptr, size_t max_fragmen
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->exportKeyImagesUR(max_fragment_length, all);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
bool MONERO_Wallet_importKeyImages(void* wallet_ptr, const char* filename) {
@@ -1863,10 +1695,7 @@ const char* MONERO_Wallet_exportOutputsUR(void* wallet_ptr, size_t max_fragment_
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->exportOutputsUR(max_fragment_length, all);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
bool MONERO_Wallet_importOutputs(void* wallet_ptr, const char* filename) {
@@ -1982,10 +1811,7 @@ const char* MONERO_Wallet_getCacheAttribute(void* wallet_ptr, const char* key) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getCacheAttribute(std::string(key));
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual bool setUserNote(const std::string &txid, const std::string &note) = 0;
@@ -2000,10 +1826,7 @@ const char* MONERO_Wallet_getUserNote(void* wallet_ptr, const char* txid) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getUserNote(std::string(txid));
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -2011,10 +1834,7 @@ const char* MONERO_Wallet_getTxKey(void* wallet_ptr, const char* txid) {
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getTxKey(std::string(txid));
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -2022,10 +1842,7 @@ const char* MONERO_Wallet_signMessage(void* wallet_ptr, const char* message, con
DEBUG_START()
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->signMessage(std::string(message), std::string(address));
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -2121,10 +1938,7 @@ const char* MONERO_Wallet_deviceShowAddress(void* wallet_ptr, uint32_t accountIn
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = "";
wallet->deviceShowAddress(accountIndex, addressIndex, str);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
// virtual bool reconnectDevice() = 0;
@@ -2216,6 +2030,22 @@ const char* MONERO_Wallet_serializeCacheToJson(void* wallet_ptr) {
DEBUG_END()
}
+const char* MONERO_Wallet_exportTrezorTdis(void *wallet_ptr) {
+ DEBUG_START()
+ Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
+ std::string result = wallet->exportTrezorTdis();
+ return strdup(result.c_str());
+ DEBUG_END()
+}
+
+bool MONERO_Wallet_importTrezorEncryptedKeyImagesJson(void *wallet_ptr, const char* json) {
+ DEBUG_START()
+ Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
+ bool result = wallet->importTrezorEncryptedKeyImagesJson(std::string(json));
+ return result;
+ DEBUG_END()
+}
+
void* MONERO_WalletManager_createWallet(void* wm_ptr, const char* path, const char* password, const char* language, int networkType) {
DEBUG_START()
Monero::WalletManager *wm = reinterpret_cast<Monero::WalletManager*>(wm_ptr);
@@ -2375,10 +2205,7 @@ const char* MONERO_WalletManager_errorString(void* wm_ptr) {
DEBUG_START()
Monero::WalletManager *wm = reinterpret_cast<Monero::WalletManager*>(wm_ptr);
std::string str = wm->errorString();
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
@@ -2459,10 +2286,7 @@ const char* MONERO_WalletManager_resolveOpenAlias(void* wm_ptr, const char* addr
DEBUG_START()
Monero::WalletManager *wm = reinterpret_cast<Monero::WalletManager*>(wm_ptr);
std::string str = wm->resolveOpenAlias(std::string(address), dnssec_valid);
- const std::string::size_type size = str.size();
- char *buffer = new char[size + 1]; //we need extra char for NUL
- memcpy(buffer, str.c_str(), size + 1);
- return buffer;
+ return strdup(str.c_str());
DEBUG_END()
}
diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h
index 39bca89..f3cfdee 100644
--- a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h
+++ b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h
@@ -848,6 +848,9 @@ extern ADDAPI void MONERO_Wallet_setDeviceReceivedData(unsigned char* data, size
extern ADDAPI void MONERO_Wallet_setDeviceSendData(unsigned char* data, size_t len);
extern ADDAPI void MONERO_Wallet_setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len));
extern ADDAPI const char* MONERO_Wallet_serializeCacheToJson(void* wallet_ptr);
+extern ADDAPI const char* MONERO_Wallet_exportTrezorTdis(void* wallet_ptr);
+extern ADDAPI bool MONERO_Wallet_importTrezorEncryptedKeyImagesJson(void* wallet_ptr, const char* json);
+
// };
// struct WalletManager