Ejemplo n.º 1
0
      boost::optional<Answer> YacProposalStorage::insert(VoteMessage msg) {
        if (shouldInsert(msg)) {
          // insert to block store

          log_->info("Vote [{}, {}] looks valid",
                     msg.hash.proposal_hash,
                     msg.hash.block_hash);

          auto iter = findStore(msg.hash.proposal_hash, msg.hash.block_hash);
          auto block_state = iter->insert(msg);

          // Single BlockStorage always returns CommitMessage because it
          // aggregates votes for a single hash.
          if (block_state) {
            // supermajority on block achieved
            current_state_ = std::move(block_state);
          } else {
            // try to find reject case
            auto reject_state = findRejectProof();
            if (reject_state) {
              log_->info("Found reject proof");
              current_state_ = std::move(reject_state);
            }
          }
        }
        return getState();
      }
Ejemplo n.º 2
0
bool
ObjectCache::findStore(Id store_id, Store& store)
{
    Store* object = findStore(store_id);
    if (object == NULL) return false;
    store = *object;
    return true;
}
Ejemplo n.º 3
0
void
Journal::addToList(JournalWindow* window, const Gltx& gltx)
{
    if (window == NULL) return;
    ListViewItem* item = new ListViewItem(window->list, window->last,
					  gltx.id());
    window->last = item;

    Store store;
    findStore(gltx.storeId(), store);

    item->setValue(0, gltx.dataTypeName());
    item->setValue(1, gltx.number());
    item->setValue(2, store.number());
    item->setValue(3, gltx.postDate());
    item->setValue(4, gltx.memo());
    item->setValue(7, !gltx.isActive());

    for (unsigned int i = 0; i < gltx.accounts().size(); ++i) {
	const AccountLine& line = gltx.accounts()[i];

	Account account;
	for (unsigned int a = 0; a < _accounts.size(); ++a) {
	    if (_accounts[a].id() == line.account_id) {
		account = _accounts[a];
		break;
	    }
	}

	ListViewItem* item = new ListViewItem(window->list, window->last,
					      gltx.id());
	window->last = item;

	item->setValue(4, account.name());
	if (line.amount >= 0.0)
	    item->setValue(5, line.amount);
	else
	    item->setValue(6, -line.amount);
    }
}
Ejemplo n.º 4
0
DataObject*
ObjectCache::find(Id object_id, bool cacheOnly)
{
    if (object_id == INVALID_ID)
	return NULL;

    if (_objects.find(object_id) != _objects.end())
	return _objects[object_id];

    if (cacheOnly)
	return NULL;

    DataObject object;
    if (!_db->lookup(object_id, object))
	return NULL;

    switch (object.dataType()) {
    case DataObject::ACCOUNT:		return findAccount(object_id);
    case DataObject::ADJUST_REASON:	return findAdjustReason(object_id);
    case DataObject::CARD_ADJUST:	return findCardAdjust(object_id);
    case DataObject::CHARGE:		return findCharge(object_id);
    case DataObject::CHEQUE:		return findCheque(object_id);
    case DataObject::CLAIM:		return findReceive(object_id);
    case DataObject::COMPANY:		return findCompany(object_id);
    case DataObject::COUNT:		return findCount(object_id);
    case DataObject::CUSTOMER:		return findCustomer(object_id);
    case DataObject::CUST_TYPE:		return findCustomerType(object_id);
    case DataObject::DEPT:		return findDept(object_id);
    case DataObject::DISCOUNT:		return findDiscount(object_id);
    case DataObject::EMPLOYEE:		return findEmployee(object_id);
    case DataObject::EXPENSE:		return findExpense(object_id);
    case DataObject::EXTRA:		return findExtra(object_id);
    case DataObject::GENERAL:		return findGeneral(object_id);
    case DataObject::GROUP:		return findGroup(object_id);
    case DataObject::INVOICE:		return findInvoice(object_id);
    case DataObject::ITEM:		return findItem(object_id);
    case DataObject::ITEM_ADJUST:	return findItemAdjust(object_id);
    case DataObject::ITEM_PRICE:	return findItemPrice(object_id);
    case DataObject::LABEL_BATCH:	return findLabelBatch(object_id);
    case DataObject::LOCATION:		return findLocation(object_id);
    case DataObject::NOSALE:		return findNosale(object_id);
    case DataObject::ORDER:		return findOrder(object_id);
    case DataObject::PO_TEMPLATE:	return findOrderTemplate(object_id);
    case DataObject::PAT_GROUP:		return findPatGroup(object_id);
    case DataObject::PAT_WS:		return findPatWorksheet(object_id);
    case DataObject::PAYOUT:		return findPayout(object_id);
    case DataObject::PERSONAL:		return findPersonal(object_id);
    case DataObject::PLU:		assert("Invalid data type: PLU");
    case DataObject::PRICE_BATCH:	return findPriceBatch(object_id);
    case DataObject::PROMO_BATCH:	return findPromoBatch(object_id);
    case DataObject::QUOTE:		return findQuote(object_id);
    case DataObject::RECEIPT:		return findReceipt(object_id);
    case DataObject::RECEIVE:		return findReceive(object_id);
    case DataObject::RECONCILE:		return findReconcile(object_id);
    case DataObject::RECURRING:		return findRecurring(object_id);
    case DataObject::REPORT:		assert("Invalid data type: REPORT");
    case DataObject::RETURN:		return findInvoice(object_id);
    case DataObject::SECURITY_TYPE:	return findSecurityType(object_id);
    case DataObject::SHIFT:		return findShift(object_id);
    case DataObject::SLIP:		return findSlip(object_id);
    case DataObject::STATION:		return findStation(object_id);
    case DataObject::STORE:		return findStore(object_id);
    case DataObject::SUBDEPT:		return findSubdept(object_id);
    case DataObject::TAX:		return findTax(object_id);
    case DataObject::TENDER:		return findTender(object_id);
    case DataObject::TEND_COUNT:	return findTenderCount(object_id);
    case DataObject::TEND_ADJUST:	return findTenderAdjust(object_id);
    case DataObject::TERM:		return findTerm(object_id);
    case DataObject::TODO:		return findTodo(object_id);
    case DataObject::USER:		return findUser(object_id);
    case DataObject::VENDOR:		return findVendor(object_id);
    case DataObject::WITHDRAW:		return findWithdraw(object_id);
    }

    qWarning("Unknown object type: " + object.dataTypeName());
    return NULL;
}