Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time_point::max() #47

Open
wants to merge 26 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d2e2a3e
Make sure that the buffer passed to fpconv_dtoa is large enough.
swatanabe-b1 Mar 16, 2020
a4c30cc
Merge pull request #37 from EOSIO/fpconv
swatanabe-b1 Mar 16, 2020
23fe5b0
ship_protocol
tbfleming Mar 16, 2020
b97cd75
Missing includes
tbfleming Mar 17, 2020
2c37ab5
Merge remote-tracking branch 'origin/hashname' into ship-hash
tbfleming Mar 17, 2020
273ec00
Allow non-static member functions to be reflected.
swatanabe-b1 Mar 17, 2020
6a85346
Merge pull request #39 from EOSIO/reflect-method
swatanabe-b1 Mar 18, 2020
2dfc1b0
Merge remote-tracking branch 'origin/master' into ship-hash
tbfleming Mar 18, 2020
06ad70c
Address review feedback
tbfleming Mar 18, 2020
970b869
Merge branch 'ship' into ship-hash
tbfleming Mar 18, 2020
dc3e6fb
Merge pull request #38 from EOSIO/ship
tbfleming Mar 19, 2020
a0871b4
fixed bug with implicit conversion to result<T> from T, should use ou…
bytemaster Mar 20, 2020
a84013c
when converting an object with optional<T> members to JSON, if the op…
bytemaster Mar 20, 2020
a6c94be
recurse_transaction_trace: to_bin
tbfleming Mar 20, 2020
84a6172
format_json
tbfleming Mar 26, 2020
c26f69a
Bump acorn from 5.7.3 to 5.7.4 in /test
dependabot[bot] Apr 5, 2020
d675fe0
Merge pull request #42 from EOSIO/dependabot/npm_and_yarn/test/acorn-…
jeffreyssmith2nd Apr 6, 2020
d0cdf3a
gcc fixes
spoonincode Apr 6, 2020
087eabe
Merge pull request #45 from EOSIO/gcc_fixes
spoonincode Apr 6, 2020
01c5a3f
replace abieos_headers target with a new abieos library target
spoonincode Apr 6, 2020
b6e3973
add time_point::max()
bytemaster Apr 9, 2020
1f6100f
Expose base58 api, fix checksum160 to use 20 bytes
bytemaster Apr 13, 2020
1bd99d5
Merge pull request #46 from EOSIO/new_libabieos_target
spoonincode Apr 15, 2020
79f95a1
Fix incorrect loop condition that caused utf-8 validation to swallow …
swatanabe-b1 Apr 15, 2020
002fe57
Merge pull request #48 from EOSIO/utf8-escape
bytemaster Apr 15, 2020
c6e9ec7
Merge branch 'master' into dansabieos
bytemaster Apr 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS ON)

