/* * work-flow of insertion a new node into AVL tree: * * - insertion is done as in the BS tree; * - check if a tree has to be balanced; * - balance the tree, if needed; */ int avl_insert(struct avl_node **r, struct avl_node *n) { struct avl_node *p; int rv = 0; if (unlikely(!*r)) { *r = n; rv = 1; goto leave; } /* * p is a parent of new node n */ p = do_simple_insert(*r, n); if (p) { /* * p is first unbalanced node in the * entire path after insertion */ p = fix_balance(n, *r); if (p) /* * r can be reassigned */ do_pivot(r, p); /* success */ rv = 1; } leave: return rv; }
void DashcoinWallet::rpcReply(QNetworkReply *reply) { if(!wallet_is_running){ return; } QByteArray bytes = reply->readAll(); QString str = QString::fromUtf8(bytes.data(), bytes.size()).simplified(); if(!str.contains("error")){ str.replace(QRegularExpression("(?<=:)\\s()(?=\\d)"),"\""); str.replace(QRegularExpression("(?<=\\d)(?=[, ])"),"\""); } QJsonDocument jsonResponse = QJsonDocument::fromJson(str.toUtf8()); QJsonObject jsonObj; if(jsonResponse.object().contains("error")){ jsonObj = jsonResponse.object()["error"].toObject(); }else{ jsonObj = jsonResponse.object()["result"].toObject(); } QString id = jsonResponse.object()["id"].toString(); if(str == ""){ messageLabel->setText("Syncing wallet "+current_wallet); return; } if(opening_wallet == true){ opening_wallet = false; messageLabel->setText("Opened wallet "+current_wallet); ui->btn_open->setDisabled(false); ui->btn_open->setText("Open wallet"); show_wallet(true); } if(id == "balance"){ QString balance = jsonObj["balance"].toString(); QString unlocked_balance = jsonObj["unlocked_balance"].toString(); balance = fix_balance(balance); unlocked_balance = fix_balance(unlocked_balance); ui->txt_balance->setText(balance+" DSH"); ui->txt_balance_unlocked->setText(unlocked_balance+" DSH"); return; } if(id == "transactions"){ QJsonArray jsonArray = jsonObj["transfers"].toArray(); ui->table_transactions->setRowCount(jsonArray.size()); int col = 0; for(int i=jsonArray.size()-1;i>=0;i--){ QString address_str = jsonArray.at(i).toObject()["address"].toString(); QTableWidgetItem *amount = new QTableWidgetItem(fix_balance(jsonArray.at(i).toObject()["amount"].toString())+" DSH"); QTableWidgetItem *address = new QTableWidgetItem(address_str); QTableWidgetItem *fee = new QTableWidgetItem(fix_balance(jsonArray.at(i).toObject()["fee"].toString())+ " DSH"); QTableWidgetItem *txhash = new QTableWidgetItem(jsonArray.at(i).toObject()["transactionHash"].toString()); QTableWidgetItem *date = new QTableWidgetItem(QDateTime::fromTime_t(jsonArray.at(i).toObject()["time"].toString().toInt()).toUTC().toString("MMM d yyyy hh:mm:ss")); QString type_str = "Send"; if(address_str == ""){ type_str = "Receive"; } QTableWidgetItem *type = new QTableWidgetItem(type_str); col = jsonArray.size()-i-1; ui->table_transactions->setItem(col,0,date); ui->table_transactions->setItem(col,1,type); ui->table_transactions->setItem(col,2,amount); ui->table_transactions->setItem(col, 3, fee); ui->table_transactions->setItem(col,4,txhash); ui->table_transactions->setItem(col,5,address); } return; } if(id == "send"){ if(jsonResponse.object().contains("error")){ QString error = jsonObj["message"].toString(); messageLabel->setText("Error sending transaction: "+error); }else{ QString txhash = jsonResponse.object()["result"].toObject()["tx_hash"].toString(); messageLabel->setText("Successfully sent transaction "+txhash); } bool b = false; ui->btn_send_confirm->setText("Confirm"); ui->txt_send_address->setDisabled(b); ui->txt_send_paymentid->setDisabled(b); ui->txt_send_amount->setDisabled(b); ui->txt_send_fee->setDisabled(b); ui->txt_send_mixin->setDisabled(b); ui->panel_send_confirm->setHidden(!b); ui->btn_send->setHidden(b); } }