Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
block_timestamp.hpp
Go to the documentation of this file.
1#pragma once
3
4#include <stdint.h>
5#include <fc/time.hpp>
6#include <fc/variant.hpp>
7#include <fc/string.hpp>
9
10namespace sysio { namespace chain {
11
17 template<uint16_t IntervalMs, uint64_t EpochMs>
19 public:
20 explicit block_timestamp( uint32_t s=0 ) :slot(s){}
21
23 set_time_point(t);
24 }
25
27 set_time_point(t);
28 }
29
30 static block_timestamp maximum() { return block_timestamp( 0xffff ); }
31 static block_timestamp min() { return block_timestamp(0); }
32
34 SYS_ASSERT( std::numeric_limits<uint32_t>::max() - slot >= 1, fc::overflow_exception, "block timestamp overflow" );
35 auto result = block_timestamp(*this);
36 result.slot += 1;
37 return result;
38 }
39
41 return (fc::time_point)(*this);
42 }
43
44 operator fc::time_point() const {
45 int64_t msec = slot * (int64_t)IntervalMs;
46 msec += EpochMs;
47 return fc::time_point(fc::milliseconds(msec));
48 }
49
50 void operator = (const fc::time_point& t ) {
51 set_time_point(t);
52 }
53
54 bool operator > ( const block_timestamp& t )const { return slot > t.slot; }
55 bool operator >=( const block_timestamp& t )const { return slot >= t.slot; }
56 bool operator < ( const block_timestamp& t )const { return slot < t.slot; }
57 bool operator <=( const block_timestamp& t )const { return slot <= t.slot; }
58 bool operator ==( const block_timestamp& t )const { return slot == t.slot; }
59 bool operator !=( const block_timestamp& t )const { return slot != t.slot; }
61
62 private:
63 void set_time_point(const fc::time_point& t) {
64 auto micro_since_epoch = t.time_since_epoch();
65 auto msec_since_epoch = micro_since_epoch.count() / 1000;
66 slot = ( msec_since_epoch - EpochMs ) / IntervalMs;
67 }
68
69 void set_time_point(const fc::time_point_sec& t) {
70 uint64_t sec_since_epoch = t.sec_since_epoch();
71 slot = (sec_since_epoch * 1000 - EpochMs) / IntervalMs;
72 }
73 }; // block_timestamp
74
76
77} }
78
79
82
83namespace fc {
84 template<uint16_t IntervalMs, uint64_t EpochMs>
88
89 template<uint16_t IntervalMs, uint64_t EpochMs>
93}
94
95#ifdef _MSC_VER
96 #pragma warning (pop)
97#endif
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
constexpr int64_t count() const
Definition time.hpp:26
constexpr uint32_t sec_since_epoch() const
Definition time.hpp:88
constexpr const microseconds & time_since_epoch() const
Definition time.hpp:52
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
T as() const
Definition variant.hpp:327
bool operator<(const block_timestamp &t) const
bool operator<=(const block_timestamp &t) const
static block_timestamp maximum()
block_timestamp next() const
bool operator>(const block_timestamp &t) const
bool operator==(const block_timestamp &t) const
block_timestamp(const fc::time_point &t)
static block_timestamp min()
fc::time_point to_time_point() const
void operator=(const fc::time_point &t)
block_timestamp(const fc::time_point_sec &t)
bool operator!=(const block_timestamp &t) const
bool operator>=(const block_timestamp &t) const
Defines exception's used by fc.
namespace sysio::chain
Definition authority.cpp:3
constexpr microseconds milliseconds(int64_t s)
Definition time.hpp:33
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
block_timestamp< config::block_interval_ms, config::block_timestamp_epoch > block_timestamp_type
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
yubihsm_pkcs11_slot * slot
char * s