本文整理汇总了C++中Offer类的典型用法代码示例。如果您正苦于以下问题:C++ Offer类的具体用法?C++ Offer怎么用?C++ Offer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Offer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: limit
TER
Taker::cross (Offer const& offer)
{
assert (!done ());
/* Before we call flow we must set the limit right; for buy semantics we
need to clamp the output. And we always want to clamp the input.
*/
Amounts limit (offer.amount());
if (! m_options.sell)
limit = offer.quality ().ceil_out (limit, m_remain.out);
limit = offer.quality().ceil_in (limit, m_remain.in);
assert (limit.in <= offer.amount().in);
assert (limit.out <= offer.amount().out);
assert (limit.in <= m_remain.in);
Amounts const amount (flow (limit, offer, account ()));
m_remain.out -= amount.out;
m_remain.in -= amount.in;
assert (m_remain.in >= zero);
return fill (offer, amount);
}
示例2:
bool Offer::operator==(Offer& other)
{
if (this->destination == other.getDest() &&
this->type == other.getType() &&
this->price == other.getPrice())
return (true);
return (false);
}
示例3: createTask
inline TaskInfo createTask(
const Offer& offer,
const std::string& command,
const Option<mesos::ExecutorID>& executorId = None(),
const std::string& name = "test-task",
const std::string& id = UUID::random().toString())
{
return createTask(
offer.slave_id(), offer.resources(), command, executorId, name, id);
}
示例4: fill
TER
Taker::cross (Offer const& offer)
{
// In direct crossings, at least one leg must not be XRP.
if (isXRP (offer.amount ().in) && isXRP (offer.amount ().out))
return tefINTERNAL;
auto const amount = do_cross (
offer.amount (), offer.quality (), offer.owner ());
return fill (amount, offer);
}
示例5: consume
// Fill a direct offer.
// @param offer the offer we are going to use.
// @param amount the amount to flow through the offer.
// @returns: tesSUCCESS if successful, or an error code otherwise.
TER
Taker::fill (Offer const& offer, Amounts const& amount)
{
consume (offer, amount);
// Pay the taker, then the owner
TER result = view ().accountSend (offer.account(), account(), amount.out);
if (result == tesSUCCESS)
result = view ().accountSend (account(), offer.account(), amount.in);
return result;
}
示例6: assert
// Performs funds transfers to fill the given offer and adjusts offer.
TER
Taker::fill (BasicTaker::Flow const& flow, Offer const& offer)
{
// adjust offer
consume_offer (offer, flow.order);
TER result = tesSUCCESS;
if (cross_type () != CrossType::XrpToIou)
{
assert (!isXRP (flow.order.in));
if(result == tesSUCCESS)
result = redeemIOU (account (), flow.issuers.in, flow.issuers.in.issue ());
if (result == tesSUCCESS)
result = issueIOU (offer.owner (), flow.order.in, flow.order.in.issue ());
}
else
{
assert (isXRP (flow.order.in));
if (result == tesSUCCESS)
result = transferXRP (account (), offer.owner (), flow.order.in);
}
// Now send funds from the account whose offer we're taking
if (cross_type () != CrossType::IouToXrp)
{
assert (!isXRP (flow.order.out));
if(result == tesSUCCESS)
result = redeemIOU (offer.owner (), flow.issuers.out, flow.issuers.out.issue ());
if (result == tesSUCCESS)
result = issueIOU (account (), flow.order.out, flow.order.out.issue ());
}
else
{
assert (isXRP (flow.order.out));
if (result == tesSUCCESS)
result = transferXRP (offer.owner (), account (), flow.order.out);
}
if (result == tesSUCCESS)
direct_crossings_++;
return result;
}
示例7: createTasks
// TODO(benh): Move this into utils, make more generic, and use in
// other tests.
vector<TaskInfo> createTasks(const Offer& offer)
{
TaskInfo task;
task.set_name("test-task");
task.mutable_task_id()->set_value("1");
task.mutable_slave_id()->MergeFrom(offer.slave_id());
task.mutable_resources()->MergeFrom(offer.resources());
task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);
vector<TaskInfo> tasks;
tasks.push_back(task);
return tasks;
}
示例8: Offer
void TableListener::printOffer(IO2GOfferTableRow *offerRow, const char *sInstrument)
{
Offer *offer = mOffers->findOffer(offerRow->getOfferID());
if (offer)
{
if (offerRow->isTimeValid() && offerRow->isBidValid() && offerRow->isAskValid())
{
offer->setDate(offerRow->getTime());
offer->setBid(offerRow->getBid());
offer->setAsk(offerRow->getAsk());
}
}
else
{
offer = new Offer(offerRow->getOfferID(), offerRow->getInstrument(),
offerRow->getDigits(), offerRow->getPointSize(), offerRow->getTime(),
offerRow->getBid(), offerRow->getAsk());
mOffers->addOffer(offer);
}
if (!sInstrument || strlen(sInstrument) == 0 || strcmp(offerRow->getInstrument(), sInstrument) == 0)
{
std::cout << offer->getID() << ", " << offer->getInstrument() << ", "
<< "Bid=" << std::fixed << offer->getBid() << ", "
<< "Ask=" << std::fixed << offer->getAsk() << std::endl;
}
}
示例9: getScalarResource
inline double getScalarResource(const Offer& offer, const std::string& name)
{
double value = 0.0;
for (int i = 0; i < offer.resources_size(); i++) {
const Resource& resource = offer.resources(i);
if (resource.name() == name &&
resource.type() == Value::SCALAR) {
value = resource.scalar().value();
}
}
return value;
}
示例10: createTask
inline TaskInfo createTask(
const Offer& offer,
const std::string& command,
const std::string& name = "test-task",
const std::string& id = UUID::random().toString())
{
TaskInfo task;
task.set_name(name);
task.mutable_task_id()->set_value(id);
task.mutable_slave_id()->MergeFrom(offer.slave_id());
task.mutable_resources()->MergeFrom(offer.resources());
task.mutable_command()->set_value(command);
return task;
}
示例11: remaining
// Adjust an offer to indicate that we are consuming some (or all) of it.
void
Taker::consume (Offer const& offer, Amounts const& consumed) const
{
Amounts const& remaining (offer.amount ());
assert (remaining.in > zero && remaining.out > zero);
assert (remaining.in >= consumed.in && remaining.out >= consumed.out);
offer.entry ()->setFieldAmount (sfTakerPays, remaining.in - consumed.in);
offer.entry ()->setFieldAmount (sfTakerGets, remaining.out - consumed.out);
view ().entryModify (offer.entry());
assert (offer.entry ()->getFieldAmount (sfTakerPays) >= zero);
assert (offer.entry ()->getFieldAmount (sfTakerGets) >= zero);
}
示例12: limit
TER
Taker::cross (Offer const& offer)
{
assert (!done ());
Amounts limit (offer.amount());
if (m_options.sell)
limit = offer.quality().ceil_in (limit, m_remain.in);
else
limit = offer.quality ().ceil_out (limit, m_remain.out);
assert (limit.out <= offer.amount().out);
assert (limit.in <= offer.amount().in);
Amounts const amount (flow (limit, offer, account ()));
m_remain.out -= amount.out;
m_remain.in -= amount.in;
assert (m_remain.in >= zero);
return fill (offer, amount);
}
示例13:
void
Taker::consume_offer (Offer const& offer, Amounts const& order)
{
if (order.in < zero)
Throw<std::logic_error> ("flow with negative input.");
if (order.out < zero)
Throw<std::logic_error> ("flow with negative output.");
if (journal_.debug) journal_.debug << "Consuming from offer " << offer;
if (journal_.trace)
{
auto const& available = offer.amount ();
journal_.trace << " in:" << format_amount (available.in);
journal_.trace << " out:" << format_amount(available.out);
}
offer.consume (view_, order);
}
示例14: taker_funds
/** Calculate the amount particular user could get through an offer.
@param amount the maximum flow that is available to the taker.
@param offer the offer to flow through.
@param taker the person taking the offer.
@return the maximum amount that can flow through this offer.
*/
Amounts
Taker::flow (Amounts amount, Offer const& offer, Account const& taker)
{
// Limit taker's input by available funds less fees
Amount const taker_funds (view ().accountFunds (
taker, amount.in, fhZERO_IF_FROZEN));
// Get fee rate paid by taker
std::uint32_t const taker_charge_rate (rippleTransferRate (view (),
taker, offer.account (), amount.in.getIssuer()));
// Skip some math when there's no fee
if (taker_charge_rate == QUALITY_ONE)
{
amount = offer.quality ().ceil_in (amount, taker_funds);
}
else
{
Amount const taker_charge (amountFromRate (taker_charge_rate));
amount = offer.quality ().ceil_in (amount,
divide (taker_funds, taker_charge, taker_funds.issue ()));
}
// Best flow the owner can get.
// Start out assuming entire offer will flow.
Amounts owner_amount (amount);
// Limit owner's output by available funds less fees
Amount const owner_funds (view ().accountFunds (
offer.account (), owner_amount.out, fhZERO_IF_FROZEN));
// Get fee rate paid by owner
std::uint32_t const owner_charge_rate (rippleTransferRate (view (),
offer.account (), taker, amount.out.getIssuer()));
if (owner_charge_rate == QUALITY_ONE)
{
// Skip some math when there's no fee
owner_amount = offer.quality ().ceil_out (owner_amount, owner_funds);
}
else
{
Amount const owner_charge (amountFromRate (owner_charge_rate));
owner_amount = offer.quality ().ceil_out (owner_amount,
divide (owner_funds, owner_charge, owner_funds.issue ()));
}
// Calculate the amount that will flow through the offer
// This does not include the fees.
return (owner_amount.in < amount.in)
? owner_amount
: amount;
}
示例15: createTask
inline TaskInfo createTask(
const Offer& offer,
const std::string& command,
const Option<mesos::ExecutorID>& executorId = None(),
const std::string& name = "test-task",
const std::string& id = UUID::random().toString())
{
TaskInfo task;
task.set_name(name);
task.mutable_task_id()->set_value(id);
task.mutable_slave_id()->CopyFrom(offer.slave_id());
task.mutable_resources()->CopyFrom(offer.resources());
if (executorId.isSome()) {
ExecutorInfo executor;
executor.mutable_executor_id()->CopyFrom(executorId.get());
executor.mutable_command()->set_value(command);
task.mutable_executor()->CopyFrom(executor);
} else {
task.mutable_command()->set_value(command);
}
return task;
}