BalanceWindow::BalanceWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::BalanceWindow) { ui->setupUi(this); INFO = QSystemTrayIcon::Information; WARNING = QSystemTrayIcon::Warning; CRYTICAL = QSystemTrayIcon::Critical; isAuthPage = true; setCentralWidget(ui->verticalLayoutWidget); setupStatusBar(); setupTrayIcon(); trayMessageTimer = new QTimer(); trayMessageTimer->setSingleShot(true); updateTimer = new QTimer(); connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateBalance())); connect(ui->updateAction, SIGNAL(triggered()), this, SLOT(updateBalance())); getSettings(); updateInfo(); if(!d) updateBalance(); }
void debit(sqlite3 *db, int acc_id, double sumtoget) { char * acc, * sum; acc = calloc(100, sizeof(char)); sum = calloc(100, sizeof(char)); sprintf(acc, "%i", acc_id); sprintf(sum, "%lf", - sumtoget); updateBalance(db, acc, sum); free(acc); free(sum); }
int serverAddToWallet(BIO *conn, int clientid, EVP_PKEY *clientKey, EVP_PKEY *bankKey) { //receive the cloud dollar file if(recvFile(conn, TEMP_DOLLAR_FILENAME) == -1) return -1; //receive the signature char signature[BUFFER_SIZE]; int status = readPacket(conn, signature, sizeof(signature)); if ( status == -1 ) return -1; int sigSize = status; //verify the cloud dollar is real (signed by the bank and right string) int verified = verifyCloudDollar(TEMP_DOLLAR_FILENAME, bankKey); if(verified < 0) { printf("\tReceived an INVALID cloud dollar.\n"); //inform user of probelm writeInt(conn, -2); return 0; } else printf("\tRecieved a valid cloud dollar.\n"); int serial; int amount; int user; status = getDollarData(TEMP_DOLLAR_FILENAME, &serial, &amount, &user); //verify the user signed the cloud dollar verified = verifyFile(TEMP_DOLLAR_FILENAME, (unsigned char*)signature, sigSize, clientKey); if(!verified) { printf("\tReceived INVALID signature for the cloud dollar.\n"); //infomr user of promebl writeInt(conn, -3); return 0; } else printf("\tReceived a valid signature from %d\n", clientid); //all valid, so up their balance int balance = getBalance(clientid); status = updateBalance(clientid, balance + amount); if(status == -1) { //inform user writeInt(conn, -1); return -1; } //inform user of success if(writeInt(conn, amount) == -1) return -1; return amount; }
int serverUploadFile(BIO *conn, int clientid) { //receive the filesize int fileSize = readInt(conn); if(fileSize == -1) return -1; //the upload costs $1 per MEGABYTE int cost = fileSize / MEGABYTE; if(fileSize % MEGABYTE != 0) ++cost; //check user has the balance for a file of this size int userBalance = getBalance(clientid); int response = 0; if(userBalance == -1) response = -1; else if(userBalance < cost) response = cost - userBalance; else response = 0; //inform user of whether we are going ahead or not int status = writeInt(conn, response); if(response != 0) return response; if(status < 0) return status; char userDirectory[BUFFER_SIZE]; snprintf(userDirectory, sizeof(userDirectory), "./%s/%d/", SERVER_FILE_FOLDER, clientid); if(chdir(userDirectory) != 0) { perror("serverUploadFile"); return -1; } //receive the file, save it with whatever name the client uses status = recvFile(conn, NULL); if(chdir("../../") != 0) { perror("serverUploadFile"); return -1; } //update their balance if(updateBalance(clientid, userBalance - cost) == -1) return -1; return 1; }