Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
9c10e0eb
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,发现更多精彩内容 >>
提交
9c10e0eb
编写于
2月 13, 2018
作者:
K
Kevin Heifner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update for bios and noon
上级
8c5ea8fb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
26 deletion
+19
-26
plugins/mongo_db_plugin/mongo_db_plugin.cpp
plugins/mongo_db_plugin/mongo_db_plugin.cpp
+19
-26
未找到文件。
plugins/mongo_db_plugin/mongo_db_plugin.cpp
浏览文件 @
9c10e0eb
...
...
@@ -73,7 +73,6 @@ public:
void
consum_blocks
();
bool
is_scope_relevant
(
const
vector
<
account_name
>&
scope
);
void
update_account
(
const
chain
::
action
&
msg
);
static
const
account_name
newaccount
;
...
...
@@ -90,8 +89,6 @@ public:
static
const
std
::
string
accounts_col
;
};
abi_def
mongo_db_plugin_impl
::
eos_abi
;
const
account_name
mongo_db_plugin_impl
::
newaccount
=
"newaccount"
;
const
account_name
mongo_db_plugin_impl
::
transfer
=
"transfer"
;
const
account_name
mongo_db_plugin_impl
::
lock
=
"lock"
;
...
...
@@ -181,14 +178,13 @@ namespace {
{
using
bsoncxx
::
builder
::
basic
::
kvp
;
try
{
auto
from_account
=
find_account
(
accounts
,
msg
.
account
);
auto
abi
=
fc
::
json
::
from_string
(
bsoncxx
::
to_json
(
from_account
.
view
()[
"abi"
].
get_document
())).
as
<
abi_def
>
();
abi_serializer
abis
;
if
(
msg
.
account
==
chain
::
config
::
system_account_name
)
{
abis
.
set_abi
(
mongo_db_plugin_impl
::
eos_abi
);
}
else
{
auto
from_account
=
find_account
(
accounts
,
msg
.
account
);
auto
abi
=
fc
::
json
::
from_string
(
bsoncxx
::
to_json
(
from_account
.
view
()[
"abi"
].
get_document
())).
as
<
abi_def
>
();
abis
.
set_abi
(
abi
);
abi
=
chain
::
contracts
::
chain_initializer
::
eos_contract_abi
(
abi
);
}
abis
.
set_abi
(
abi
);
auto
v
=
abis
.
binary_to_variant
(
abis
.
get_action_type
(
msg
.
name
),
msg
.
data
);
auto
json
=
fc
::
json
::
to_string
(
v
);
try
{
...
...
@@ -264,15 +260,10 @@ void mongo_db_plugin_impl::_process_irreversible_block(const signed_block& block
auto
block_num
=
block
.
block_num
();
if
(
processed
==
0
)
{
if
(
startup
)
{
if
(
wipe_database_on_
startup
)
{
// verify on start we have no previous blocks
verify_no_blocks
(
blocks
);
FC_ASSERT
(
block_num
<
2
,
"Expected start of block, instead received block_num: ${bn}"
,
(
"bn"
,
block_num
));
// Currently we are creating a 'fake' block in chain_controller::initialize_chain() since initial accounts
// and producers are not written to the block log. If this is the fake block, indicate it as block_num 0.
if
(
block_num
==
1
&&
block
.
producer
==
chain
::
config
::
system_account_name
)
{
block_num
=
0
;
}
}
else
{
// verify on restart we have previous block
verify_last_block
(
blocks
,
prev_block_id_str
);
...
...
@@ -403,17 +394,22 @@ void mongo_db_plugin_impl::update_account(const chain::action& msg) {
if
(
msg
.
name
==
transfer
)
{
auto
now
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
microseconds
{
fc
::
time_point
::
now
().
time_since_epoch
().
count
()});
/* todo need to follow eosio.system transfer
auto transfer = msg.as<chain::contracts::transfer>();
auto from_name = transfer.from.to_string();
auto to_name = transfer.to.to_string();
auto from_account = find_account(accounts, transfer.from);
auto to_account = find_account(accounts, transfer.to);
abi_serializer
abis
;
auto
eosio_account
=
find_account
(
accounts
,
msg
.
account
);
auto
abi
=
fc
::
json
::
from_string
(
bsoncxx
::
to_json
(
eosio_account
.
view
()[
"abi"
].
get_document
())).
as
<
abi_def
>
();
abis
.
set_abi
(
abi
);
auto
transfer
=
abis
.
binary_to_variant
(
abis
.
get_action_type
(
msg
.
name
),
msg
.
data
);
auto
from_name
=
transfer
[
"from"
].
as
<
name
>
().
to_string
();
auto
to_name
=
transfer
[
"to"
].
as
<
name
>
().
to_string
();
auto
from_account
=
find_account
(
accounts
,
from_name
);
auto
to_account
=
find_account
(
accounts
,
to_name
);
asset
from_balance
=
asset
::
from_string
(
from_account
.
view
()[
"eos_balance"
].
get_utf8
().
value
.
to_string
());
asset
to_balance
=
asset
::
from_string
(
to_account
.
view
()[
"eos_balance"
].
get_utf8
().
value
.
to_string
());
from_balance -= asset(chain::share_type(transfer.amount));
to_balance += asset(chain::share_type(transfer.amount));
auto
asset_quantity
=
transfer
[
"quantity"
].
as
<
asset
>
();
from_balance
-=
asset_quantity
;
to_balance
+=
asset_quantity
;
document
update_from
{};
update_from
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
from_balance
.
to_string
()
...
...
@@ -426,7 +422,7 @@ void mongo_db_plugin_impl::update_account(const chain::action& msg) {
accounts
.
update_one
(
document
{}
<<
"_id"
<<
from_account
.
view
()[
"_id"
].
get_oid
()
<<
finalize
,
update_from
.
view
());
accounts
.
update_one
(
document
{}
<<
"_id"
<<
to_account
.
view
()[
"_id"
].
get_oid
()
<<
finalize
,
update_to
.
view
());
*/
}
else
if
(
msg
.
name
==
newaccount
)
{
auto
now
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
microseconds
{
fc
::
time_point
::
now
().
time_since_epoch
().
count
()});
...
...
@@ -496,8 +492,6 @@ void mongo_db_plugin_impl::init() {
// Create the native contract accounts manually; sadly, we can't run their contracts to make them create themselves
// See native_contract_chain_initializer::prepare_database()
eos_abi
=
chain
::
contracts
::
chain_initializer
::
eos_contract_abi
();
accounts
=
mongo_conn
[
db_name
][
accounts_col
];
// Accounts
bsoncxx
::
builder
::
stream
::
document
doc
{};
if
(
accounts
.
count
(
doc
.
view
())
==
0
)
{
...
...
@@ -507,7 +501,6 @@ void mongo_db_plugin_impl::init() {
<<
"eos_balance"
<<
asset
(
chain
::
config
::
initial_token_supply
).
to_string
()
<<
"staked_balance"
<<
asset
().
to_string
()
<<
"unstaking_balance"
<<
asset
().
to_string
()
<<
"abi"
<<
bsoncxx
::
from_json
(
fc
::
json
::
to_string
(
eos_abi
))
<<
"createdAt"
<<
b_date
{
now
}
<<
"updatedAt"
<<
b_date
{
now
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录