Skip to content

Commit

Permalink
allow EOS to be deposited to contract without initiating buy
Browse files Browse the repository at this point in the history
  • Loading branch information
cthacker committed Jun 5, 2019
1 parent cb12ee6 commit 25ede89
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ build:
rm -rf build/*
mkdir -p build/dgoods
mv dgoods.abi dgoods.wasm build/dgoods/

.PHONY: ddata
ddata:
bash -c "kill $$(pidof nodeos)" && rm -rf ~/.local/share/eosio/nodeos/data/
Binary file modified build/dgoods/dgoods.wasm
Binary file not shown.
7 changes: 5 additions & 2 deletions include/dasset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ namespace dgoods_asset {

void _check_max(const uint64_t& a) {
static constexpr uint64_t max_amount = ( 1LL << 62 ) - 1;
check( a <= max_amount, "max supply must be less than 2^62 - 1");
check( a > 0, "max supply must be greater than 0");
check( a < max_amount, "max supply must be less than 2^62 - 1");
}

dasset() {}

void from_string(const string& s) {
string string_amount = trim(s);
check( ( string_amount[0] != '-' ), "Amount can not be negative" );
auto dot_pos = string_amount.find('.');
uint64_t uint_part;
uint64_t frac_part;
Expand All @@ -56,6 +56,7 @@ namespace dgoods_asset {
frac_part = stoull(string_amount.substr( dot_pos + 1 ));
}
amount = uint_part * p10 + frac_part;
check( amount > 0, "max supply must be greater than 0");

}

Expand All @@ -65,6 +66,7 @@ namespace dgoods_asset {
_check_precision(p);

string string_amount = trim(s);
check( ( string_amount[0] != '-' ), "Amount can not be negative" );
// 1.0 1. 1
uint64_t uint_part;
uint64_t frac_part;
Expand All @@ -81,6 +83,7 @@ namespace dgoods_asset {
_check_max(uint_part);
uint64_t p10 = _get_precision(p);
amount = uint_part * p10 + frac_part;
check( amount > 0, "max supply must be greater than 0");

}

Expand Down
6 changes: 4 additions & 2 deletions include/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ namespace utility {

tuple<uint64_t, name> parsememo(const string& memo) {
auto dot_pos = memo.find(',');
string errormsg = "malformed memo: must have dgood_id,to_account";
check ( dot_pos != string::npos, errormsg.c_str() );
if ( dot_pos != string::npos ) {
check( ( dot_pos != memo.size() - 1 ), "malformed memo, must have dgood_id,to_account");
check( ( dot_pos != memo.size() - 1 ), errormsg.c_str() );
}
// need to trim substring
// will abort if stoull throws error since wasm no error checking
uint64_t dgood_id = stoull( trim( memo.substr( 0, dot_pos ) ) );
name to_account = name( trim ( memo.substr( dot_pos + 1 ) ) );

Expand Down
7 changes: 5 additions & 2 deletions src/dgoods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,15 @@ ACTION dgoods::buynft(name from,
name to,
asset quantity,
string memo) {
// allow EOS to be sent by sending with empty string memo
if ( memo == "deposit" ) return;
// don't allow spoofs
if ( to != get_self() ) return;
if ( from == name("eosio.stake") ) return;
if ( quantity.symbol != symbol( symbol_code("EOS"), 4) ) return;
if ( memo.length() > 32 ) return;
// memo format comma separated
// dgood_id,to_account
//memo format comma separated
//dgood_id,to_account

uint64_t dgood_id;
name to_account;
Expand Down

0 comments on commit 25ede89

Please sign in to comment.