if(NOT DEFINED SKIP_SUBMODULE_CHECK)
execute_process(COMMAND git submodule status --recursive
Expand All @@ -31,24 +31,30 @@ Please run the command 'git submodule update --init --recursive'.")
endif()
endif()

add_library(abieos MODULE src/abieos.cpp src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)
target_include_directories(abieos PRIVATE include external/outcome/single-header external/rapidjson/include external/date/include)
add_library(abieos STATIC src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)
target_include_directories(abieos PUBLIC include external/outcome/single-header external/rapidjson/include external/date/include)
set_target_properties(abieos PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_library(abieos_headers INTERFACE)
target_include_directories(abieos_headers INTERFACE include external/outcome/single-header external/date/include external/rapidjson/include)
add_library(abieos_module MODULE src/abieos.cpp)
target_link_libraries(abieos_module abieos)
set_target_properties(abieos_module PROPERTIES OUTPUT_NAME "abieos")

add_executable(test src/test.cpp src/abieos.cpp src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)
target_include_directories(test PRIVATE include external/outcome/single-header external/rapidjson/include external/date/include)
add_executable(test src/test.cpp src/abieos.cpp)
target_link_libraries(test abieos)

add_executable(template_test src/template_test.cpp src/abieos.cpp src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)
target_include_directories(template_test PRIVATE include external/outcome/single-header external/rapidjson/include external/date/include)
add_executable(template_test src/template_test.cpp src/abieos.cpp)
target_link_libraries(template_test abieos)

add_executable(key_test src/key_test.cpp src/abieos.cpp src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)
target_include_directories(key_test PRIVATE include external/outcome/single-header external/rapidjson/include external/date/include)
add_executable(key_test src/key_test.cpp src/abieos.cpp)
target_link_libraries(key_test abieos)

add_executable(reflect_test src/reflect_test.cpp)
target_include_directories(reflect_test PRIVATE include)

add_executable(test-sanitize src/test.cpp src/abieos.cpp src/abi.cpp src/crypto.cpp include/eosio/fpconv.c)

target_include_directories(test-sanitize PRIVATE include external/outcome/single-header external/rapidjson/include external/date/include)
target_link_libraries(test-sanitize -fno-omit-frame-pointer -fsanitize=address,undefined)
target_link_libraries(test-sanitize abieos -fno-omit-frame-pointer -fsanitize=address,undefined)
target_compile_options(test-sanitize PUBLIC -fno-omit-frame-pointer -fsanitize=address,undefined)

# add_executable(fuzzer src/fuzzer.cpp src/abieos.cpp)
Expand Down
1 change: 1 addition & 0 deletions include/eosio/abi.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <functional>
#include <string>
#include <map>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion include/eosio/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct asset {
/**
* The symbol name of the asset
*/
symbol symbol;
eosio::symbol symbol;

/**
* Maximum amount possible for this asset. It's capped to 2^62 - 1
Expand Down
9 changes: 7 additions & 2 deletions include/eosio/chain_conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ inline uint64_t string_to_name(const std::string& str) { return string_to_name(s
unsigned i = 0;
for (; i < str.size() && i < 12; ++i) {
uint64_t x = 0;
OUTCOME_TRY(char_to_name_digit_strict(str[i], x));
// - this is not safe in const expression OUTCOME_TRY(char_to_name_digit_strict(str[i], x));
auto r = char_to_name_digit_strict(str[i], x);
if( !r ) return stream_error::invalid_name_char;
name |= (x & 0x1f) << (64 - 5 * (i + 1));
}
if (i < str.size() && i == 12) {
uint64_t x = 0;
OUTCOME_TRY(char_to_name_digit_strict(str[i], x));
// - this is not safe in const expression OUTCOME_TRY(char_to_name_digit_strict(str[i], x));
auto r = char_to_name_digit_strict(str[i], x);
if( !r ) return stream_error::invalid_name_char;

if (x != (x & 0xf))
return stream_error::invalid_name_char13;
name |= x;
Expand Down
3 changes: 3 additions & 0 deletions include/eosio/crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,7 @@ result<void> from_json(signature& obj, S& stream) {
obj = std::move(result);
return outcome::success();
}

std::string to_base58(const char* d, size_t s );

} // namespace eosio
5 changes: 3 additions & 2 deletions include/eosio/fixed_bytes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@ class fixed_bytes {
// Everything else should be using one of the typedefs below.
template <std::size_t Size, typename Word, typename F>
void eosio_for_each_field(fixed_bytes<Size, Word>*, F&& f) {
f("value", [](auto* p) -> decltype((p->value)) { return p->value; });
f("value",
[](auto* p) -> decltype(&std::decay_t<decltype(*p)>::value) { return &std::decay_t<decltype(*p)>::value; });
}

template <std::size_t Size, typename Word>
EOSIO_COMPARE(fixed_bytes<Size, Word>);

using checksum160 = fixed_bytes<20>;
using checksum160 = fixed_bytes<20,uint32_t>;
using checksum256 = fixed_bytes<32>;
using checksum512 = fixed_bytes<64>;

Expand Down
22 changes: 20 additions & 2 deletions include/eosio/for_each_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,30 @@ namespace eosio {

template <typename T, typename F>
constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t<reflection::has_for_each_field_v<std::decay_t<T>>> {
eosio_for_each_field((std::decay_t<T>*)nullptr, [&](const char*, auto member) { f(member(&t)); });
eosio_for_each_field((std::decay_t<T>*)nullptr, [&](const char*, auto member) {
if constexpr (std::is_member_object_pointer_v<decltype(member(&t))>) {
f(t.*member(&t));
}
});
}

template <typename T, typename F>
constexpr void for_each_field(F&& f) {
eosio_for_each_field((T*)nullptr, f);
eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) {
if constexpr (std::is_member_object_pointer_v<decltype(member((T*)nullptr))>) {
f(name, [member](auto p) -> decltype((p->*member(p))) { return p->*member(p); });
}
});
}

// Calls f(#fn_name, &T::fn_name) for every reflected member function of T.
template <typename T, typename F>
constexpr void for_each_method(F&& f) {
eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) {
if constexpr (std::is_member_function_pointer_v<decltype(member((T*)nullptr))>) {
f(name, member((T*)nullptr));
}
});
}

} // namespace eosio
23 changes: 15 additions & 8 deletions include/eosio/from_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <tuple>
#include <variant>
#include <vector>
#include <string_view>

namespace eosio {

Expand Down Expand Up @@ -215,6 +216,16 @@ inline result<void> from_bin(std::string& obj, S& stream) {
return stream.read(obj.data(), obj.size());
}

template <typename S>
inline result<void> from_bin(std::string_view& obj, S& stream) {
uint32_t size;
auto r = varuint32_from_bin(size, stream);
if (!r)
return r;
obj = std::string_view(stream.get_pos(),size);
return stream.skip(size);
}

template <typename T, typename S>
result<void> from_bin(std::optional<T>& obj, S& stream) {
bool present;
Expand Down Expand Up @@ -296,10 +307,8 @@ result<void> from_bin(T& obj, S& stream) {
template <typename T, typename S>
result<T> from_bin(S& stream) {
T obj;
auto r = from_bin(obj, stream);
if (!r)
return r.error();
return obj;
OUTCOME_TRY( from_bin(obj, stream) );
return outcome::success(obj);
}

template <typename T>
Expand All @@ -311,10 +320,8 @@ result<void> convert_from_bin(T& obj, const std::vector<char>& bin) {
template <typename T>
result<T> convert_from_bin(const std::vector<char>& bin) {
T obj;
auto r = convert_from_bin(obj, bin);
if (!r)
return r.error();
return obj;
OUTCOME_TRY( convert_from_bin(obj, bin) );
return outcome::success(obj);
}

} // namespace eosio
1 change: 1 addition & 0 deletions include/eosio/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdlib>
#include <eosio/eosio_outcome.hpp>
#include <eosio/for_each_field.hpp>
#include <functional>
#include <optional>
#include <rapidjson/reader.h>
#include <vector>
Expand Down
55 changes: 55 additions & 0 deletions include/eosio/murmur.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

namespace eosio {
namespace {
inline constexpr uint64_t unaligned_load(const char* p)
{
uint64_t r = 0;
for( uint32_t i = 0; i < 8; ++i ) {
r |= p[i];
r <<= 8;
}
return r;
}

// Loads n bytes, where 1 <= n < 8.
inline constexpr uint64_t load_bytes(const char* p, int n)
{
std::uint64_t result = 0;
--n;
do
result = (result << 8) + (unsigned char)(p[n]);
while (--n >= 0);
return result;
}

inline constexpr uint64_t shift_mix(std::uint64_t v)
{ return v ^ (v >> 47);}
}

// Implementation of Murmur hash for 64-bit size_t.
inline constexpr uint64_t murmur64(const char* ptr, uint64_t len, uint64_t seed = 0xbadd00d00)
{
const uint64_t mul = (((uint64_t) 0xc6a4a793UL) << 32UL)
+ (uint64_t) 0x5bd1e995UL;
const char* const buf = ptr;

// Remove the bytes not divisible by the sizeof(uint64_t). This
// allows the main loop to process the data as 64-bit integers.
const uint64_t len_aligned = len & ~(uint64_t)0x7;
const char* const end = buf + len_aligned;
uint64_t hash = seed ^ (len * mul);
for (const char* p = buf; p != end; p += 8) {
const uint64_t data = shift_mix(unaligned_load(p) * mul) * mul;
hash ^= data;
hash *= mul;
}
if ((len & 0x7) != 0) {
const uint64_t data = load_bytes(end, len & 0x7);
hash ^= data;
hash *= mul;
}
hash = shift_mix(hash) * mul;
hash = shift_mix(hash);
return hash;
}
} // namespace eosio
18 changes: 14 additions & 4 deletions include/eosio/name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <eosio/check.hpp>
#include <eosio/operators.hpp>
#include <eosio/reflection.hpp>
#include <eosio/murmur.hpp>
#include <string>

namespace eosio {
Expand All @@ -15,7 +16,9 @@ struct name {
constexpr name() = default;
constexpr explicit name(uint64_t value) : value{ value } {}
constexpr explicit name(name::raw value) : value{ static_cast<uint64_t>(value) } {}
constexpr explicit name(std::string_view str) : value{ check(string_to_name_strict(str)) } {}
constexpr explicit name(std::string_view str) : value{ check(string_to_name_strict(str)) } { }


constexpr name(const name&) = default;

constexpr operator raw() const { return static_cast<raw>(value); }
Expand Down Expand Up @@ -137,14 +140,20 @@ struct name {
}
};

inline constexpr uint64_t hash_name( std::string_view str ) {
auto r = string_to_name_strict(str);
if( r ) return r.value();
return murmur64( str.data(), str.size() );
}

EOSIO_REFLECT(name, value);
EOSIO_COMPARE(name);

template <typename S>
result<void> from_json(name& obj, S& stream) {
OUTCOME_TRY(r, stream.get_string());
OUTCOME_TRY(value, string_to_name_strict(r));
obj = name(value);
//OUTCOME_TRY(value, string_to_name_strict(r));
obj = name(hash_name(r));
return eosio::outcome::success();
}

Expand All @@ -154,7 +163,8 @@ result<void> to_json(const name& obj, S& stream) {
}

inline namespace literals {
inline constexpr name operator""_n(const char* s, size_t) { return name{ s }; }
inline constexpr name operator""_n(const char* s, size_t) { return name( check(string_to_name_strict(s)) ); }
inline constexpr name operator""_h(const char* s, size_t) { return name( hash_name(s) ); }
} // namespace literals

} // namespace eosio
3 changes: 2 additions & 1 deletion include/eosio/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace eosio { namespace reflection {
template <typename T>
inline constexpr bool has_for_each_field_v = has_for_each_field<T>::value;

#define EOSIO_REFLECT_MEMBER(STRUCT, FIELD) f(#FIELD, [](auto p) -> decltype((p->FIELD)) { return (p->FIELD); });
#define EOSIO_REFLECT_MEMBER(STRUCT, FIELD) \
f(#FIELD, [](auto p) -> decltype(&std::decay_t<decltype(*p)>::FIELD) { return &std::decay_t<decltype(*p)>::FIELD; });

#define EOSIO_REFLECT_STRIP_BASEbase
#define EOSIO_REFLECT_BASE(STRUCT, BASE) \
Expand Down
Loading