Skip to content

Commit

Permalink
Sell by param (#27)
Browse files Browse the repository at this point in the history
* enable sell by date as parameter
  • Loading branch information
cthacker authored Jul 28, 2020
1 parent d668f41 commit d2710a3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ different metadata
Changes
=======

v1.1.5 - List For Sale Configurable Time
----

Instead of a sale lasting a default of one week, it is now configurable and exposed as a parameter
in `listsalenft`.

* if `sell_by_days` is 0, sale is treated as indefinite
* if `sell_by_days` > 0, the sale will be valid for `sell_by_days` number of days

Note that a sale will still need to be closed after expiration has passed. This can be done by
anyone if the sale is expired by calling `closesalenft`.



v1.1 - Time Based Minting
----

Expand Down
4 changes: 4 additions & 0 deletions build/dgoods/dgoods.abi
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@
"name": "dgood_ids",
"type": "uint64[]"
},
{
"name": "sell_by_days",
"type": "uint32"
},
{
"name": "net_sale_amount",
"type": "asset"
Expand Down
Binary file modified build/dgoods/dgoods.wasm
Binary file not shown.
5 changes: 3 additions & 2 deletions dgoods_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ ACTION transferft(name from, name to, name category, name token_name, asset quan

**LISTSALENFT**: Used to list nfts for sale in the token contract itself. Callable only by owner,
if sellable is true and token not locked, creates sale listing in the token contract, marks token as
not transferable while listed for sale. An array of dgood_ids is required.
not transferable while listed for sale. Sale is valid for `sell_by_days` number of days. If
`sell_by_days` is 0, listing is indefinite. An array of dgood_ids is required.

```c++
ACTION listsalenft(name seller, vector<uint64_t> dgood_ids, asset net_sale_amount);
ACTION listsalenft(name seller, vector<uint64_t> dgood_ids, uint32_t sell_by_days, asset net_sale_amount);
```
**CLOSESALENFT**: Callable by seller if listing hasn't expired, or anyone if the listing is expired;
Expand Down
3 changes: 1 addition & 2 deletions include/dgoods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ CONTRACT dgoods: public contract {
public:
using contract::contract;

const int WEEK_SEC = 3600*24*7;

dgoods(name receiver, name code, datastream<const char*> ds)
: contract(receiver, code, ds) {}

Expand Down Expand Up @@ -71,6 +69,7 @@ CONTRACT dgoods: public contract {

ACTION listsalenft(const name& seller,
const vector<uint64_t>& dgood_ids,
const uint32_t sell_by_days,
const asset& net_sale_amount);

ACTION closesalenft(const name& seller,
Expand Down
14 changes: 11 additions & 3 deletions src/dgoods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,17 @@ ACTION dgoods::transferft(const name& from,

ACTION dgoods::listsalenft(const name& seller,
const vector<uint64_t>& dgood_ids,
const uint32_t sell_by_days,
const asset& net_sale_amount) {
require_auth( seller );

time_point_sec expiration = time_point_sec(0);

if ( sell_by_days != 0 ) {
uint32_t sell_by_seconds = sell_by_days * 24 * 3600;
expiration = time_point_sec(current_time_point()) + sell_by_seconds;
}

check (dgood_ids.size() <= 20, "max batch size of 20");
check( net_sale_amount.amount > .02 * pow(10, net_sale_amount.symbol.precision()), "minimum price of at least 0.02 EOS");
check( net_sale_amount.symbol == symbol( symbol_code("EOS"), 4), "only accept EOS for sale" );
Expand Down Expand Up @@ -299,7 +307,7 @@ ACTION dgoods::listsalenft(const name& seller,
a.dgood_ids = dgood_ids;
a.seller = seller;
a.amount = net_sale_amount;
a.expiration = time_point_sec(current_time_point()) + WEEK_SEC;
a.expiration = expiration;
});
}

Expand All @@ -309,7 +317,7 @@ ACTION dgoods::closesalenft(const name& seller,
const auto& ask = ask_table.get( batch_id, "cannot find sale to close" );

lock_index lock_table( get_self(), get_self().value );
if ( time_point_sec(current_time_point()) <= ask.expiration ) {
if ( ask.expiration == time_point_sec(0) || time_point_sec(current_time_point()) <= ask.expiration ) {
require_auth( seller );
check( ask.seller == seller, "only the seller can cancel a sale in progress");
}
Expand Down Expand Up @@ -342,7 +350,7 @@ void dgoods::buynft(const name& from,
ask_index ask_table( get_self(), get_self().value );
const auto& ask = ask_table.get( batch_id, "cannot find listing" );
check ( ask.amount.amount == quantity.amount, "send the correct amount");
check (ask.expiration > time_point_sec(current_time_point()), "sale has expired");
check ( ask.expiration == time_point_sec(0) || ask.expiration > time_point_sec(current_time_point()), "sale has expired");

// nft(s) bought, change owner to buyer regardless of transferable
_changeowner( ask.seller, to_account, ask.dgood_ids, "bought by: " + to_account.to_string(), false);
Expand Down

0 comments on commit d2710a3

Please sign in to comment.