Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
3d061601
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,发现更多精彩内容 >>
未验证
提交
3d061601
编写于
2月 12, 2018
作者:
K
Kevin Heifner
提交者:
GitHub
2月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1368 from wanderingbort/feature/abi-serializer-for-blocks
explode the results of get_block
上级
5cdd69c7
16221ede
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
39 deletion
+58
-39
libraries/chain/contracts/chain_initializer.cpp
libraries/chain/contracts/chain_initializer.cpp
+1
-1
libraries/chain/include/eosio/chain/contracts/abi_serializer.hpp
...es/chain/include/eosio/chain/contracts/abi_serializer.hpp
+6
-2
plugins/chain_plugin/chain_plugin.cpp
plugins/chain_plugin/chain_plugin.cpp
+43
-20
plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
.../chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
+8
-16
未找到文件。
libraries/chain/contracts/chain_initializer.cpp
浏览文件 @
3d061601
...
...
@@ -184,7 +184,7 @@ void chain_initializer::prepare_database( chain_controller& chain,
a
.
privileged
=
true
;
if
(
name
==
config
::
system_account_name
)
{
a
.
set_abi
(
eos_contract_abi
());
a
.
set_abi
(
abi_def
());
}
});
const
auto
&
owner
=
db
.
create
<
permission_object
>
([
&
](
permission_object
&
p
)
{
...
...
libraries/chain/include/eosio/chain/contracts/abi_serializer.hpp
浏览文件 @
3d061601
...
...
@@ -5,6 +5,7 @@
#pragma once
#include <eosio/chain/contracts/types.hpp>
#include <eosio/chain/transaction.hpp>
#include <eosio/chain/block.hpp>
#include <fc/variant_object.hpp>
...
...
@@ -74,7 +75,7 @@ struct abi_serializer {
template
<
typename
Vec
>
static
bool
to_abi
(
account_name
account
,
const
Vec
&
abi_vec
,
abi_def
&
abi
)
{
if
(
!
is_empty_abi
(
abi_vec
)
)
{
/// 4 == packsize of empty Abi
if
(
!
is_empty_abi
(
abi_vec
)
||
account
==
eosio
::
chain
::
config
::
system_account_name
)
{
/// 4 == packsize of empty Abi
fc
::
datastream
<
const
char
*>
ds
(
abi_vec
.
data
(),
abi_vec
.
size
()
);
fc
::
raw
::
unpack
(
ds
,
abi
);
append_system_abi
(
account
,
abi
);
...
...
@@ -99,7 +100,10 @@ namespace impl {
std
::
is_same
<
T
,
packed_transaction
>::
value
||
std
::
is_same
<
T
,
action
>::
value
||
std
::
is_same
<
T
,
transaction_trace
>::
value
||
std
::
is_same
<
T
,
action_trace
>::
value
;
std
::
is_same
<
T
,
action_trace
>::
value
||
std
::
is_same
<
T
,
shard_summary
>::
value
||
std
::
is_same
<
T
,
region_summary
>::
value
||
std
::
is_base_of
<
signed_block_summary
,
T
>::
value
;
}
/**
...
...
plugins/chain_plugin/chain_plugin.cpp
浏览文件 @
3d061601
...
...
@@ -358,18 +358,52 @@ fc::variant read_only::get_currency_stats( const read_only::get_currency_stats_p
return
results
;
}
read_only
::
get_block_results
read_only
::
get_block
(
const
read_only
::
get_block_params
&
params
)
const
{
try
{
if
(
auto
block
=
db
.
fetch_block_by_id
(
fc
::
json
::
from_string
(
params
.
block_num_or_id
).
as
<
block_id_type
>
()))
return
*
block
;
}
catch
(
fc
::
bad_cast_exception
)
{
/* do nothing */
}
template
<
typename
Api
>
struct
resolver_factory
{
static
auto
make
(
const
Api
*
api
)
{
return
[
api
](
const
account_name
&
name
)
->
optional
<
abi_serializer
>
{
const
auto
*
accnt
=
api
->
db
.
get_database
().
template
find
<
account_object
,
by_name
>(
name
);
if
(
accnt
!=
nullptr
)
{
abi_def
abi
;
if
(
abi_serializer
::
to_abi
(
accnt
->
name
,
accnt
->
abi
,
abi
))
{
return
abi_serializer
(
abi
);
}
}
return
optional
<
abi_serializer
>
();
};
}
};
template
<
typename
Api
>
auto
make_resolver
(
const
Api
*
api
)
{
return
resolver_factory
<
Api
>::
make
(
api
);
}
fc
::
variant
read_only
::
get_block
(
const
read_only
::
get_block_params
&
params
)
const
{
optional
<
signed_block
>
block
;
try
{
if
(
auto
block
=
db
.
fetch_block_by_number
(
fc
::
to_uint64
(
params
.
block_num_or_id
)))
return
*
block
;
block
=
db
.
fetch_block_by_id
(
fc
::
json
::
from_string
(
params
.
block_num_or_id
).
as
<
block_id_type
>
());
if
(
!
block
)
{
block
=
db
.
fetch_block_by_number
(
fc
::
to_uint64
(
params
.
block_num_or_id
));
}
}
catch
(
fc
::
bad_cast_exception
)
{
/* do nothing */
}
FC_THROW_EXCEPTION
(
unknown_block_exception
,
if
(
!
block
)
FC_THROW_EXCEPTION
(
unknown_block_exception
,
"Could not find block: ${block}"
,
(
"block"
,
params
.
block_num_or_id
));
fc
::
variant
pretty_output
;
abi_serializer
::
to_variant
(
*
block
,
pretty_output
,
make_resolver
(
this
));
return
fc
::
mutable_variant_object
(
pretty_output
.
get_object
())
(
"id"
,
block
->
id
())
(
"block_num"
,
block
->
block_num
())
(
"ref_block_prefix"
,
block
->
id
().
_hash
[
1
]);
}
read_write
::
push_block_results
read_write
::
push_block
(
const
read_write
::
push_block_params
&
params
)
{
...
...
@@ -379,18 +413,7 @@ read_write::push_block_results read_write::push_block(const read_write::push_blo
read_write
::
push_transaction_results
read_write
::
push_transaction
(
const
read_write
::
push_transaction_params
&
params
)
{
packed_transaction
pretty_input
;
auto
resolver
=
[
&
,
this
](
const
account_name
&
name
)
->
optional
<
abi_serializer
>
{
const
auto
*
accnt
=
db
.
get_database
().
find
<
account_object
,
by_name
>
(
name
);
if
(
accnt
!=
nullptr
)
{
abi_def
abi
;
if
(
abi_serializer
::
to_abi
(
accnt
->
name
,
accnt
->
abi
,
abi
))
{
return
abi_serializer
(
abi
);
}
}
return
optional
<
abi_serializer
>
();
};
auto
resolver
=
make_resolver
(
this
);
abi_serializer
::
from_variant
(
params
,
pretty_input
,
resolver
);
auto
result
=
db
.
push_transaction
(
pretty_input
,
skip_flags
);
#warning TODO: get transaction results asynchronously
...
...
plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
浏览文件 @
3d061601
...
...
@@ -41,6 +41,9 @@ struct permission {
authority
required_auth
;
};
template
<
typename
>
struct
resolver_factory
;
class
read_only
{
const
chain_controller
&
db
;
...
...
@@ -143,20 +146,7 @@ public:
string
block_num_or_id
;
};
struct
get_block_results
:
public
chain
::
signed_block
{
get_block_results
(
const
chain
::
signed_block
&
b
)
:
signed_block
(
b
),
id
(
b
.
id
()),
block_num
(
b
.
block_num
()),
ref_block_prefix
(
id
.
_hash
[
1
]
)
{}
chain
::
block_id_type
id
;
uint32_t
block_num
=
0
;
uint32_t
ref_block_prefix
=
0
;
};
get_block_results
get_block
(
const
get_block_params
&
params
)
const
;
fc
::
variant
get_block
(
const
get_block_params
&
params
)
const
;
struct
get_table_rows_params
{
bool
json
=
false
;
...
...
@@ -292,7 +282,8 @@ public:
}
return
result
;
}
friend
struct
resolver_factory
<
read_only
>
;
};
class
read_write
{
...
...
@@ -316,6 +307,8 @@ public:
using
push_transactions_params
=
vector
<
push_transaction_params
>
;
using
push_transactions_results
=
vector
<
push_transaction_results
>
;
push_transactions_results
push_transactions
(
const
push_transactions_params
&
params
);
friend
resolver_factory
<
read_write
>
;
};
}
// namespace chain_apis
...
...
@@ -365,7 +358,6 @@ FC_REFLECT(eosio::chain_apis::read_only::get_info_results,
(
recent_slots
)(
participation_rate
))
FC_REFLECT
(
eosio
::
chain_apis
::
read_only
::
get_block_params
,
(
block_num_or_id
))
FC_REFLECT_DERIVED
(
eosio
::
chain_apis
::
read_only
::
get_block_results
,
(
eosio
::
chain
::
signed_block
),
(
id
)(
block_num
)(
ref_block_prefix
)
);
FC_REFLECT
(
eosio
::
chain_apis
::
read_write
::
push_transaction_results
,
(
transaction_id
)(
processed
)
)
FC_REFLECT
(
eosio
::
chain_apis
::
read_only
::
get_table_rows_params
,
(
json
)(
code
)(
scope
)(
table
)(
table_key
)(
lower_bound
)(
upper_bound
)(
limit
)
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录