diff --git a/Makefile b/Makefile index c86b047..d216841 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/build/dgoods/dgoods.wasm b/build/dgoods/dgoods.wasm index 09d3b14..3a67753 100755 Binary files a/build/dgoods/dgoods.wasm and b/build/dgoods/dgoods.wasm differ diff --git a/include/dasset.hpp b/include/dasset.hpp index a836e89..482b0f0 100644 --- a/include/dasset.hpp +++ b/include/dasset.hpp @@ -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; @@ -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"); } @@ -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; @@ -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"); } diff --git a/include/utility.hpp b/include/utility.hpp index 2dc00fd..60dfa26 100644 --- a/include/utility.hpp +++ b/include/utility.hpp @@ -34,10 +34,12 @@ namespace utility { tuple 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 ) ) ); diff --git a/src/dgoods.cpp b/src/dgoods.cpp index 5062c66..e546985 100644 --- a/src/dgoods.cpp +++ b/src/dgoods.cpp @@ -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;