void SellsPage::on_acceptButton_clicked() { QItemSelectionModel* selectionModel = ui->buysTableWidget->selectionModel(); QModelIndexList selected = selectionModel->selectedRows(); if(selected.count() == 0) return; QModelIndex index = selected.at(0); int r = index.row(); std::string id = ui->buysTableWidget->item(r, 4)->text().toStdString(); uint256 listingIdHash = uint256(id); std::string rid = ui->buysTableWidget->item(r, 5)->text().toStdString(); uint256 requestIdHash = uint256(rid); // ask the user if they really want to accept the buy request QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Accept Buy", "Are you sure you want to accept the buy request for this item?", QMessageBox::Yes|QMessageBox::No); if (reply == QMessageBox::Yes) { CBuyAccept accept; accept.listingId = listingIdHash; accept.buyRequestId = requestIdHash; accept.nDate = GetTime(); accept.sellerKey = pwalletMain->GenerateNewKey(); CBuyRequest buyRequest = mapBuyRequests[requestIdHash]; // create the escrow lock address std::string errors; std::string escrowAddress; bool res = AddMultisigAddress(mapListings[listingIdHash].listing.sellerKey, mapBuyRequests[requestIdHash].buyerKey, escrowAddress, errors); accept.escrowAddress = escrowAddress; // fund it std::string strError = ""; CWalletTx wtxNew; CReserveKey reserveKey(pwalletMain); bool result = CreateEscrowLockTx(accept.escrowAddress, mapListings[buyRequest.listingId].listing.nPrice + (0.01 * COIN), strError, wtxNew); //pwalletMain->CommitTransaction(wtxNew, reserveKey); //accept.sellerEscrowLockTxHash = wtxNew.GetHash(); // serialize the tx to a string CDataStream ssTx(SER_NETWORK, CLIENT_VERSION); ssTx.reserve(sizeof(wtxNew)); ssTx << wtxNew; // misuse this parameter like a boss accept.raw = ssTx.str(); SignBuyAccept(accept, accept.vchSig); ReceiveBuyAccept(accept); accept.BroadcastToAll(); LoadSells(); LoadBuyRequests(); } }
Value marketapprovebuy(const Array& params, bool fHelp) { if (fHelp || params.size() == 2) throw runtime_error("marketapprovebuy \n" "Approves market listing buy request \n" "parameters: <requestId>"); string requestID = params[0].get_str(); uint256 requestHashId = uint256(requestID); uint256 listingHashId = mapBuyRequests[requestHashId].listingId; CBuyAccept accept; accept.listingId = listingHashId; accept.buyRequestId = requestHashId; accept.nDate = GetTime(); accept.sellerKey = pwalletMain->GenerateNewKey(); CBuyRequest buyRequest = mapBuyRequests[requestHashId]; // create the escrow lock address std::string errors; std::string escrowAddress; AddMultisigAddress(mapListings[listingHashId].listing.sellerKey, mapBuyRequests[requestHashId].buyerKey, escrowAddress, errors); accept.escrowAddress = escrowAddress; // fund it std::string strError = ""; CWalletTx wtxNew; CreateEscrowLockTx(accept.escrowAddress, mapListings[buyRequest.listingId].listing.nPrice + (0.01 * COIN), strError, wtxNew); // serialize the tx to a string CDataStream ssTx(SER_NETWORK, CLIENT_VERSION); ssTx.reserve(sizeof(wtxNew)); ssTx << wtxNew; // misuse this parameter like a boss accept.raw = ssTx.str(); SignBuyAccept(accept, accept.vchSig); ReceiveBuyAccept(accept); accept.BroadcastToAll(); return Value::null; }