Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
name_bidding.cpp
Go to the documentation of this file.
3
4#include <sysio/transaction.hpp>
5
6namespace sysiosystem {
7
8 using sysio::current_time_point;
9 using sysio::token;
10
11 void system_contract::bidname( const name& bidder, const name& newname, const asset& bid ) {
12 require_auth( bidder );
13 check( newname.suffix() == newname, "you can only bid on top-level suffix" );
14
15 check( (bool)newname, "the empty name is not a valid account name to bid on" );
16 check( (newname.value & 0xFull) == 0, "13 character names are not valid account names to bid on" );
17 check( (newname.value & 0x1F0ull) == 0, "accounts with 12 character names and no dots can be created without bidding required" );
18 check( !is_account( newname ), "account already exists" );
19 check( bid.symbol == core_symbol(), "asset must be system token" );
20 check( bid.amount > 0, "insufficient bid" );
21 token::transfer_action transfer_act{ token_account, { {bidder, active_permission} } };
22 transfer_act.send( bidder, names_account, bid, std::string("bid name ")+ newname.to_string() );
23 name_bid_table bids(get_self(), get_self().value);
24 print( name{bidder}, " bid ", bid, " on ", name{newname}, "\n" );
25 auto current = bids.find( newname.value );
26 if( current == bids.end() ) {
27 bids.emplace( bidder, [&]( auto& b ) {
28 b.newname = newname;
29 b.high_bidder = bidder;
30 b.high_bid = bid.amount;
31 b.last_bid_time = current_time_point();
32 });
33 } else {
34 check( current->high_bid > 0, "this auction has already closed" );
35 check( bid.amount - current->high_bid > (current->high_bid / 10), "must increase bid by 10%" );
36 check( current->high_bidder != bidder, "account is already highest bidder" );
37
38 bid_refund_table refunds_table(get_self(), newname.value);
39
40 auto it = refunds_table.find( current->high_bidder.value );
41 if ( it != refunds_table.end() ) {
42 refunds_table.modify( it, same_payer, [&](auto& r) {
43 r.amount += asset( current->high_bid, core_symbol() );
44 });
45 } else {
46 refunds_table.emplace( bidder, [&](auto& r) {
47 r.bidder = current->high_bidder;
48 r.amount = asset( current->high_bid, core_symbol() );
49 });
50 }
51
53 t.actions.emplace_back( permission_level{current->high_bidder, active_permission},
54 get_self(), "bidrefund"_n,
55 std::make_tuple( current->high_bidder, newname )
56 );
57 t.delay_sec = 0;
58 uint128_t deferred_id = (uint128_t(newname.value) << 64) | current->high_bidder.value;
59 sysio::cancel_deferred( deferred_id );
60 t.send( deferred_id, bidder );
61
62 bids.modify( current, bidder, [&]( auto& b ) {
63 b.high_bidder = bidder;
64 b.high_bid = bid.amount;
65 b.last_bid_time = current_time_point();
66 });
67 }
68 }
69
70 void system_contract::bidrefund( const name& bidder, const name& newname ) {
71 bid_refund_table refunds_table(get_self(), newname.value);
72 auto it = refunds_table.find( bidder.value );
73 check( it != refunds_table.end(), "refund not found" );
74
76 transfer_act.send( names_account, bidder, asset(it->amount), std::string("refund bid on name ")+(name{newname}).to_string() );
77 refunds_table.erase( it );
78 }
79
80}
void print(std::ostream &os, int const level, std::string const &title, Catch::SourceLineInfo const &info)
const mie::Vuint & r
Definition bn.cpp:28
sysio::action_wrapper<"transfer"_n, &token::transfer > transfer_action
void bidrefund(const name &bidder, const name &newname)
static constexpr sysio::name token_account
static constexpr sysio::name active_permission
static constexpr sysio::name names_account
void bidname(const name &bidder, const name &newname, const asset &bid)
sysio::multi_index< "refunds"_n, refund_request > refunds_table
sysio::multi_index< "namebids"_n, name_bid, indexed_by<"highbid"_n, const_mem_fun< name_bid, uint64_t, &name_bid::by_high_bid > > > name_bid_table
sysio::multi_index< "bidrefunds"_n, bid_refund > bid_refund_table
#define value
Definition pkcs11.h:157
string to_string() const
Definition asset.cpp:19
Immutable except for fc::from_variant.
Definition name.hpp:43
std::string to_string() const
Definition name.cpp:19
fc::unsigned_int delay_sec
upper limit on the total CPU time billed for this transaction
vector< action > actions