This commit is contained in:
Czarek Nakamoto
2024-04-29 14:09:14 +02:00
parent 75d6aba195
commit b739dd6b51
4 changed files with 75 additions and 3 deletions

View File

@@ -169,6 +169,19 @@ std::set<std::string> splitString(const std::string& str, const std::string& del
return tokens;
}
std::vector<std::string> splitStringVector(const std::string& str, const std::string& delim) {
std::vector<std::string> tokens;
if (str.empty()) return tokens;
size_t pos = 0;
std::string content = str; // Copy of str so we can safely erase content
while ((pos = content.find(delim)) != std::string::npos) {
tokens.push_back(content.substr(0, pos));
content.erase(0, pos + delim.length());
}
tokens.push_back(content); // Inserting the last token
return tokens;
}
std::vector<uint64_t> splitStringUint(const std::string& str, const std::string& delim) {
std::vector<uint64_t> tokens;
if (str.empty()) return tokens;

View File

@@ -9,4 +9,5 @@ const char* vectorToString(const std::vector<uint64_t>& vec, const std::string s
const char* vectorToString(const std::vector<std::set<uint32_t>>& vec, const std::string separator);
const char* vectorToString(const std::set<uint32_t>& intSet, const std::string separator);
std::set<std::string> splitString(const std::string& str, const std::string& delim);
std::vector<uint64_t> splitStringUint(const std::string& str, const std::string& delim);
std::vector<uint64_t> splitStringUint(const std::string& str, const std::string& delim);
std::vector<std::string> splitStringVector(const std::string& str, const std::string& delim);

View File

@@ -1220,6 +1220,13 @@ void MONERO_Wallet_setSubaddressLabel(void* wallet_ptr, uint32_t accountIndex, u
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->setSubaddressLabel(accountIndex, addressIndex, std::string(label));
}
void* MONERO_Wallet_multisig(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
Monero::MultisigState *mstate_ptr = new Monero::MultisigState(wallet->multisig());
return reinterpret_cast<void*>(mstate_ptr);
}
const char* MONERO_Wallet_getMultisigInfo(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
std::string str = wallet->getMultisigInfo();
@@ -1229,6 +1236,50 @@ const char* MONERO_Wallet_getMultisigInfo(void* wallet_ptr) {
return buffer;
}
const char* MONERO_Wallet_makeMultisig(void* wallet_ptr, const char* info, const char* info_separator, uint32_t threshold) {
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;
}
const char* MONERO_Wallet_exchangeMultisigKeys(void* wallet_ptr, const char* info, const char* info_separator, bool force_update_use_with_caution) {
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;
}
const char* MONERO_Wallet_exportMultisigImages(void* wallet_ptr, const char* separator) {
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;
}
size_t MONERO_Wallet_importMultisigImages(void* wallet_ptr, const char* info, const char* info_separator) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->importMultisigImages(splitStringVector(std::string(info), std::string(info_separator)));
}
size_t MONERO_Wallet_hasMultisigPartialKeyImages(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->hasMultisigPartialKeyImages();
}
void* MONERO_Wallet_restoreMultisigTransaction(void* wallet_ptr, const char* signData) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return reinterpret_cast<void*>(wallet->restoreMultisigTransaction(std::string(signData)));
}
Monero::PendingTransaction::Priority PendingTransaction_Priority_fromInt(int value) {
switch(value) {
case 0: return Monero::PendingTransaction::Priority::Priority_Default;
@@ -1732,8 +1783,8 @@ uint64_t MONERO_DEBUG_test3(uint64_t x) {
}
void* MONERO_DEBUG_test4(uint64_t x) {
int y = x;
return reinterpret_cast<void*>(&y);
int *y = new int(x);
return reinterpret_cast<void*>(y);
}
const char* MONERO_DEBUG_test5() {

View File

@@ -678,14 +678,21 @@ extern ADDAPI const char* MONERO_Wallet_getSubaddressLabel(void* wallet_ptr, uin
// virtual void setSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex, const std::string &label) = 0;
extern ADDAPI void MONERO_Wallet_setSubaddressLabel(void* wallet_ptr, uint32_t accountIndex, uint32_t addressIndex, const char* label);
// virtual MultisigState multisig() const = 0;
extern ADDAPI void* MONERO_Wallet_multisig(void* wallet_ptr);
// virtual std::string getMultisigInfo() const = 0;
extern ADDAPI const char* MONERO_Wallet_getMultisigInfo(void* wallet_ptr);
// virtual std::string makeMultisig(const std::vector<std::string>& info, uint32_t threshold) = 0;
extern ADDAPI const char* MONERO_Wallet_makeMultisig(void* wallet_ptr, const char* info, const char* info_separator, uint32_t threshold);
// virtual std::string exchangeMultisigKeys(const std::vector<std::string> &info, const bool force_update_use_with_caution) = 0;
extern ADDAPI const char* MONERO_Wallet_exchangeMultisigKeys(void* wallet_ptr, const char* info, const char* info_separator, bool force_update_use_with_caution);
// virtual bool exportMultisigImages(std::string& images) = 0;
extern ADDAPI const char* MONERO_Wallet_exportMultisigImages(void* wallet_ptr, const char* separator);
// virtual size_t importMultisigImages(const std::vector<std::string>& images) = 0;
extern ADDAPI size_t MONERO_Wallet_importMultisigImages(void* wallet_ptr, const char* info, const char* info_separator);
// virtual bool hasMultisigPartialKeyImages() const = 0;
extern ADDAPI size_t MONERO_Wallet_hasMultisigPartialKeyImages(void* wallet_ptr);
// virtual PendingTransaction* restoreMultisigTransaction(const std::string& signData) = 0;
extern ADDAPI void* MONERO_Wallet_restoreMultisigTransaction(void* wallet_ptr, const char* signData);
// virtual PendingTransaction * createTransactionMultDest(const std::vector<std::string> &dst_addr, const std::string &payment_id,
// optional<std::vector<uint64_t>> amount, uint32_t mixin_count,
// PendingTransaction::Priority = PendingTransaction::Priority_Low,