From 25ede89ec8a53e739e7a380a9fcab3c950e03fb0 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 4 Jun 2019 17:08:00 -0700 Subject: [PATCH] allow EOS to be deposited to contract without initiating buy --- Makefile | 4 ---- build/dgoods/dgoods.wasm | Bin 75193 -> 75826 bytes include/dasset.hpp | 7 +++++-- include/utility.hpp | 6 ++++-- src/dgoods.cpp | 7 +++++-- 5 files changed, 14 insertions(+), 10 deletions(-) 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 09d3b14271aac1ae83a006754f11f4dd9b4d5843..3a6775320357ce022da87d37b782010ac1561276 100755 GIT binary patch delta 6917 zcmZ`;3tUxI)<5gq7jQ*R>ZF3mxkpTVz@UwQFXT`vJ`l2|hxtN4@j@aGOVI?=O3O-F z+R;W$CrwLD<*N9|w1-WTnHXtmHD*nH>8M##O%Er(|2hZEnePjKzrEMlkM-LBwb$C$ zJ%`3k97$(uH!Tb(ikZOoIl26Gi#WYTYYrhQ|1#iK;s(rdDiFJmw(htv3{H zyf%TK?A6XSUds!;(5ol;MuU+{yEk<9=4V_5``xOin&x2JWu@3qWuMu@RJ6MTE?qUh zRD!0GqAI$Ysie9ls2S$l2Ni9g;Wnq`L@JJR-~~TEL)kd_nOg8ZO=YdN1zjg6X&J#UFEW`s5-;A3xE;s{@=>uwC|K{Oip=`I`#ya|>D zY1knw6YLeRMHJ9sHvr&@Nl}xX>3FgEe%-~@Y0<8tfSXsQCHDqnoU!ii>VnV0aOO?A z%YliOS|2gtvJ#9}qJ)C8v}`_`mO~S{XP?z*8~Sub`%|C2^abziYtd28?zgMOqIVRH zY-7!%p{V|UAPVx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Ypp~4wJD%R*S-X2<{`1`;^VHwd z#P=wnh7I*7$GFd)_X6Lg;A(y%9~d{&bWupn-R;``+Q$}%TLyn zX}clNub;2M%?*Kqc+(dn=zzD@mm9><<){1Nn{uWJw?EUs=sn|DEGk1)(p>=*r0eyl z2A@0=PUpP8oLMBctUT9(cbs*j_x0JH#~w;*WK~E z$tPd0p-)-662h~;89)d5{5K=OBM^t+i4Wfo zYoXQgy8(U)vLObMO2vjwHp5wb;aVuSz8;AahFq_Y@8s*ZDBGL;Q8p&3c(&ef^9~{b;$~%tHAXt+G%7ZY`IUve3-8QY@N-Rw_X=#zxQ4((UCo zYDaW(`#n2ZsvgQygmubKH`PD$BR?wBy}kzP?|f+xc((VW5!j9@yEUECPy10cMm8t) zLDSz!Yth_wQZ87JsYdO=S_kWSdTe!rNqTjINx9jC1ds@w^3yT;x&R8V>i+hq`-~!H z^+|ygtuIihF8b>g>Rd%wzed#_LsTD2gi@xDtwE8XdaDL?M>D1-Md{UQQV{wZM8A7Y z0w~3Ndvoe3I;~%*N$`vAtc5*gdjDE9yXpXE;6tGX8eJg?{H=c&NI-^OyEa{?mAV{+ z$+LQL5VeH%;z7?HFSs7P=UWGS{aC!8(gW*IHb~)v=DN2IEV)#_QisxT?8jdtAn-d^L5FF||W)+kl$c&SND~|2cwO`Wp?%L9_Hl4X7I((l0ciHu%j^Zy!NV zQHj1Zf*Q()j_TzRaNbXPP6RcgLj8IKLS&DwHl()xw~k3p>%=Gt$K5`rk7`Jf)$xOl z(>@_@biPn{BhejZDJQFm+7BI;_$=zy-1436HSkcqBgWi&qE`Be^TEVMQ!2d Yt5FnN^HcnD! 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;