diff --git a/contracts/currency/currency.cpp b/contracts/currency/currency.cpp index 699db572bff8a0ed4e1ace8593a3647fbfc37f2f..dd21b9bbf11899e89d5b5f1ecf3388c957d74740 100644 --- a/contracts/currency/currency.cpp +++ b/contracts/currency/currency.cpp @@ -42,7 +42,7 @@ extern "C" { account owned_account; //Initialize currency account only if it does not exist if ( !accounts::get( owned_account, N(currency) )) { - store_account( N(currency), account( currency_tokens(1000ll*1000ll*1000ll) ) ); + store_account( N(currency), account( currency_tokens(1000ull*1000ull*1000ull) ) ); } } diff --git a/contracts/currency/currency.hpp b/contracts/currency/currency.hpp index a31829b27de7cd65612260878375b2d3fc918f1c..0659cd769f03c3d8499b4316bb2552e60e4582af 100644 --- a/contracts/currency/currency.hpp +++ b/contracts/currency/currency.hpp @@ -87,7 +87,8 @@ namespace TOKEN_NAME { /** Assert statement to verify structure packing for account **/ - static_assert( sizeof(account) == sizeof(uint64_t)+sizeof(currency_tokens), "unexpected packing" ); + //This structure is *not* packed the check will not work for different sizes of currency_tockens + //static_assert( sizeof(account) == sizeof(uint64_t)+sizeof(currency_tokens), "unexpected packing" ); /** Defines the database table for account information diff --git a/contracts/eoslib/token.hpp b/contracts/eoslib/token.hpp index 642394c83000128e9f74dbb77ab657e1b948dec3..64a4a70e59fdf3b88e8e7006ea49b96921ce17da 100644 --- a/contracts/eoslib/token.hpp +++ b/contracts/eoslib/token.hpp @@ -58,6 +58,8 @@ namespace eosio { */ template struct token { + using number_type = NumberType; + static_assert(eosio::is_unsigned::value, "NumberType can only be unsigned number"); /** * Type of the currency (e.g. eos) represented as an unsigned 64 bit integer * @brief Type of the currency @@ -68,20 +70,22 @@ namespace eosio { * Default constructor * @brief Default constructor */ - token(){} + token() : quantity{} {} /** * Constructor for token given quantity of tokens available * @brief Constructor for token given quantity of tokens available * @param v - quantity of tokens available */ - explicit token( NumberType v ):quantity(v){}; +// template::value && eosio::is_same::value>::type> + template::value && !(sizeof(T)>sizeof(NumberType))>::type> + explicit token( T v ):quantity(v){}; /** * Quantity of tokens available * @brief Quantity of tokens available */ - NumberType quantity = 0; + NumberType quantity; /** * Subtracts quantity of token from this object diff --git a/contracts/eoslib/types.hpp b/contracts/eoslib/types.hpp index b4becfe5661920d83072b401d132b67e8d9b38b1..33c29369cffd9d669679704970bf50b479288d8a 100644 --- a/contracts/eoslib/types.hpp +++ b/contracts/eoslib/types.hpp @@ -89,4 +89,71 @@ namespace eosio { template struct remove_reference { typedef T type; }; ///@} + /** + * @ingroup types + * needed for universal references since we build with --nostdlib and thus std::forward is not available + * with forward(args...) we always guarantee correctness of the calling code + */ + template + constexpr decltype(auto) forward(U && u) noexcept + { + return static_cast(u); + } + + template< class T > + constexpr typename remove_reference::type&& move( T&& t ) noexcept { + return static_cast::type&&>(t); + } + + template + struct integral_constant { + static constexpr T value = v; + typedef T value_type; + typedef integral_constant type; // using injected-class-name + constexpr operator value_type() const noexcept { return value; } + constexpr value_type operator()() const noexcept { return value; } //since c++14 + }; + using true_type = integral_constant; + using false_type = integral_constant; + + template + struct is_same : false_type {}; + + template + struct is_same : true_type {}; + + + template struct voidify { using type = void; }; + template using void_t = typename voidify::type; + + template + struct supports_arithmetic_operations : false_type {}; + + //for no default ctor we'll need decltype(eosio::declval() +-/* eosio::declval()) + template + struct supports_arithmetic_operations> + : true_type {}; + + + namespace detail { + template::value> + struct is_unsigned : integral_constant {}; + + template + struct is_unsigned : false_type {}; + } // namespace detail + + template + struct is_unsigned : detail::is_unsigned::type {}; + + template + struct enable_if {}; + + template + struct enable_if { typedef T type; }; + } // namespace eos diff --git a/contracts/exchange/exchange.cpp b/contracts/exchange/exchange.cpp index 1e1c93c52a6e2534a107ee098e45c92e7c1f0894..5e81ff2560502d65da14f81eb9a5171df05ca07c 100644 --- a/contracts/exchange/exchange.cpp +++ b/contracts/exchange/exchange.cpp @@ -132,7 +132,7 @@ void apply_exchange_buy( buy_order order ) { bid& exchange_bid = order; require_auth( exchange_bid.buyer.name ); - assert( exchange_bid.quantity > eosio::tokens(0), "invalid quantity" ); + assert( exchange_bid.quantity > eosio::tokens(0u), "invalid quantity" ); assert( exchange_bid.expiration > now(), "order expired" ); print( name(exchange_bid.buyer.name), " created bid for ", order.quantity, " currency at price: ", order.at_price, "\n" ); @@ -163,7 +163,7 @@ void apply_exchange_buy( buy_order order ) { print( "lowest ask <= exchange_bid.at_price\n" ); match( exchange_bid, buyer_account, lowest_ask, seller_account ); - if( lowest_ask.quantity == currency_tokens(0) ) { + if( lowest_ask.quantity == currency_tokens(0u) ) { seller_account.open_orders--; save( seller_account ); save( buyer_account ); @@ -195,7 +195,7 @@ void apply_exchange_sell( sell_order order ) { ask& exchange_ask = order; require_auth( exchange_ask.seller.name ); - assert( exchange_ask.quantity > currency_tokens(0), "invalid quantity" ); + assert( exchange_ask.quantity > currency_tokens(0u), "invalid quantity" ); assert( exchange_ask.expiration > now(), "order expired" ); print( "\n\n", name(exchange_ask.seller.name), " created sell for ", order.quantity, @@ -224,7 +224,7 @@ void apply_exchange_sell( sell_order order ) { while( highest_bid.at_price >= exchange_ask.at_price ) { match( highest_bid, buyer_account, exchange_ask, seller_account ); - if( highest_bid.quantity == eos_tokens(0) ) { + if( highest_bid.quantity == eos_tokens(0u) ) { buyer_account.open_orders--; save( seller_account ); save( buyer_account ); diff --git a/contracts/exchange/exchange.hpp b/contracts/exchange/exchange.hpp index 4ad70c38317c2405ed033a4c6725d89a80d1b0d3..06616f600d2f8f450b9b411e26741741c9b7309c 100644 --- a/contracts/exchange/exchange.hpp +++ b/contracts/exchange/exchange.hpp @@ -28,7 +28,7 @@ namespace exchange { eosio::print( "{ quantity: ", quantity, ", price: ", at_price, " }" ); } }; - static_assert( sizeof(bid) == 32+12, "unexpected padding" ); + static_assert( sizeof(bid) == sizeof(order_id)+sizeof(price)+sizeof(eosio::tokens)+sizeof(time), "unexpected padding" ); //@abi table struct PACKED( ask ) { @@ -41,7 +41,8 @@ namespace exchange { eosio::print( "{ quantity: ", quantity, ", price: ", at_price, " }" ); } }; - static_assert( sizeof(ask) == 32+12, "unexpected padding" ); + static_assert( sizeof(ask) == sizeof(order_id)+sizeof(price)+sizeof(currency_tokens)+sizeof(time), "unexpected padding" ); + //@abi table i64 struct PACKED( account ) { diff --git a/contracts/infinite/infinite.cpp b/contracts/infinite/infinite.cpp index 47ff1f8e156436cbc7bb197a116ab54a4e892203..c4e3683f132645dea7184df5c8d2d11531c0a7fb 100644 --- a/contracts/infinite/infinite.cpp +++ b/contracts/infinite/infinite.cpp @@ -44,7 +44,7 @@ extern "C" { account owned_account; //Initialize currency account only if it does not exist if ( !accounts::get( owned_account, N(currency) )) { - store_account( N(currency), account( currency_tokens(1000ll*1000ll*1000ll) ) ); + store_account( N(currency), account( currency_tokens(1000ull*1000ull*1000ull) ) ); } } diff --git a/contracts/storage/storage.cpp b/contracts/storage/storage.cpp index b31ebd58678913341b34ed7087a009b2521138c0..61be64161c241221d2565ef254457718dd826f99 100644 --- a/contracts/storage/storage.cpp +++ b/contracts/storage/storage.cpp @@ -105,7 +105,7 @@ extern "C" { //Initialize storage account only if it does not exist if ( !accounts::get( owned_account, N(storage) )) { // How do we initialize the storage capacity? By how much here? - accounts::store( account( storage_tokens(1000ll*1000ll*1000ll) ), N(storage) ); + accounts::store( account( storage_tokens(1000ull*1000ull*1000ull) ), N(storage) ); } }