Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
767410ea
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,发现更多精彩内容 >>
提交
767410ea
编写于
10月 14, 2017
作者:
K
Kevin Heifner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
-Add updateAt to Account, createAt to all documents #172
上级
46387eba
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
9 deletion
+39
-9
plugins/db_plugin/db_plugin.cpp
plugins/db_plugin/db_plugin.cpp
+39
-9
未找到文件。
plugins/db_plugin/db_plugin.cpp
浏览文件 @
767410ea
...
...
@@ -271,12 +271,15 @@ void db_plugin_impl::_process_irreversible_block(const signed_block& block)
}
}
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
block_doc
<<
"block_num"
<<
b_int32
{
static_cast
<
int32_t
>
(
block
.
block_num
())}
<<
"block_id"
<<
block_id_str
<<
"prev_block_id"
<<
prev_block_id_str
<<
"timestamp"
<<
b_date
{
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
block
.
timestamp
.
sec_since_epoch
()}}}
<<
"transaction_merkle_root"
<<
block
.
transaction_merkle_root
.
str
()
<<
"producer_account_id"
<<
block
.
producer
.
toString
();
<<
"producer_account_id"
<<
block
.
producer
.
toString
()
<<
"createdAt"
<<
b_date
{
now
};
if
(
!
blocks
.
insert_one
(
block_doc
.
view
()))
{
elog
(
"Failed to insert block ${bid}"
,
(
"bid"
,
block_id
));
}
...
...
@@ -338,6 +341,7 @@ void db_plugin_impl::_process_irreversible_block(const signed_block& block)
msg_doc
.
append
(
kvp
(
"handler_account_name"
,
msg
.
code
.
toString
()));
msg_doc
.
append
(
kvp
(
"type"
,
msg
.
type
.
toString
()));
add_data
(
msg_doc
,
accounts
,
msg
);
msg_doc
.
append
(
kvp
(
"createdAt"
,
b_date
{
now
}));
mongocxx
::
model
::
insert_one
insert_msg
{
msg_doc
.
view
()};
bulk_msgs
.
append
(
insert_msg
);
...
...
@@ -360,7 +364,9 @@ void db_plugin_impl::_process_irreversible_block(const signed_block& block)
}
}
auto
complete_doc
=
trx_doc
<<
stream
::
close_array
<<
stream
::
finalize
;
auto
complete_doc
=
trx_doc
<<
stream
::
close_array
<<
"createdAt"
<<
b_date
{
now
}
<<
stream
::
finalize
;
mongocxx
::
model
::
insert_one
insert_op
{
complete_doc
.
view
()};
transactions_in_block
=
true
;
bulk_trans
.
append
(
insert_op
);
...
...
@@ -392,6 +398,7 @@ void db_plugin_impl::update_account(const chain::Message& msg) {
return
;
if
(
msg
.
type
==
transfer
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
auto
transfer
=
msg
.
as
<
types
::
transfer
>
();
auto
from_name
=
transfer
.
from
.
toString
();
auto
to_name
=
transfer
.
to
.
toString
();
...
...
@@ -404,14 +411,19 @@ void db_plugin_impl::update_account(const chain::Message& msg) {
to_balance
+=
eos
::
types
::
ShareType
(
transfer
.
amount
);
document
update_from
{};
update_from
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
from_balance
.
toString
()
<<
close_document
;
update_from
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
from_balance
.
toString
()
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
document
update_to
{};
update_to
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
to_balance
.
toString
()
<<
close_document
;
update_to
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
to_balance
.
toString
()
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
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
.
type
==
newaccount
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
auto
newaccount
=
msg
.
as
<
types
::
newaccount
>
();
// find creator to update its balance
...
...
@@ -436,12 +448,15 @@ void db_plugin_impl::update_account(const chain::Message& msg) {
doc
<<
"name"
<<
newaccount
.
name
.
toString
()
<<
"eos_balance"
<<
Asset
().
toString
()
<<
"staked_balance"
<<
newaccount
.
deposit
.
toString
()
<<
"unstaked_balance"
<<
Asset
().
toString
();
<<
"unstaking_balance"
<<
Asset
().
toString
()
<<
"createdAt"
<<
b_date
{
now
}
<<
"updatedAt"
<<
b_date
{
now
};
if
(
!
accounts
.
insert_one
(
doc
.
view
()))
{
elog
(
"Failed to insert account ${n}"
,
(
"n"
,
newaccount
.
name
));
}
}
else
if
(
msg
.
type
==
lock
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
auto
lock
=
msg
.
as
<
types
::
lock
>
();
auto
from_account
=
find_account
(
accounts
,
lock
.
from
);
auto
to_account
=
find_account
(
accounts
,
lock
.
to
);
...
...
@@ -452,14 +467,19 @@ void db_plugin_impl::update_account(const chain::Message& msg) {
to_balance
+=
lock
.
amount
;
document
update_from
{};
update_from
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
from_balance
.
toString
()
<<
close_document
;
update_from
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
from_balance
.
toString
()
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
document
update_to
{};
update_to
<<
"$set"
<<
open_document
<<
"stacked_balance"
<<
to_balance
.
toString
()
<<
close_document
;
update_to
<<
"$set"
<<
open_document
<<
"stacked_balance"
<<
to_balance
.
toString
()
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
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
.
type
==
unlock
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
auto
unlock
=
msg
.
as
<
types
::
unlock
>
();
auto
from_account
=
find_account
(
accounts
,
unlock
.
account
);
...
...
@@ -474,11 +494,13 @@ void db_plugin_impl::update_account(const chain::Message& msg) {
update_from
<<
"$set"
<<
open_document
<<
"staked_balance"
<<
stack_balance
.
toString
()
<<
"unstacking_balance"
<<
unstack_balance
.
toString
()
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
accounts
.
update_one
(
document
{}
<<
"_id"
<<
from_account
.
view
()[
"_id"
].
get_oid
()
<<
finalize
,
update_from
.
view
());
}
else
if
(
msg
.
type
==
claim
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
auto
claim
=
msg
.
as
<
types
::
claim
>
();
auto
from_account
=
find_account
(
accounts
,
claim
.
account
);
...
...
@@ -491,17 +513,20 @@ void db_plugin_impl::update_account(const chain::Message& msg) {
update_from
<<
"$set"
<<
open_document
<<
"eos_balance"
<<
balance
.
toString
()
<<
"unstacking_balance"
<<
unstack_balance
.
toString
()
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
accounts
.
update_one
(
document
{}
<<
"_id"
<<
from_account
.
view
()[
"_id"
].
get_oid
()
<<
finalize
,
update_from
.
view
());
}
else
if
(
msg
.
type
==
setcode
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
auto
setcode
=
msg
.
as
<
types
::
setcode
>
();
auto
from_account
=
find_account
(
accounts
,
setcode
.
account
);
document
update_from
{};
update_from
<<
"$set"
<<
open_document
<<
"abi"
<<
bsoncxx
::
from_json
(
fc
::
json
::
to_string
(
setcode
.
abi
))
<<
"updatedAt"
<<
b_date
{
now
}
<<
close_document
;
accounts
.
update_one
(
document
{}
<<
"_id"
<<
from_account
.
view
()[
"_id"
].
get_oid
()
<<
finalize
,
update_from
.
view
());
...
...
@@ -549,6 +574,7 @@ void db_plugin_impl::wipe_database() {
}
void
db_plugin_impl
::
init
()
{
using
namespace
bsoncxx
::
types
;
// 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()
...
...
@@ -557,11 +583,15 @@ void db_plugin_impl::init() {
accounts
=
mongo_conn
[
db_name
][
accounts_col
];
// Accounts
bsoncxx
::
builder
::
stream
::
document
doc
{};
if
(
accounts
.
count
(
doc
.
view
())
==
0
)
{
auto
now
=
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
fc
::
time_point
::
now
().
sec_since_epoch
()}};
doc
<<
"name"
<<
config
::
EosContractName
.
toString
()
<<
"eos_balance"
<<
Asset
(
config
::
InitialTokenSupply
).
toString
()
<<
"staked_balance"
<<
Asset
().
toString
()
<<
"unstaked_balance"
<<
Asset
().
toString
()
<<
"abi"
<<
bsoncxx
::
from_json
(
fc
::
json
::
to_string
(
eos_abi
));
<<
"unstaking_balance"
<<
Asset
().
toString
()
<<
"abi"
<<
bsoncxx
::
from_json
(
fc
::
json
::
to_string
(
eos_abi
))
<<
"createdAt"
<<
b_date
{
now
}
<<
"updatedAt"
<<
b_date
{
now
};
if
(
!
accounts
.
insert_one
(
doc
.
view
()))
{
elog
(
"Failed to insert account ${n}"
,
(
"n"
,
config
::
EosContractName
.
toString
()));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录