Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
e6a5ee2c
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,发现更多精彩内容 >>
提交
e6a5ee2c
编写于
1月 17, 2018
作者:
D
Daniel Larimer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Progress on currency contract
上级
48e0889f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
15 deletion
+40
-15
contracts/eoslib/generic_currency.hpp
contracts/eoslib/generic_currency.hpp
+12
-10
contracts/eoslib/singleton.hpp
contracts/eoslib/singleton.hpp
+5
-5
libraries/chain/apply_context.cpp
libraries/chain/apply_context.cpp
+1
-0
libraries/testing/include/eosio/testing/tester.hpp
libraries/testing/include/eosio/testing/tester.hpp
+4
-0
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+18
-0
未找到文件。
contracts/eoslib/generic_currency.hpp
浏览文件 @
e6a5ee2c
#pragma once
#include <eoslib/singleton.hpp>
#include <eoslib/table.hpp>
#include <eoslib/token.hpp>
#include <eoslib/asset.hpp>
#include <eoslib/dispatcher.hpp>
...
...
@@ -72,28 +73,30 @@ namespace eosio {
};
struct
account
{
uint64_t
symbol
=
token_type
::
symbol
;
token_type
balance
;
template
<
typename
DataStream
>
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
account
&
t
){
return
ds
<<
t
.
balance
;
return
ds
<<
t
.
symbol
<<
t
.
balance
;
}
template
<
typename
DataStream
>
friend
DataStream
&
operator
>>
(
DataStream
&
ds
,
account
&
t
){
return
ds
>>
t
.
balance
;
return
ds
>>
t
.
symbol
>>
t
.
balance
;
}
};
struct
currency_stats
{
uint64_t
symbol
=
token_type
::
symbol
;
token_type
supply
;
template
<
typename
DataStream
>
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
currency_stats
&
t
){
return
ds
<<
t
.
supply
;
return
ds
<<
t
.
s
ymbol
<<
t
.
s
upply
;
}
template
<
typename
DataStream
>
friend
DataStream
&
operator
>>
(
DataStream
&
ds
,
currency_stats
&
t
){
return
ds
>>
t
.
supply
;
return
ds
>>
t
.
s
ymbol
>>
t
.
s
upply
;
}
};
...
...
@@ -101,22 +104,21 @@ namespace eosio {
* Each user stores their balance in the singleton table under the
* scope of their account name.
*/
typedef
singleton
<
code
,
accounts_table_name
,
account
>
accounts
;
typedef
singleton
<
code
,
stats_table_name
,
currency_stats
>
stats
;
typedef
table64
<
code
,
accounts_table_name
,
account
>
accounts
;
typedef
table64
<
code
,
stats_table_name
,
currency_stats
>
stats
;
static
token_type
get_balance
(
account_name
owner
)
{
return
accounts
::
get_or_create
(
owner
).
balance
;
return
accounts
::
get_or_create
(
token_type
::
symbol
,
owner
).
balance
;
}
static
void
set_balance
(
account_name
owner
,
token_type
balance
)
{
accounts
::
set
(
account
{
balance
},
owner
);
accounts
::
set
(
account
{
token_type
::
symbol
,
balance
},
owner
);
}
static
void
on
(
const
issue
&
act
)
{
require_auth
(
code
);
auto
s
=
stats
::
get_or_create
();
auto
s
=
stats
::
get_or_create
(
token_type
::
symbol
);
s
.
supply
+=
act
.
quantity
;
stats
::
set
(
s
);
...
...
contracts/eoslib/singleton.hpp
浏览文件 @
e6a5ee2c
...
...
@@ -15,18 +15,18 @@ namespace eosio {
class
singleton
{
public:
static
const
uint64_t
singleton_table_name
=
N
(
singleton
);
//
static const uint64_t singleton_table_name = N(singleton);
static
bool
exists
(
scope_name
scope
=
Code
)
{
uint64_t
key
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Code
,
singleton_table_name
,
(
char
*
)
&
key
,
sizeof
(
key
)
);
auto
read
=
load_i64
(
scope
,
Code
,
key
,
(
char
*
)
&
key
,
sizeof
(
key
)
);
return
read
>
0
;
}
static
T
get
(
scope_name
scope
=
Code
)
{
char
temp
[
1024
+
8
];
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Code
,
singleton_table_n
ame
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
scope
,
Code
,
SingletonN
ame
,
temp
,
sizeof
(
temp
)
);
assert
(
read
>
0
,
"singleton does not exist"
);
datastream
<
const
char
*>
ds
(
temp
+
sizeof
(
SingletonName
),
read
);
...
...
@@ -40,7 +40,7 @@ namespace eosio {
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Code
,
singleton_table_n
ame
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
scope
,
Code
,
SingletonN
ame
,
temp
,
sizeof
(
temp
)
);
if
(
read
<
0
)
{
set
(
def
,
scope
);
return
def
;
...
...
@@ -62,7 +62,7 @@ namespace eosio {
ds
<<
SingletonName
;
ds
<<
value
;
store_i64
(
scope
,
singleton_table_n
ame
,
buf
,
sizeof
(
buf
)
);
store_i64
(
scope
,
SingletonN
ame
,
buf
,
sizeof
(
buf
)
);
}
};
...
...
libraries/chain/apply_context.cpp
浏览文件 @
e6a5ee2c
...
...
@@ -85,6 +85,7 @@ void apply_context::exec_one()
}
}
std
::
cerr
<<
_pending_console_output
.
str
();
results
.
applied_actions
.
emplace_back
(
action_trace
{
receiver
,
act
,
_pending_console_output
.
str
(),
0
,
0
,
move
(
data_access
)});
_pending_console_output
=
std
::
ostringstream
();
_read_locks
.
clear
();
...
...
libraries/testing/include/eosio/testing/tester.hpp
浏览文件 @
e6a5ee2c
...
...
@@ -56,6 +56,10 @@ namespace eosio { namespace testing {
share_type
get_balance
(
const
account_name
&
account
)
const
;
share_type
get_currency_balance
(
account_name
contract
,
uint64_t
symbol
,
const
account_name
&
account
)
const
;
private:
fc
::
temp_directory
tempdir
;
chain_controller
::
controller_config
cfg
;
...
...
libraries/testing/tester.cpp
浏览文件 @
e6a5ee2c
...
...
@@ -247,5 +247,23 @@ namespace eosio { namespace testing {
return
contracts
::
get_eosio_balance
(
db
,
account
);
}
/**
* Reads balance as stored by generic_currency contract
*/
share_type
tester
::
get_currency_balance
(
account_name
code
,
uint64_t
symbol
,
const
account_name
&
account
)
const
{
/*
const auto& db = control->get_database();
const auto& tbl = db.get<table_id_object, contracts::by_scope_code_table>(boost::make_tuple(account, code, N(account)));
const auto& obj = db.get<key_value_object, contracts::by_scope_primary>( boost::make_tuple( tbl.id, symbol ) );
datastream<const char*> ds( obj.value.data(), obj.value.size() );
share_type result;
fc::raw::unpack( ds, result );
*/
return
0
;
//result;
}
}
}
/// eosio::test
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录