Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
864c4dcc
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,发现更多精彩内容 >>
提交
864c4dcc
编写于
6月 10, 2018
作者:
D
dskvr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
document symbols
上级
7d48cd00
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
119 addition
and
8 deletion
+119
-8
contracts/eosiolib/symbol.hpp
contracts/eosiolib/symbol.hpp
+119
-8
未找到文件。
contracts/eosiolib/symbol.hpp
浏览文件 @
864c4dcc
...
...
@@ -8,6 +8,25 @@
namespace
eosio
{
/**
* @defgroup symbolapi Symbol API
* @brief Defines API for managing symbols
* @ingroup contractdev
*/
/**
* @defgroup symbolcppapi Symbol CPP API
* @brief Defines %CPP API for managing symbols
* @ingroup symbolapi
* @{
*/
/**
* Converts string to uint64_t representation of symbol
*
* @param precision - precision of symbol
* @param str - the string representation of the symbol
*/
static
constexpr
uint64_t
string_to_symbol
(
uint8_t
precision
,
const
char
*
str
)
{
uint32_t
len
=
0
;
while
(
str
[
len
]
)
++
len
;
...
...
@@ -25,10 +44,25 @@ namespace eosio {
return
result
;
}
/**
* Macro for converting string to char representation of symbol
*
* @param precision - precision of symbol
* @param str - the string representation of the symbol
*/
#define S(P,X) ::eosio::string_to_symbol(P,#X)
/**
* uint64_t representation of a symbol name
*/
typedef
uint64_t
symbol_name
;
/**
* Checks if provided symbol name is valid.
*
* @param sym - symbol name of type symbol_name
* @return true - if symbol is valid
*/
static
constexpr
bool
is_valid_symbol
(
symbol_name
sym
)
{
sym
>>=
8
;
for
(
int
i
=
0
;
i
<
7
;
++
i
)
{
...
...
@@ -46,29 +80,71 @@ namespace eosio {
return
true
;
}
static
constexpr
uint32_t
symbol_name_length
(
symbol_name
tmp
)
{
tmp
>>=
8
;
/// skip precision
/**
* Returns the character length of the provided symbol
*
* @param sym - symbol to retrieve length for (uint64_t)
* @return length - character length of the provided symbol
*/
static
constexpr
uint32_t
symbol_name_length
(
symbol_name
sym
)
{
sym
>>=
8
;
/// skip precision
uint32_t
length
=
0
;
while
(
tmp
&
0xff
&&
length
<=
7
)
{
while
(
sym
&
0xff
&&
length
<=
7
)
{
++
length
;
tmp
>>=
8
;
sym
>>=
8
;
}
return
length
;
}
/**
* \struct Stores information about a symbol
*
* @brief Stores information about a symbol
*/
struct
symbol_type
{
/**
* The symbol name
*/
symbol_name
value
;
symbol_type
()
{
}
/**
* What is the type of the symbol
*/
symbol_type
(
symbol_name
s
)
:
value
(
s
)
{
}
/**
* Is this symbol valid
*/
bool
is_valid
()
const
{
return
is_valid_symbol
(
value
);
}
/**
* This symbol's precision
*/
uint64_t
precision
()
const
{
return
value
&
0xff
;
}
/**
* Returns uint64_t representation of symbol name
*/
uint64_t
name
()
const
{
return
value
>>
8
;
}
/**
* The length of this symbol
*/
uint32_t
name_length
()
const
{
return
symbol_name_length
(
value
);
}
/**
*
*/
operator
symbol_name
()
const
{
return
value
;
}
/**
* %Print the symbol
*
* @brief %Print the symbol
*/
void
print
(
bool
show_precision
=
true
)
const
{
if
(
show_precision
){
::
eosio
::
print
(
precision
());
...
...
@@ -88,25 +164,60 @@ namespace eosio {
EOSLIB_SERIALIZE
(
symbol_type
,
(
value
)
)
};
/**
* \struct Extended asset which stores the information of the owner of the symbol
*
*/
struct
extended_symbol
:
public
symbol_type
{
extended_symbol
(
symbol_name
s
=
0
,
account_name
c
=
0
)
:
symbol_type
{
s
},
contract
(
c
){}
account_name
contract
;
/**
* The owner of the symbol
*
* @brief The owner of the symbol
*/
account_name
contract
;
extended_symbol
(
symbol_name
sym
=
0
,
account_name
acc
=
0
)
:
symbol_type
{
sym
},
contract
(
acc
){}
/**
* %Print the extended symbol
*
* @brief %Print the extended symbol
*/
void
print
()
const
{
symbol_type
::
print
();
prints
(
"@"
);
printn
(
contract
);
}
/**
* Equivalency operator. Returns true if a == b (are the same)
*
* @brief Subtraction operator
* @param a - The extended asset to be subtracted
* @param b - The extended asset used to subtract
* @return boolean - true if both provided symbols are the same
*/
friend
bool
operator
==
(
const
extended_symbol
&
a
,
const
extended_symbol
&
b
)
{
return
std
::
tie
(
a
.
value
,
a
.
contract
)
==
std
::
tie
(
b
.
value
,
b
.
contract
);
}
/**
* Inverted equivalency operator. Returns true if a != b (are different)
*
* @brief Subtraction operator
* @param a - The extended asset to be subtracted
* @param b - The extended asset used to subtract
* @return boolean - true if both provided symbols are the same
*/
friend
bool
operator
!=
(
const
extended_symbol
&
a
,
const
extended_symbol
&
b
)
{
return
std
::
tie
(
a
.
value
,
a
.
contract
)
!=
std
::
tie
(
b
.
value
,
b
.
contract
);
}
EOSLIB_SERIALIZE
(
extended_symbol
,
(
value
)(
contract
)
)
};
// }@ symbolapi
}
/// namespace eosio
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录