Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
270d4c70
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
270d4c70
编写于
1月 16, 2018
作者:
V
venediktov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make token accept smaller/larger unsigned integral types for NumberType
上级
ea09b974
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
86 addition
and
13 deletion
+86
-13
contracts/currency/currency.cpp
contracts/currency/currency.cpp
+1
-1
contracts/currency/currency.hpp
contracts/currency/currency.hpp
+2
-1
contracts/eoslib/token.hpp
contracts/eoslib/token.hpp
+7
-3
contracts/eoslib/types.hpp
contracts/eoslib/types.hpp
+67
-0
contracts/exchange/exchange.cpp
contracts/exchange/exchange.cpp
+4
-4
contracts/exchange/exchange.hpp
contracts/exchange/exchange.hpp
+3
-2
contracts/infinite/infinite.cpp
contracts/infinite/infinite.cpp
+1
-1
contracts/storage/storage.cpp
contracts/storage/storage.cpp
+1
-1
未找到文件。
contracts/currency/currency.cpp
浏览文件 @
270d4c70
...
...
@@ -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
(
1000
ll
*
1000ll
*
1000
ll
)
)
);
store_account
(
N
(
currency
),
account
(
currency_tokens
(
1000
ull
*
1000ull
*
1000u
ll
)
)
);
}
}
...
...
contracts/currency/currency.hpp
浏览文件 @
270d4c70
...
...
@@ -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
...
...
contracts/eoslib/token.hpp
浏览文件 @
270d4c70
...
...
@@ -58,6 +58,8 @@ namespace eosio {
*/
template
<
typename
NumberType
,
uint64_t
currency
=
N
(
eos
)
>
struct
token
{
using
number_type
=
NumberType
;
static_assert
(
eosio
::
is_unsigned
<
NumberType
>::
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<typename T, typename = typename eosio::enable_if<eosio::is_unsigned<T>::value && eosio::is_same<T,NumberType>::value>::type>
template
<
typename
T
,
typename
=
typename
eosio
::
enable_if
<
eosio
::
is_unsigned
<
T
>
::
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
...
...
contracts/eoslib/types.hpp
浏览文件 @
270d4c70
...
...
@@ -89,4 +89,71 @@ namespace eosio {
template
<
typename
T
>
struct
remove_reference
<
const
T
&>
{
typedef
T
type
;
};
///@}
/**
* @ingroup types
* needed for universal references since we build with --nostdlib and thus std::forward<T> is not available
* with forward<Args...>(args...) we always guarantee correctness of the calling code
*/
template
<
typename
T
,
typename
U
>
constexpr
decltype
(
auto
)
forward
(
U
&&
u
)
noexcept
{
return
static_cast
<
T
&&>
(
u
);
}
template
<
class
T
>
constexpr
typename
remove_reference
<
T
>::
type
&&
move
(
T
&&
t
)
noexcept
{
return
static_cast
<
typename
remove_reference
<
decltype
(
t
)
>::
type
&&>
(
t
);
}
template
<
class
T
,
T
v
>
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
<
bool
,
true
>
;
using
false_type
=
integral_constant
<
bool
,
false
>
;
template
<
class
T
,
class
U
>
struct
is_same
:
false_type
{};
template
<
class
T
>
struct
is_same
<
T
,
T
>
:
true_type
{};
template
<
class
...
>
struct
voidify
{
using
type
=
void
;
};
template
<
class
...
Ts
>
using
void_t
=
typename
voidify
<
Ts
...
>::
type
;
template
<
class
T
,
class
=
void
>
struct
supports_arithmetic_operations
:
false_type
{};
//for no default ctor we'll need decltype(eosio::declval<T>() +-/* eosio::declval<T>())
template
<
class
T
>
struct
supports_arithmetic_operations
<
T
,
void_t
<
decltype
(
T
()
+
T
()),
decltype
(
T
()
-
T
()),
decltype
(
T
()
*
T
()),
decltype
(
T
()
/
T
())
>>
:
true_type
{};
namespace
detail
{
template
<
typename
T
,
bool
=
supports_arithmetic_operations
<
T
>
::
value
>
struct
is_unsigned
:
integral_constant
<
bool
,
T
(
0
)
<
T
(
-
1
)
>
{};
template
<
typename
T
>
struct
is_unsigned
<
T
,
false
>
:
false_type
{};
}
// namespace detail
template
<
typename
T
>
struct
is_unsigned
:
detail
::
is_unsigned
<
T
>::
type
{};
template
<
bool
B
,
class
T
=
void
>
struct
enable_if
{};
template
<
class
T
>
struct
enable_if
<
true
,
T
>
{
typedef
T
type
;
};
}
// namespace eos
contracts/exchange/exchange.cpp
浏览文件 @
270d4c70
...
...
@@ -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
(
0
u
),
"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
(
0
u
)
)
{
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
(
0
u
),
"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
(
0
u
)
)
{
buyer_account
.
open_orders
--
;
save
(
seller_account
);
save
(
buyer_account
);
...
...
contracts/exchange/exchange.hpp
浏览文件 @
270d4c70
...
...
@@ -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
)
{
...
...
contracts/infinite/infinite.cpp
浏览文件 @
270d4c70
...
...
@@ -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
(
1000
ll
*
1000ll
*
1000
ll
)
)
);
store_account
(
N
(
currency
),
account
(
currency_tokens
(
1000
ull
*
1000ull
*
1000u
ll
)
)
);
}
}
...
...
contracts/storage/storage.cpp
浏览文件 @
270d4c70
...
...
@@ -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
(
1000
ll
*
1000ll
*
1000
ll
)
),
N
(
storage
)
);
accounts
::
store
(
account
(
storage_tokens
(
1000
ull
*
1000ull
*
1000u
ll
)
),
N
(
storage
)
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录