Modern UI contract: transfer read and transfer.submit
The transfer read lists the transfer list with asking fee, salary reference, offers and the own bid, and the own squad. transfer.submit lists an own player (or offers him for loan) or bids through the original's offer editor (open, set fee, salary and years, submit); the outcome tells accepted, pending or rejected. The open editor is part of the rollback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43317985e4
commit
1400848387
3 files changed
+179
-1
No files matched your search
@@ -342,6 +342,39 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// transfers: list an own player, bid on a listed one (asking fee and salary reference)
|
||||
{
|
||||
const J market = session.ui_read(O{{"kind", "transfer"}}, rev);
|
||||
const auto* listings = at(at(market, "data"), "listings").array();
|
||||
const auto* squad = at(at(market, "data"), "squad").array();
|
||||
check(s(at(market, "messageType")) == "snapshot" && listings && squad && !squad->empty(), "transfer read");
|
||||
const uint64_t before = rev;
|
||||
if (squad && squad->size() > 15) {
|
||||
const std::string seller = s(at(squad->back(), "playerId"));
|
||||
const J listed = session.ui_command(cmd("request:t9", "transfer.submit", O{{"action", "list"}, {"playerId", seller}}), rev);
|
||||
if (s(at(listed, "messageType")) != "command_result") std::fprintf(stderr, "list: %s\n", cli::dump_json(listed).c_str());
|
||||
check(s(at(listed, "messageType")) == "command_result" && rev == before + 1, "own player listed");
|
||||
}
|
||||
std::string listing;
|
||||
J fee, salary;
|
||||
if (listings)
|
||||
for (const auto& l : *listings)
|
||||
if (listing.empty() && !truth(at(l, "ownListing")) && !truth(at(l, "ownBidPending")))
|
||||
listing = s(at(l, "id")), fee = at(l, "askingFee"), salary = at(l, "salaryReference");
|
||||
if (!listing.empty()) {
|
||||
// the salary reference is annual in the market row; the offer takes a monthly salary
|
||||
const int64_t monthly = std::stoll(s(at(salary, "minor"))) / 12 / 100 * 100;
|
||||
const uint64_t b2 = rev;
|
||||
const J bid = session.ui_command(cmd("request:t10", "transfer.submit",
|
||||
O{{"action", "bid"}, {"listingId", listing}, {"fee", fee},
|
||||
{"monthlySalary", O{{"minor", std::to_string(monthly)}, {"currency", "EUR"}, {"minorUnits", 2}}}, {"years", 2}}), rev);
|
||||
std::printf("(bid on %s: %s)\n", listing.c_str(), cli::dump_json(bid).substr(0, 260).c_str());
|
||||
check((s(at(bid, "messageType")) == "command_result" && rev == b2 + 1) ||
|
||||
(s(at(bid, "messageType")) == "error" && rev == b2), "bid answered or refused cleanly");
|
||||
}
|
||||
check(s(at(session.ui_command(cmd("request:t11", "transfer.submit", O{{"action", "bid"}, {"listingId", "listing:999"}}), rev), "code")) ==
|
||||
"unknown_listing", "unknown listing refused");
|
||||
}
|
||||
// toto and the exclusive sponsor
|
||||
{
|
||||
const J toto = session.ui_read(O{{"kind", "toto"}}, rev);
|
||||
|
||||
Reference in new issue
Block a user