// Generate Transactions // void gen_rules(TransPar &par) { StringSet *lits; StringSetIter *patterns; Transaction *trans; poisson_distribution<LINT> tlen(par.tlen - 1); ofstream data_fp; ofstream pat_fp; data_fp.open(data_file, ios::trunc); pat_fp.open(pat_file, ios::trunc); lits = new StringSet(par.nitems, par.lits); // Reset random seed generator before generating transactions if (par.seed < 0) generator.seed(par.seed); par.write(pat_fp); lits->display(pat_fp); patterns = new StringSetIter(*lits); for (LINT i = 0; i < par.ntrans; i ++) { trans = mk_tran(*patterns, tlen(generator) + 1); if (par.ascii) trans->write_asc(data_fp); else trans->write(data_fp); delete trans; } data_fp.close(); pat_fp.close(); }
bool TransactionQueue::buildQueue(ifstream& transFile) { // temporary members to store input for processing char act; int a1, a1t, a2, a2t, amt, tmp; a1 = a1t = a2 = a2t = amt = tmp = 0; transFile >> act; //loop through file for (;;) { // get action indicator first to guide action //cout << act << "|"; // test if valid action, otherwise abort for this line if (act == 'D' || act == 'W' || act == 'M' || act == 'H') { transFile >> tmp; //cout << tmp << "|"; if (act == 'H') { // for History, store acct#/type & done a1 = tmp; } else { // all others need at least a first a1 = tmp / 10; // acct#, acct type, and amount a1t = tmp % 10; transFile >> amt; if (act == 'M') { // finally, if Move get second transFile >> tmp; // acct# and acct type a2 = tmp / 10; a2t = tmp % 10; } } // build object and enqueue, then move on to next line Transaction* t = new Transaction; t->setData(act, a1, a1t, a2, a2t, amt); transQueue.push_back(t); a1 = a1t = a2 = a2t = amt = tmp = 0; } else {
void Bank::Transfer(const Transaction& tr) { Account info; Account* from = NULL; Account* to = NULL; string acc = tr.GetAccount(); string num = acc.substr(0, acc.length() - 1); info.SetNumber(num); if (!tree.Retrieve(info, from)) { cerr << "ERROR: Account " << num << " not found. Transferal refused." << endl; return; } string acc2 = tr.GetAccount2(); string num2 = acc2.substr(0, acc2.length() - 1); info.SetNumber(num2); if (!tree.Retrieve(info, to)) { cerr << "ERROR: Account " << num2 << " not found. Transferal refused." << endl; return; } if (from->Transfer(tr, true)) { to->Transfer(tr, false); } }
void update_screen (int icid, int screen) { if (m_send_refcount > 0 && m_current_icid == icid) { m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_SCREEN); m_send_trans.put_data ((uint32) screen); } }
int s3fs_chown(const char *path, uid_t uid, gid_t gid) { #ifdef DEBUG syslog(LOG_INFO, "chown[%s] uid[%d] gid[%d]", path, uid, gid); #endif try { Transaction t; t.getExisting(path); // uid or gid < 0 indicates no change if ((int) uid >= 0 && t.file->info->uid != uid) { t.file->info->uid = uid; t.file->dirty_metadata = true; } if ((int) gid >= 0 && t.file->info->gid != gid) { t.file->info->gid = gid; t.file->dirty_metadata = true; } return 0; } catch (int e) { syslog(LOG_INFO, "chown[%s]: %s", path, strerror(e)); return e; } }
void Transact::on_debug_clicked() { // Secret s = findSecret(value() + fee()); Address from = fromAccount(); auto b = ethereum()->balanceAt(from, PendingBlock); if (!from || b < value() + fee()) { QMessageBox::critical(this, "Transaction Failed", "Couldn't make transaction: account doesn't contain at least the required amount."); return; } try { Block postState(ethereum()->postState()); Transaction t = isCreation() ? Transaction(value(), gasPrice(), gas(), m_data, postState.transactionsFrom(from)) : Transaction(value(), gasPrice(), gas(), toAccount().first, m_data, postState.transactionsFrom(from)); t.forceSender(from); Debugger dw(m_main, this); Executive e(postState, ethereum()->blockChain(), 0); dw.populate(e, t); dw.exec(); } catch (dev::Exception const& _e) { QMessageBox::critical(this, "Transaction Failed", "Couldn't make transaction. Low-level error: " + QString::fromStdString(diagnostic_information(_e))); // this output is aimed at developers, reconsider using _e.what for more user friendly output. } }
void MixClient::executeTransaction(Transaction const& _t, Block& _block, bool _call, bool _gasAuto, Secret const& _secret) { Transaction t = _gasAuto ? replaceGas(_t, m_postMine.gasLimitRemaining()) : _t; // do debugging run first EnvInfo envInfo(bc().info(), bc().lastHashes()); ExecutionResult d = debugTransaction(t, _block.state(), envInfo, _call); // execute on a state if (!_call) { t = _gasAuto ? replaceGas(_t, d.gasUsed, _secret) : _t; eth::ExecutionResult const& er = _block.execute(envInfo.lastHashes(), t); if (t.isCreation() && _block.state().code(d.contractAddress).empty()) BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment")); d.gasUsed = er.gasUsed + er.gasRefunded + er.gasForDeposit + c_callStipend; LocalisedLogEntries logs; TransactionReceipt const& tr = _block.receipt(_block.pending().size() - 1); LogEntries le = tr.log(); if (le.size()) for (unsigned j = 0; j < le.size(); ++j) logs.insert(logs.begin(), LocalisedLogEntry(le[j])); d.logs = logs; } WriteGuard l(x_executions); m_executions.emplace_back(std::move(d)); }
int s3fs_rmdir(const char *path) { #ifdef DEBUG syslog(LOG_INFO, "rmdir[%s]", path); #endif try { Transaction t; t.getExisting(path); // sync any deleted files inside this directory Filecache::sync(); // make sure the directory is empty std::string marker; stringlist entries; S3request::get_directory(path, marker, entries, 1); if (entries.size() > 0) throw -ENOTEMPTY; t.file->deleted = true; return 0; } catch (int e) { syslog(LOG_INFO, "rmdir[%s]: %s", path, strerror(e)); return e; } }
// Generate a transaction // Transaction *mk_tran(StringSetIter &lits, // table of patterns LINT tlen, // transaction length LINT NPATS, Taxonomy *tax) { Transaction *trans; StringP pat; if (tlen > Transaction::MAXNITEMS) tlen = Transaction::MAXNITEMS; //MJZ: can't exceed nitems trans = new Transaction(tlen); LINT patcnt = 0; //MJZ while (trans->size() < tlen && patcnt < NPATS) { patcnt++; //cout << trans->size() << " " << tlen << " HERE2\n"; pat = lits.get_pat(); // get a pattern if (!trans->add(*pat)) { // this pattern didn't fit in the transaction lits.unget_pat(); break; } } return trans; }
bool Manager::apply() { Transaction *tx = m_reapack->setupTransaction(); if(!tx) return false; if(m_autoInstall) m_config->install()->autoInstall = m_autoInstall.value(); if(m_bleedingEdge) m_config->install()->bleedingEdge = m_bleedingEdge.value(); for(const auto &pair : m_enableOverrides) { const Remote &remote = pair.first; const bool enable = pair.second; if(m_uninstall.find(remote) == m_uninstall.end()) m_reapack->setRemoteEnabled(enable, remote); } for(const Remote &remote : m_uninstall) m_reapack->uninstall(remote); tx->runTasks(); m_config->write(); reset(); return true; }
TEST_F(TestStream, Simple) { Connection c = Connection::create(m_engine); Transaction tx = Transaction::create(c); ib_stream_pump_t *pump; ASSERT_EQ(IB_OK, ib_stream_pump_create(&pump, m_reg, tx.ib()) ); ASSERT_EQ(IB_OK, ib_stream_pump_processor_add(pump, "inflate") ); ASSERT_EQ(IB_OK, ib_stream_pump_processor_add(pump, "collector") ); ASSERT_EQ(IB_OK, ib_stream_pump_flush(pump) ); ASSERT_EQ(IB_OK, ib_stream_pump_process(pump, compressed_data, 3) ); ASSERT_EQ(IB_OK, ib_stream_pump_process(pump, compressed_data + 3, compressed_data_len - 3) ); ASSERT_EQ(IB_OK, ib_stream_pump_flush(pump) ); ASSERT_EQ(0, m_collector.compare(0, std::string::npos, reinterpret_cast<const char*>(uncompressed_data), uncompressed_data_len)); }
uid_t YChatDB::addUser(const string& username, const string& password) { Storage* uind_store = get_user_index_table(); Storage* user_store = get_user_table(); if (uind_store == NULL || user_store == NULL) return 0; Transaction txn; uid_t uid = 0; try { if (!inc_and_get_curr_max_uid(uind_store, txn, uid)) { txn.abort(); return 0; } OctetsStream key, value; key << username, value << password << uid; uind_store->insert(key, value, txn); User user(uid, username); OctetsStream key2, value2; key2 << uid, value2 << user.toString(); user_store->insert(key2, value2, txn); } catch (...) { txn.abort(); return 0; } return uid; }
void process_commit() { /* Loop through all the maps and add to new map in each transaction. Once that is done, what we have is the new final transaction. Erase trans_stack and add this new final transaction as tid 0 */ vector<Transaction*>::iterator t_stack_it; map<string, int> tr_start_varMap; map<int,int> tr_start_valMap; Transaction *t = new Transaction(0); Transaction* tr_start; for (t_stack_it = trans_stack.begin(); t_stack_it != trans_stack.end(); ++t_stack_it) { tr_start = *t_stack_it; // get all varMap and valMapentries from tr_start to t tr_start_varMap = tr_start->get_varMap(); //tr_start_valMap = tr_start->get_valMap(); t->populate_vmaps(tr_start_varMap); //clear the copy buffers tr_start_valMap.erase(tr_start_valMap.begin(), tr_start_valMap.end()); tr_start_varMap.erase(tr_start_varMap.begin(), tr_start_varMap.end()); } trans_stack.erase(trans_stack.begin(), trans_stack.end()); trans_stack.push_back(t); }
void TransactionHandler::work() { //std::lock_guard<std::mutex> guard(m); //m.lock(); int i = 0; while (!mQueue.empty()) { //m.unlock(); //m.lock(); Transaction* t = mQueue.front(); mQueue.pop(); //m.unlock(); t->call(); //m1.lock(); //std::cout << std::this_thread::get_id() << ": " << i << std::endl; //m1.unlock(); i++; } //delete t; //m1.lock(); //std::cout << "I am " << std::this_thread::get_id() << " and I did " << i << " transactions. " << std::endl; //m1.unlock(); }
void AspEventHandler::report_topsortedtx() { char buff[256]; assert(ASP_ROOT != NULL); sprintf(buff, "%s/asp/analysis/work/%s/%s", ASP_ROOT, test_name_, TRACE_FILE); FILE* trace_file = fopen(buff, "w"); if(!trace_file) { printf("Error in opening the trace file /tmp/trace.txt !"); exit(-1); } for(TransactionPtrList::iterator itr = txlist_sorted_.begin(); itr != txlist_sorted_.end(); ++itr) { Transaction* tx = (*itr); fprintf(report_file_, "%s\n", TXID_ToString(tx->txid()).c_str()); // write to Richard's trace file format AccessBasePtrList* accesses = tx->accesses(); for(AccessBasePtrList::iterator iter = accesses->begin(); iter < accesses->end(); ++iter) { AccessBase* access = (*iter); if(access->is_array() && access->is_write()) { fprintf(trace_file, "_asp_log_write(%s, %d, %s, %.4f)\n", access->base_name(), access->offset(), "_my_in_img", access->double_value()); } } } fclose(trace_file); }
int s3fs_getattr(const char *path, struct stat *stbuf) { #ifdef DEBUG syslog(LOG_INFO, "getattr[%s]", path); #endif try { Transaction t; t.getExisting(path); if (t.file->deleted) throw -ENOENT; t.file->info->toStat(stbuf); return 0; } catch (int e) { if (e == -ENOENT) { // getattr is used to check if a file exists, so // getting a File Not Found error is nothing to worry about #ifdef DEBUG syslog(LOG_INFO, "getattr[%s]: File not found", path); #endif } else { syslog(LOG_INFO, "getattr[%s]: %s", path, strerror(e)); } return e; } }
bool AspEventHandler::UpdateConflictEdges(AccessBase* access, AccessBasePtrList* accesses) { bool conflicting = false; ADDRINT mem = access->mem(); if(accesses != NULL) { assert(accesses->size() > 0); Transaction* tx = access->tx(); // record last accesses in the transaction graph for(AccessBasePtrList::iterator itr = accesses->begin(); itr < accesses->end(); ++itr) { AccessBase* lastAccess = (*itr); assert(lastAccess->mem() == mem); conflicting = conflicting || lastAccess->conflicts_with(access); if(conflicting) { // add a conflict edge Transaction* lastTx = lastAccess->tx(); assert(lastTx != NULL); if(lastTx->conflicts_with(tx)) { lastTx->AddConflictEdge(lastAccess, access); } } else { break; } } } return conflicting; }
int s3fs_readlink(const char *path, char *buf, size_t size) { #ifdef DEBUG syslog(LOG_INFO, "readlink[%s]", path); #endif // save room for null at the end size--; if (size <= 0) return 0; try { Transaction t; t.getExisting(path); t.getFd(); struct stat st; if (fstat(t.file->fd, &st) < 0) throw -errno; if ((size_t) st.st_size < size) size = st.st_size; if (pread(t.file->fd, buf, size, 0) < 0) throw -errno; buf[size] = 0; return 0; } catch (int e) { syslog(LOG_INFO, "readlink[%s]: %s", path, strerror(e)); return e; } }
Void metadata::Transaction::RemoveNextTransactions() { if(!current_transaction.isValid()) return; for(Transaction tmp = current_transaction.getNextTransactionTransaction(); tmp.isValid(); tmp = current_transaction.getNextTransactionTransaction()) tmp.destroy(); }
int s3fs_truncate(const char *path, off_t size) { #ifdef DEBUG syslog(LOG_INFO, "truncate[%s] size[%llu]", path, (unsigned long long) size); #endif try { Transaction t; t.getExisting(path); // the easy case if ((size_t) size == t.file->info->size) return 0; // we don't have it locally if (size == 0) t.file->info->size = 0; // this will only download if we don't have it and size > 0 t.getFd(); if (ftruncate(t.file->fd, size) < 0) throw -errno; t.file->info->mtime = time(NULL); t.file->dirty_data = true; t.file->dirty_metadata = true; return 0; } catch (int e) { syslog(LOG_INFO, "truncate[%s]: %s", path, strerror(e)); return e; } }
bool Budget::ChangeDate(string category, string oldtimestamp, string newtimestamp) { if (!_CategoryExists(category)) { return false; } Category* c = _categories.find(category)->second; // Don't do anything if the old timestamp doesn't exist if (c->Transactions()->count(oldtimestamp) == 0) { return false; } // Don't do anything if the new timestamp already exists if (c->Transactions()->count(newtimestamp) > 0) { return false; } // Temporarily remove the transaction Transaction* t = c->Transactions()->find(oldtimestamp)->second; c->Transactions()->erase(oldtimestamp); // Rename it t->SetTimestamp(newtimestamp); c->AddTransaction(t); return true; }
bool TransactionFilter::matches(State const& _s, unsigned _i) const { h256 b = _s.changesFromPending(_i).bloom(); if (!matches(b)) return false; Transaction t = _s.pending()[_i]; if (!m_to.empty() && !m_to.count(t.receiveAddress)) return false; if (!m_from.empty() && !m_from.count(t.sender())) return false; if (m_stateAltered.empty() && m_altered.empty()) return true; StateDiff d = _s.pendingDiff(_i); if (!m_altered.empty()) { for (auto const& s: m_altered) if (d.accounts.count(s)) return true; return false; } if (!m_stateAltered.empty()) { for (auto const& s: m_stateAltered) if (d.accounts.count(s.first) && d.accounts.at(s.first).storage.count(s.second)) return true; return false; } return true; }
void Category::Save(ofstream& file) { for (Category::Iterator i = Begin(); i != End(); i++) { Transaction* t = i->second; csv_fwrite(file, Name()); file << ','; csv_fwrite(file, t->Timestamp()); file << ','; csv_fwrite(file, t->Reason()); file << ','; ostringstream amount; amount.setf(ios::showpoint); amount.setf(ios::fixed); amount << setprecision(2) << t->Amount(); csv_fwrite(file, amount.str()); file << ','; csv_fwrite(file, t->Action()); file << "\r\n"; // Carriage return + line feed (DOS style newline) } }
Json::Value toJson(dev::eth::TransactionReceipt const& _tr, std::pair<h256, unsigned> _location, BlockNumber _blockNumber, Transaction const& _t) { Json::Value res; h256 h = _t.sha3(); res["transactionHash"] = toJS(h); res["transactionIndex"] = _location.second; res["blockHash"] = toJS(_location.first); res["blockNumber"] = _blockNumber; res["cumulativeGasUsed"] = toJS(_tr.gasUsed()); // TODO: check if this is fine res["gasUsed"] = toJS(_tr.gasUsed()); res["contractAddress"] = toJS(toAddress(_t.from(), _t.nonce())); res["logs"] = Json::Value(Json::arrayValue); for (unsigned i = 0; i < _tr.log().size(); i++) { LogEntry e = _tr.log()[i]; Json::Value l = toJson(e); l["type"] = "mined"; l["blockNumber"] = _blockNumber; l["blockHash"] = toJS(_location.first); l["logIndex"] = i; l["transactionHash"] = toJS(h); l["transactionIndex"] = _location.second; res["logs"].append(l); } return res; }
BitcoinChain::BitcoinChain() : _genesis("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f") { _messageStart[0] = 0xf9; _messageStart[1] = 0xbe; _messageStart[2] = 0xb4; _messageStart[3] = 0xd9; const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"; Transaction txNew; Script signature = Script() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); txNew.addInput(Input(Coin(), signature)); Script script = Script() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG; txNew.addOutput(Output(50 * COIN, script)); _genesisBlock = Block(1, 0, 0, 1231006505, 0x1d00ffff, 2083236893); _genesisBlock.addTransaction(txNew); _genesisBlock.updateMerkleTree(); // genesisBlock assert(_genesisBlock.getHash() == _genesis); _checkpoints = boost::assign::map_list_of ( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ( 68555, uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ( 70567, uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) (105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) (118000, uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553")) (134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")) (140700, uint256("0x000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd")) (168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")) ; }
static Eina_Bool ecore_ise_input_handler (void *data, Ecore_Fd_Handler *fd_handler) { int cmd; int timeout = 0; Transaction trans; if (fd_handler == NULL) return ECORE_CALLBACK_RENEW; int fd = ecore_main_fd_handler_fd_get (fd_handler); if (_imcontrol_client.is_connected () && isf_socket_wait_for_data_internal (fd, timeout) > 0) { trans.clear (); if (!trans.read_from_socket (fd, timeout)) { IMFCONTROLERR ("%s:: read_from_socket() may be timeout \n", __FUNCTION__); _isf_imf_control_finalize (); return ECORE_CALLBACK_CANCEL; } if (trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REQUEST) { while (trans.get_command (cmd)) { ecore_ise_process_data (trans, cmd); } } return ECORE_CALLBACK_RENEW; } IMFCONTROLERR ("ecore_ise_input_handler is failed!!!\n"); _isf_imf_control_finalize (); return ECORE_CALLBACK_CANCEL; }
status_t BPackageManager::ClientInstallationInterface::PrepareTransaction( Transaction& transaction) { return fDaemonClient.CreateTransaction(transaction.Repository().Location(), transaction.ActivationTransaction(), transaction.TransactionDirectory()); }
void update_aux_string (int icid, const WideString &str, const AttributeList &attrs) { if (m_send_refcount > 0 && m_current_icid == icid) { m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_AUX_STRING); m_send_trans.put_data (utf8_wcstombs (str)); m_send_trans.put_data (attrs); } }
void send_helper_event (int icid, const String &helper_uuid, const Transaction &trans) { if (m_send_refcount > 0 && m_current_icid == icid) { m_send_trans.put_command (SCIM_TRANS_CMD_SEND_HELPER_EVENT); m_send_trans.put_data (helper_uuid); m_send_trans.put_data (trans); } }
void update_spot_location (int icid, int x, int y) { if (m_send_refcount > 0 && m_current_icid == icid) { m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_SPOT_LOCATION); m_send_trans.put_data ((uint32) x); m_send_trans.put_data ((uint32) y); } }