fixing api for zano

This commit is contained in:
leo 2023-10-25 19:07:58 +00:00
parent 219f43a959
commit a260d0a599
2 changed files with 94 additions and 285 deletions

View file

@ -15,7 +15,7 @@ void __clear_cache(void* start, void* end) { }
#endif #endif
#include "plain_wallet_api.h" #include "plain_wallet_api.h"
#include "plain_wallet_api_ex.h" //#include "plain_wallet_api_ex.h"
@ -81,7 +81,7 @@ extern "C"
uint64_t rate; uint64_t rate;
char *assetType; char *assetType;
HavenRate(char *_assetType, uint64_t _rate) ZanoRate(char *_assetType, uint64_t _rate)
{ {
rate = _rate; rate = _rate;
assetType = _assetType; assetType = _assetType;
@ -175,8 +175,9 @@ extern "C"
int64_t datetime; int64_t datetime;
TransactionInfoRow(wallet_public::wallet_transfer_info& wti) TransactionInfoRow(/*wallet_public::wallet_transfer_info& wti*/)
{ {
/*
amount = wti.subtransfers. amount = wti.subtransfers.
fee = transaction->fee(); fee = transaction->fee();
blockHeight = transaction->blockHeight(); blockHeight = transaction->blockHeight();
@ -221,8 +222,8 @@ extern "C"
std::mutex store_lock; std::mutex store_lock;
bool is_storing = false; bool is_storing = false;
*/ */
void change_current_wallet(Monero::Wallet *wallet) //void change_current_wallet(Monero::Wallet *wallet)
{ //{
/* /*
m_wallet = wallet; m_wallet = wallet;
m_listener = nullptr; m_listener = nullptr;
@ -255,64 +256,22 @@ extern "C"
m_subaddress = nullptr; m_subaddress = nullptr;
} }
*/ */
//}
//Monero::Wallet *get_current_wallet()
//{
// return nullptr;//return m_wallet;
//}
char * create_wallet(char *path, char *password, char *language, int32_t networkType, char *error)
{
return strdup(plain_wallet::generate(path, password).c_str());
} }
Monero::Wallet *get_current_wallet() char * restore_wallet_from_seed(char *path, char *password, char *seed, int32_t networkType, uint64_t restoreHeight, char *error)
{ {
return strdup(restore(seed, path, password, "");
return nullptr;//return m_wallet;
}
bool create_wallet(char *path, char *password, char *language, int32_t networkType, char *error)
{
/*
Monero::WalletManagerFactory::setLogLevel(4);
Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
Monero::WalletManager *walletManager = Monero::WalletManagerFactory::getWalletManager();
Monero::Wallet *wallet = walletManager->createWallet(path, password, language, _networkType);
int status;
std::string errorString;
wallet->statusWithErrorString(status, errorString);
if (wallet->status() != Monero::Wallet::Status_Ok)
{
error = strdup(wallet->errorString().c_str());
return false;
}
change_current_wallet(wallet);
*/
return true;
}
bool restore_wallet_from_seed(char *path, char *password, char *seed, int32_t networkType, uint64_t restoreHeight, char *error)
{
/*
Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
Monero::Wallet *wallet = Monero::WalletManagerFactory::getWalletManager()->recoveryWallet(
std::string(path),
std::string(password),
std::string(seed),
_networkType,
(uint64_t)restoreHeight);
int status;
std::string errorString;
wallet->statusWithErrorString(status, errorString);
if (status != Monero::Wallet::Status_Ok || !errorString.empty())
{
error = strdup(errorString.c_str());
return false;
}
change_current_wallet(wallet);
*/
return true;
} }
bool restore_wallet_from_keys(char *path, char *password, char *language, char *address, char *viewKey, char *spendKey, int32_t networkType, uint64_t restoreHeight, char *error) bool restore_wallet_from_keys(char *path, char *password, char *language, char *address, char *viewKey, char *spendKey, int32_t networkType, uint64_t restoreHeight, char *error)
@ -342,275 +301,125 @@ extern "C"
change_current_wallet(wallet); change_current_wallet(wallet);
*/ */
return true;
}
bool load_wallet(char *path, char *password, int32_t nettype)
{
/*
nice(19);
Monero::NetworkType networkType = static_cast<Monero::NetworkType>(nettype);
Monero::WalletManager *walletManager = Monero::WalletManagerFactory::getWalletManager();
Monero::Wallet *wallet = walletManager->openWallet(std::string(path), std::string(password), networkType);
int status;
std::string errorString;
wallet->statusWithErrorString(status, errorString);
change_current_wallet(wallet);
return !(status != Monero::Wallet::Status_Ok || !errorString.empty());
*/
return false; return false;
} }
char * load_wallet(char *path, char *password, int32_t nettype)
{
return strdup(open(path, password));
}
char *error_string() { char *error_string() {
return strdup(get_current_wallet()->errorString().c_str()); return strdup("");//strdup(get_current_wallet()->errorString().c_str());
} }
bool is_wallet_exist(char *path) bool is_wallet_exist(char *path)
{ {
return false; //return Monero::WalletManagerFactory::getWalletManager()->walletExists(std::string(path)); return plain_wallet::is_wallet_exist(path);
} }
void close_current_wallet() void close_wallet(uint64_t hwallet)
{ {
//Monero::WalletManagerFactory::getWalletManager()->closeWallet(get_current_wallet()); plain_wallet::close_wallet(hwallet);
//change_current_wallet(nullptr);
}
char *get_filename()
{
return nullptr;//return strdup(get_current_wallet()->filename().c_str());
}
char *secret_view_key()
{
return nullptr;//return strdup(get_current_wallet()->secretViewKey().c_str());
}
char *public_view_key()
{
return nullptr;//return strdup(get_current_wallet()->publicViewKey().c_str());
}
char *secret_spend_key()
{
return nullptr;//return strdup(get_current_wallet()->secretSpendKey().c_str());
}
char *public_spend_key()
{
return nullptr;//return strdup(get_current_wallet()->publicSpendKey().c_str());
}
char *get_address(uint32_t account_index, uint32_t address_index)
{
return nullptr;//return strdup(get_current_wallet()->address(account_index, address_index).c_str());
} }
const char *seed() char *get_wallet_info(uint64_t hwallet) {
{ return strdup(plain_wallet::get_wallet_info(hwallet));
return nullptr;//return strdup(get_current_wallet()->seed().c_str());
} }
int64_t *get_full_balance(uint32_t account_index)
{
/* /*
std::map<std::string, uint64_t> accountBalance; get_filename(): -> get_wallet_info(h).wi.path
std::map<uint32_t, std::map<std::string, uint64_t>> balanceSubaddresses = get_current_wallet()->balance(account_index); secret_view_key(): -> get_wallet_info(h).wi_extended.view_private_key
std::vector<std::string> assetList = Monero::Assets::list(); public_view_key(): -> get_wallet_info(h).wi_extended.view_public_key
//prefill balances secret_spend_key(): -> get_wallet_info(h).wi_extended.spend_private_key
for (const auto &asset_type : assetList) { public_spend_key(): -> get_wallet_info(h).wi_extended.spend_public_key
get_address(): -> get_wallet_info(h).wi.address
seed(): -> get_wallet_info(h).wi_extended.seed
get_current_height(): -> get_wallet_status(h).current_wallet_height
get_node_height(): -> get_wallet_status(h).current_daemon_height
accountBalance[asset_type] = 0; start_refresh() ???
} set_refresh_from_block_height ???
// balances are mapped to their subaddress set_recovering_from_seed ???
// we compute total balances of account
for (auto const& balanceSubaddress : balanceSubaddresses)
{
std::map<std::string, uint64_t> balanceOfSubaddress = balanceSubaddress.second; connect_to_node()/is_connected(): -> get_connectivity_status(): {
"is_online": true,
for (auto const& balance : balanceOfSubaddress) "last_daemon_is_disconnected": false,
{ "is_server_busy": false,
"last_proxy_communicate_timestamp": 12121212
const std::string &assetType = balance.first;
const uint64_t &amount = balance.second;
accountBalance[assetType] +=amount;
}
} }
size_t size = accountBalance.size();
int64_t *balanceAddresses = (int64_t *)malloc(size * sizeof(int64_t));
int i = 0;
for (auto const& balance : accountBalance)
{
char *assetType = strdup(balance.first.c_str());
HavenBalance *hb = new HavenBalance(assetType, balance.second);
balanceAddresses[i] = reinterpret_cast<int64_t>(hb);
i++;
} }
return balanceAddresses;
get_full_balance/get_unlocked_balance(): -> async_call("get_recent_txs_and_info", hwallet, "{ params: {offset: 0,count: 30,update_provision_info: true}}")
return list of last transactions + balances
store(): -> async_call("store", hwallet, "{params: {}}")
set_password() return "OK" if succeded
*/ */
return nullptr;
}
int64_t *get_unlocked_balance(uint32_t account_index)
char* get_wallet_status(uint64_t hwallet)
{ {
/* return strdup(plain_wallet::get_wallet_status(hwallet));
std::map<std::string, uint64_t> accountBalance;
std::map<uint32_t, std::map<std::string, uint64_t>> balanceSubaddresses = get_current_wallet()->unlockedBalance(account_index);
std::vector<std::string> assetList = Monero::Assets::list();
//prefill balances
for (const auto &asset_type : assetList) {
accountBalance[asset_type] = 0;
} }
// balances are mapped to their subaddress
// we compute total balances of account char* async_call(char* method_name, uint64_t instance_id, char* params)
for (auto const& balanceSubaddress : balanceSubaddresses)
{ {
return strdup(plain_wallet::async_call(method_name, instance_id, params));
std::map<std::string, uint64_t> balanceOfSubaddress = balanceSubaddress.second; }
char* try_pull_result(uint64_t job_id)
for (auto const& balance : balanceOfSubaddress)
{ {
return strdup(plain_wallet::try_pull_result(job_id));
const std::string &assetType = balance.first;
const uint64_t &amount = balance.second;
accountBalance[assetType] +=amount;
}
} }
size_t size = accountBalance.size(); char* get_connectivity_status()
int64_t *balanceAddresses = (int64_t *)malloc(size * sizeof(int64_t));
int i = 0;
for (auto const& balance : accountBalance)
{ {
char *assetType = strdup(balance.first.c_str()); return strdup(plain_wallet::get_connectivity_status());
HavenBalance *hb = new HavenBalance(assetType, balance.second);
balanceAddresses[i] = reinterpret_cast<int64_t>(hb);
i++;
}
return balanceAddresses;
*/
return nullptr;
}
uint64_t get_current_height()
{
return 0;//return get_current_wallet()->blockChainHeight();
}
uint64_t get_node_height()
{
return 0;//return get_current_wallet()->daemonBlockChainHeight();
}
bool connect_to_node(char *error)
{
/*
nice(19);
bool is_connected = get_current_wallet()->connectToDaemon();
if (!is_connected)
{
error = strdup(get_current_wallet()->errorString().c_str());
}
return is_connected;
*/
return false;
} }
bool setup_node(char *address, char *login, char *password, bool use_ssl, bool is_light_wallet, char *error) bool setup_node(char *address, char *login, char *password, bool use_ssl, bool is_light_wallet, char *error)
{ {
/*
nice(19); nice(19);
Monero::Wallet *wallet = get_current_wallet(); if(use_ssl)
std::string _login = plain_wallet::get_version();
std::string _password = "";
if (login != nullptr)
{ {
_login = std::string(login); //LOG_ERROR("SSL is not supported yet for Zano");
return false;
} }
if (password != nullptr) std::string res = plain_wallet::init(address, "", 0);
if(API_RETURN_CODE_OK != res)
{ {
_password = std::string(password); //LOG_ERROR("Failed init wallet");
return false;
} }
bool inited = wallet->init(std::string(address), 0, _login, _password, use_ssl, is_light_wallet); return true;
if (!inited)
{
error = strdup(wallet->errorString().c_str());
} else if (!wallet->connectToDaemon()) {
error = strdup(wallet->errorString().c_str());
} }
return inited; //void start_refresh()
*/ //{
return plain_wallet::get_version().empty();
}
bool is_connected()
{
return false;//return get_current_wallet()->connected();
}
void start_refresh()
{
//get_current_wallet()->refreshAsync(); //get_current_wallet()->refreshAsync();
//get_current_wallet()->startRefresh(); //get_current_wallet()->startRefresh();
} //}
void set_refresh_from_block_height(uint64_t height) //void set_refresh_from_block_height(uint64_t height)
{ //{
//get_current_wallet()->setRefreshFromBlockHeight(height); //get_current_wallet()->setRefreshFromBlockHeight(height);
} //}
void set_recovering_from_seed(bool is_recovery) //void set_recovering_from_seed(bool is_recovery)
{ //{
//get_current_wallet()->setRecoveringFromSeed(is_recovery); //get_current_wallet()->setRecoveringFromSeed(is_recovery);
} //}
void store(char *path) char* set_password(uint64_t hwallet, char *password, Utf8Box &error)
{ {
/* return strdup(plain_wallet::reset_wallet_password(hwallet, password));
store_lock.lock();
if (is_storing) {
return;
}
is_storing = true;
get_current_wallet()->store(std::string(path));
is_storing = false;
store_lock.unlock();
*/
}
bool set_password(char *password, Utf8Box &error)
{
/*
bool is_changed = get_current_wallet()->setPassword(std::string(password));
if (!is_changed) {
error = Utf8Box(strdup(get_current_wallet()->errorString().c_str()));
}
return is_changed;
*/
return false;
} }
bool transaction_create(char *address, char *asset_type, char *payment_id, char *amount, bool transaction_create(char *address, char *asset_type, char *payment_id, char *amount,

View file

@ -4,7 +4,7 @@ set -o xtrace
. ./config.sh . ./config.sh
#HAVEN_VERSION=tags/v3.0.7 #HAVEN_VERSION=tags/v3.0.7
ZANO_SRC_DIR=${WORKDIR}/zano ZANO_SRC_DIR=${WORKDIR}/zano
ZANO_CHECKOUT_ID=cryptoassets ZANO_CHECKOUT_ID=cake
#git clone --recursive https://github.com/hyle-team/zano.git ${ZANO_SRC_DIR} #git clone --recursive https://github.com/hyle-team/zano.git ${ZANO_SRC_DIR}
cd $ZANO_SRC_DIR cd $ZANO_SRC_DIR
@ -63,7 +63,7 @@ cd $ZANO_SRC_DIR
rm -rf ./build/release rm -rf ./build/release
mkdir -p ./build/release mkdir -p ./build/release
cd ./build/release cd ./build/release
CC=${CLANG} CXX=${CXXLANG} cmake -S../.. -DCMAKE_INSTALL_PREFIX=${DEST_LIB_DIR} -D TESTNET=TRUE -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH=${ARCH} -D STATIC=ON -D BUILD_64=${BUILD_64} -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D INSTALL_VENDORED_LIBUNBOUND=ON -D BUILD_TAG=${TAG} -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI=${ARCH_ABI} $FLAGS CC=${CLANG} CXX=${CXXLANG} cmake -S../.. -DCMAKE_INSTALL_PREFIX=${DEST_LIB_DIR} -D CAKEWALLET=TRUE -D TESTNET=TRUE -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH=${ARCH} -D STATIC=ON -D BUILD_64=${BUILD_64} -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D INSTALL_VENDORED_LIBUNBOUND=ON -D BUILD_TAG=${TAG} -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI=${ARCH_ABI} $FLAGS
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to perform cmake" echo "Failed to perform cmake"
exit 1 exit 1