Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
7e19d137
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,发现更多精彩内容 >>
提交
7e19d137
编写于
2月 01, 2018
作者:
K
Khaled Al-Hassanieh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added bta_index, reversed scope-code order
上级
895aac08
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
236 addition
and
220 deletion
+236
-220
contracts/eosiolib/db.h
contracts/eosiolib/db.h
+49
-49
contracts/eosiolib/db.hpp
contracts/eosiolib/db.hpp
+93
-93
contracts/eosiolib/table.hpp
contracts/eosiolib/table.hpp
+3
-3
libraries/chain/apply_context.cpp
libraries/chain/apply_context.cpp
+5
-5
libraries/chain/contracts/eosio_contract.cpp
libraries/chain/contracts/eosio_contract.cpp
+10
-10
libraries/chain/include/eosio/chain/apply_context.hpp
libraries/chain/include/eosio/chain/apply_context.hpp
+8
-8
libraries/chain/include/eosio/chain/contracts/contract_table_objects.hpp
.../include/eosio/chain/contracts/contract_table_objects.hpp
+34
-17
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+27
-28
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+1
-1
plugins/chain_plugin/chain_plugin.cpp
plugins/chain_plugin/chain_plugin.cpp
+1
-1
plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
.../chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
+5
-5
未找到文件。
contracts/eosiolib/db.h
浏览文件 @
7e19d137
此差异已折叠。
点击以展开。
contracts/eosiolib/db.hpp
浏览文件 @
7e19d137
此差异已折叠。
点击以展开。
contracts/eosiolib/table.hpp
浏览文件 @
7e19d137
...
...
@@ -12,14 +12,14 @@ namespace eosio {
{
public:
static
bool
exists
(
uint64_t
key
,
scope_name
scope
=
DefaultScope
)
{
auto
read
=
load_i64
(
scope
,
DefaultS
cope
,
TableName
,
(
char
*
)
&
key
,
sizeof
(
key
)
);
auto
read
=
load_i64
(
DefaultScope
,
s
cope
,
TableName
,
(
char
*
)
&
key
,
sizeof
(
key
)
);
return
read
>
0
;
}
static
T
get
(
uint64_t
key
,
scope_name
scope
=
DefaultScope
)
{
char
temp
[
1024
];
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
key
;
auto
read
=
load_i64
(
scope
,
DefaultS
cope
,
TableName
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
DefaultScope
,
s
cope
,
TableName
,
temp
,
sizeof
(
temp
)
);
assert
(
read
>
0
,
"key does not exist"
);
datastream
<
const
char
*>
ds
(
temp
,
read
);
...
...
@@ -32,7 +32,7 @@ namespace eosio {
char
temp
[
1024
];
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
key
;
auto
read
=
load_i64
(
scope
,
DefaultS
cope
,
TableName
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
DefaultScope
,
s
cope
,
TableName
,
temp
,
sizeof
(
temp
)
);
if
(
read
<
0
)
{
set
(
def
,
scope
);
return
def
;
...
...
libraries/chain/apply_context.cpp
浏览文件 @
7e19d137
...
...
@@ -204,22 +204,22 @@ void apply_context::cancel_deferred( uint32_t sender_id ) {
results
.
canceled_deferred
.
emplace_back
(
receiver
,
sender_id
);
}
const
contracts
::
table_id_object
*
apply_context
::
find_table
(
name
scope
,
name
cod
e
,
name
table
)
{
const
contracts
::
table_id_object
*
apply_context
::
find_table
(
name
code
,
name
scop
e
,
name
table
)
{
require_read_lock
(
code
,
scope
);
return
db
.
find
<
table_id_object
,
contracts
::
by_
scope_code_table
>
(
boost
::
make_tuple
(
scope
,
cod
e
,
table
));
return
db
.
find
<
table_id_object
,
contracts
::
by_
code_scope_table
>
(
boost
::
make_tuple
(
code
,
scop
e
,
table
));
}
const
contracts
::
table_id_object
&
apply_context
::
find_or_create_table
(
name
scope
,
name
cod
e
,
name
table
)
{
const
contracts
::
table_id_object
&
apply_context
::
find_or_create_table
(
name
code
,
name
scop
e
,
name
table
)
{
require_read_lock
(
code
,
scope
);
const
auto
*
existing_tid
=
db
.
find
<
contracts
::
table_id_object
,
contracts
::
by_
scope_code_table
>
(
boost
::
make_tuple
(
scope
,
cod
e
,
table
));
const
auto
*
existing_tid
=
db
.
find
<
contracts
::
table_id_object
,
contracts
::
by_
code_scope_table
>
(
boost
::
make_tuple
(
code
,
scop
e
,
table
));
if
(
existing_tid
!=
nullptr
)
{
return
*
existing_tid
;
}
require_write_lock
(
scope
);
return
mutable_db
.
create
<
contracts
::
table_id_object
>
([
&
](
contracts
::
table_id_object
&
t_id
){
t_id
.
scope
=
scope
;
t_id
.
code
=
code
;
t_id
.
scope
=
scope
;
t_id
.
table
=
table
;
});
}
...
...
libraries/chain/contracts/eosio_contract.cpp
浏览文件 @
7e19d137
...
...
@@ -42,18 +42,18 @@ void intialize_eosio_tokens(chainbase::database& db, const account_name& system_
}
static
void
modify_eosio_balance
(
apply_context
&
context
,
const
account_name
&
account
,
share_type
amt
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
account
,
config
::
system_account_name
,
N
(
currency
));
const
auto
&
t_id
=
context
.
find_or_create_table
(
config
::
system_account_name
,
account
,
N
(
currency
));
uint64_t
key
=
N
(
account
);
share_type
balance
=
0
;
context
.
front_record
<
key_value_index
,
by_scope_primary
>
(
t_id
,
&
key
,
(
char
*
)
&
balance
,
sizeof
(
balance
));
balance
+=
amt
;
context
.
store_record
<
key_value_object
>
(
t_id
,
&
key
,
(
const
char
*
)
&
balance
,
sizeof
(
balance
));
context
.
store_record
<
key_value_object
>
(
t_id
,
config
::
system_account_name
,
&
key
,
(
const
char
*
)
&
balance
,
sizeof
(
balance
));
}
share_type
get_eosio_balance
(
const
chainbase
::
database
&
db
,
const
account_name
&
account
)
{
const
auto
*
t_id
=
db
.
find
<
table_id_object
,
by_
scope_code_table
>
(
boost
::
make_tuple
(
account
,
config
::
system_account_name
,
N
(
currency
)));
const
auto
*
t_id
=
db
.
find
<
table_id_object
,
by_
code_scope_table
>
(
boost
::
make_tuple
(
config
::
system_account_name
,
account
,
N
(
currency
)));
if
(
!
t_id
)
{
return
share_type
(
0
);
}
...
...
@@ -568,7 +568,7 @@ static const abi_serializer& get_abi_serializer() {
}
static
optional
<
variant
>
get_pending_recovery
(
apply_context
&
context
,
account_name
account
)
{
const
auto
*
t_id
=
context
.
find_table
(
account
,
config
::
system_account_name
,
N
(
recovery
));
const
auto
*
t_id
=
context
.
find_table
(
config
::
system_account_name
,
account
,
N
(
recovery
));
if
(
t_id
)
{
uint64_t
key
=
account
;
int32_t
record_size
=
context
.
front_record
<
key_value_index
,
by_scope_primary
>
(
*
t_id
,
&
key
,
nullptr
,
0
);
...
...
@@ -589,13 +589,13 @@ static optional<variant> get_pending_recovery(apply_context& context, account_na
static
uint32_t
get_next_sender_id
(
apply_context
&
context
)
{
context
.
require_write_lock
(
config
::
eosio_auth_scope
);
const
auto
&
t_id
=
context
.
find_or_create_table
(
config
::
eosio_auth_scope
,
config
::
system_account_nam
e
,
N
(
deferred
.
seq
));
const
auto
&
t_id
=
context
.
find_or_create_table
(
config
::
system_account_name
,
config
::
eosio_auth_scop
e
,
N
(
deferred
.
seq
));
uint64_t
key
=
N
(
config
::
eosio_auth_scope
);
uint32_t
next_serial
=
0
;
context
.
front_record
<
key_value_index
,
by_scope_primary
>
(
t_id
,
&
key
,
(
char
*
)
&
next_serial
,
sizeof
(
uint32_t
));
uint32_t
result
=
next_serial
++
;
context
.
store_record
<
key_value_object
>
(
t_id
,
&
key
,
(
char
*
)
&
next_serial
,
sizeof
(
uint32_t
));
context
.
store_record
<
key_value_object
>
(
t_id
,
config
::
system_account_name
,
&
key
,
(
char
*
)
&
next_serial
,
sizeof
(
uint32_t
));
return
result
;
}
...
...
@@ -682,16 +682,16 @@ void apply_eosio_postrecovery(apply_context& context) {
context
.
execute_deferred
(
std
::
move
(
dtrx
));
const
auto
&
t_id
=
context
.
find_or_create_table
(
account
,
config
::
system_account_name
,
N
(
recovery
));
const
auto
&
t_id
=
context
.
find_or_create_table
(
config
::
system_account_name
,
account
,
N
(
recovery
));
auto
data
=
get_abi_serializer
().
variant_to_binary
(
"pending_recovery"
,
record_data
);
context
.
store_record
<
key_value_object
>
(
t_id
,
&
account
.
value
,
data
.
data
()
+
sizeof
(
uint64_t
),
data
.
size
()
-
sizeof
(
uint64_t
));
context
.
store_record
<
key_value_object
>
(
t_id
,
0
,
&
account
.
value
,
data
.
data
()
+
sizeof
(
uint64_t
),
data
.
size
()
-
sizeof
(
uint64_t
));
context
.
console_append_formatted
(
"Recovery Started for account ${account} : ${memo}
\n
"
,
mutable_variant_object
()(
"account"
,
account
)(
"memo"
,
recover_act
.
memo
));
}
static
void
remove_pending_recovery
(
apply_context
&
context
,
const
account_name
&
account
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
account
,
config
::
system_account_name
,
N
(
recovery
));
context
.
remove_record
<
key_value_object
>
(
t_id
,
&
account
.
value
);
const
auto
&
t_id
=
context
.
find_or_create_table
(
config
::
system_account_name
,
account
,
N
(
recovery
));
context
.
remove_record
<
key_value_object
>
(
t_id
,
config
::
system_account_name
,
&
account
.
value
);
}
void
apply_eosio_passrecovery
(
apply_context
&
context
)
{
...
...
libraries/chain/include/eosio/chain/apply_context.hpp
浏览文件 @
7e19d137
...
...
@@ -32,17 +32,17 @@ class apply_context {
void
cancel_deferred
(
uint32_t
sender_id
);
using
table_id_object
=
contracts
::
table_id_object
;
const
table_id_object
*
find_table
(
name
scope
,
name
cod
e
,
name
table
);
const
table_id_object
&
find_or_create_table
(
name
scope
,
name
cod
e
,
name
table
);
const
table_id_object
*
find_table
(
name
code
,
name
scop
e
,
name
table
);
const
table_id_object
&
find_or_create_table
(
name
code
,
name
scop
e
,
name
table
);
template
<
typename
ObjectType
>
int32_t
store_record
(
const
table_id_object
&
t_id
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
);
int32_t
store_record
(
const
table_id_object
&
t_id
,
const
account_name
&
bta
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
);
template
<
typename
ObjectType
>
int32_t
update_record
(
const
table_id_object
&
t_id
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
);
int32_t
update_record
(
const
table_id_object
&
t_id
,
const
account_name
&
bta
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
);
template
<
typename
ObjectType
>
int32_t
remove_record
(
const
table_id_object
&
t_id
,
const
typename
ObjectType
::
key_type
*
keys
);
int32_t
remove_record
(
const
table_id_object
&
t_id
,
const
account_name
&
bta
,
const
typename
ObjectType
::
key_type
*
keys
);
template
<
typename
IndexType
,
typename
Scope
>
int32_t
load_record
(
const
table_id_object
&
t_id
,
typename
IndexType
::
value_type
::
key_type
*
keys
,
char
*
value
,
size_t
valuelen
);
...
...
@@ -391,7 +391,7 @@ using apply_handler = std::function<void(apply_context&)>;
template
<
typename
ObjectType
>
int32_t
apply_context
::
store_record
(
const
table_id_object
&
t_id
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
)
{
int32_t
apply_context
::
store_record
(
const
table_id_object
&
t_id
,
const
account_name
&
bta
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
)
{
require_write_lock
(
t_id
.
scope
);
auto
tuple
=
impl
::
exact_tuple
<
ObjectType
>::
get
(
t_id
,
keys
);
...
...
@@ -413,7 +413,7 @@ using apply_handler = std::function<void(apply_context&)>;
}
template
<
typename
ObjectType
>
int32_t
apply_context
::
update_record
(
const
table_id_object
&
t_id
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
)
{
int32_t
apply_context
::
update_record
(
const
table_id_object
&
t_id
,
const
account_name
&
bta
,
const
typename
ObjectType
::
key_type
*
keys
,
const
char
*
value
,
size_t
valuelen
)
{
require_write_lock
(
t_id
.
scope
);
auto
tuple
=
impl
::
exact_tuple
<
ObjectType
>::
get
(
t_id
,
keys
);
...
...
@@ -434,7 +434,7 @@ using apply_handler = std::function<void(apply_context&)>;
}
template
<
typename
ObjectType
>
int32_t
apply_context
::
remove_record
(
const
table_id_object
&
t_id
,
const
typename
ObjectType
::
key_type
*
keys
)
{
int32_t
apply_context
::
remove_record
(
const
table_id_object
&
t_id
,
const
account_name
&
bta
,
const
typename
ObjectType
::
key_type
*
keys
)
{
require_write_lock
(
t_id
.
scope
);
auto
tuple
=
impl
::
exact_tuple
<
ObjectType
>::
get
(
t_id
,
keys
);
...
...
libraries/chain/include/eosio/chain/contracts/contract_table_objects.hpp
浏览文件 @
7e19d137
...
...
@@ -18,13 +18,12 @@ namespace eosio { namespace chain { namespace contracts {
OBJECT_CTOR
(
table_id_object
)
id_type
id
;
scope_name
scope
;
account_name
code
;
scope_name
scope
;
table_name
table
;
account_name
bta
;
};
struct
by_
scope_cod
e_table
;
struct
by_
code_scop
e_table
;
using
table_id_multi_index
=
chainbase
::
shared_multi_index_container
<
table_id_object
,
...
...
@@ -32,12 +31,11 @@ namespace eosio { namespace chain { namespace contracts {
ordered_unique
<
tag
<
by_id
>
,
member
<
table_id_object
,
table_id_object
::
id_type
,
&
table_id_object
::
id
>
>
,
ordered_unique
<
tag
<
by_
scope_cod
e_table
>
,
ordered_unique
<
tag
<
by_
code_scop
e_table
>
,
composite_key
<
table_id_object
,
member
<
table_id_object
,
scope_name
,
&
table_id_object
::
scope
>
,
member
<
table_id_object
,
account_name
,
&
table_id_object
::
code
>
,
member
<
table_id_object
,
table_name
,
&
table_id_object
::
tabl
e
>
,
member
<
table_id_object
,
account_name
,
&
table_id_object
::
bta
>
member
<
table_id_object
,
scope_name
,
&
table_id_object
::
scop
e
>
,
member
<
table_id_object
,
table_name
,
&
table_id_object
::
table
>
>
>
>
...
...
@@ -48,7 +46,18 @@ namespace eosio { namespace chain { namespace contracts {
struct
by_scope_primary
;
struct
by_scope_secondary
;
struct
by_scope_tertiary
;
struct
by_bta
;
template
<
typename
ObjectType
>
using
bta_index
=
ordered_unique
<
tag
<
by_bta
>
,
composite_key
<
ObjectType
,
member
<
ObjectType
,
typename
ObjectType
::
id_type
,
&
ObjectType
::
id
>
,
member
<
ObjectType
,
table_id
,
&
ObjectType
::
t_id
>
,
member
<
ObjectType
,
account_name
,
&
ObjectType
::
bta
>
>
,
composite_key_compare
<
std
::
less
<
typename
ObjectType
::
id_type
>
,
std
::
less
<
table_id
>
,
std
::
less
<
account_name
>
>
>
;
struct
key_value_object
:
public
chainbase
::
object
<
key_value_object_type
,
key_value_object
>
{
OBJECT_CTOR
(
key_value_object
,
(
value
))
...
...
@@ -58,6 +67,7 @@ namespace eosio { namespace chain { namespace contracts {
id_type
id
;
table_id
t_id
;
uint64_t
primary_key
;
account_name
bta
;
shared_string
value
;
};
...
...
@@ -71,7 +81,8 @@ namespace eosio { namespace chain { namespace contracts {
member
<
key_value_object
,
uint64_t
,
&
key_value_object
::
primary_key
>
>
,
composite_key_compare
<
std
::
less
<
table_id
>
,
std
::
less
<
uint64_t
>
>
>
>
,
bta_index
<
key_value_object
>
>
>
;
...
...
@@ -104,6 +115,7 @@ namespace eosio { namespace chain { namespace contracts {
id_type
id
;
table_id
t_id
;
shared_string
primary_key
;
account_name
bta
;
shared_string
value
;
};
...
...
@@ -117,7 +129,8 @@ namespace eosio { namespace chain { namespace contracts {
const_mem_fun
<
keystr_value_object
,
const
char
*
,
&
keystr_value_object
::
data
>
>
,
composite_key_compare
<
std
::
less
<
table_id
>
,
shared_string_less
>
>
>
,
bta_index
<
keystr_value_object
>
>
>
;
...
...
@@ -131,6 +144,7 @@ namespace eosio { namespace chain { namespace contracts {
table_id
t_id
;
uint128_t
primary_key
;
uint128_t
secondary_key
;
account_name
bta
;
shared_string
value
;
};
...
...
@@ -153,7 +167,8 @@ namespace eosio { namespace chain { namespace contracts {
member
<
key128x128_value_object
,
typename
key128x128_value_object
::
id_type
,
&
key128x128_value_object
::
id
>
>
,
composite_key_compare
<
std
::
less
<
table_id
>
,
std
::
less
<
uint128_t
>
,
std
::
less
<
typename
key128x128_value_object
::
id_type
>
>
>
>
,
bta_index
<
key128x128_value_object
>
>
>
;
...
...
@@ -168,6 +183,7 @@ namespace eosio { namespace chain { namespace contracts {
uint64_t
primary_key
;
uint64_t
secondary_key
;
uint64_t
tertiary_key
;
account_name
bta
;
shared_string
value
;
};
...
...
@@ -199,7 +215,8 @@ namespace eosio { namespace chain { namespace contracts {
member
<
key64x64x64_value_object
,
typename
key64x64x64_value_object
::
id_type
,
&
key64x64x64_value_object
::
id
>
>
,
composite_key_compare
<
std
::
less
<
table_id
>
,
std
::
less
<
uint64_t
>
,
std
::
less
<
typename
key64x64x64_value_object
::
id_type
>
>
>
>
,
bta_index
<
key64x64x64_value_object
>
>
>
;
...
...
@@ -212,8 +229,8 @@ CHAINBASE_SET_INDEX_TYPE(eosio::chain::contracts::keystr_value_object, eosio::ch
CHAINBASE_SET_INDEX_TYPE
(
eosio
::
chain
::
contracts
::
key128x128_value_object
,
eosio
::
chain
::
contracts
::
key128x128_value_index
)
CHAINBASE_SET_INDEX_TYPE
(
eosio
::
chain
::
contracts
::
key64x64x64_value_object
,
eosio
::
chain
::
contracts
::
key64x64x64_value_index
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
table_id_object
,
(
id
)(
scope
)(
cod
e
)(
table
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key_value_object
,
(
id
)(
t_id
)(
primary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
keystr_value_object
,
(
id
)(
t_id
)(
primary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key128x128_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key64x64x64_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
tertiary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
table_id_object
,
(
id
)(
code
)(
scop
e
)(
table
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key_value_object
,
(
id
)(
t_id
)(
primary_key
)(
bta
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
keystr_value_object
,
(
id
)(
t_id
)(
primary_key
)(
bta
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key128x128_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
bta
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key64x64x64_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
tertiary_key
)(
bta
)(
value
)
)
libraries/chain/wasm_interface.cpp
浏览文件 @
7e19d137
...
...
@@ -543,36 +543,35 @@ class db_api : public context_aware_api {
using
KeyType
=
typename
ObjectType
::
key_type
;
static
constexpr
int
KeyCount
=
ObjectType
::
number_of_keys
;
using
KeyArrayType
=
KeyType
[
KeyCount
];
using
ContextMethodType
=
int
(
apply_context
::*
)(
const
table_id_object
&
,
const
KeyType
*
,
const
char
*
,
size_t
);
using
ContextMethodType
=
int
(
apply_context
::*
)(
const
table_id_object
&
,
const
account_name
&
,
const
KeyType
*
,
const
char
*
,
size_t
);
private:
int
call
(
ContextMethodType
method
,
const
scope_name
&
scope
,
const
name
&
table
,
array_ptr
<
const
char
>
data
,
size_t
data_len
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
scope
,
context
.
receiver
,
table
);
int
call
(
ContextMethodType
method
,
const
scope_name
&
scope
,
const
name
&
table
,
a
ccount_name
bta
,
a
rray_ptr
<
const
char
>
data
,
size_t
data_len
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
context
.
receiver
,
scope
,
table
);
FC_ASSERT
(
data_len
>=
KeyCount
*
sizeof
(
KeyType
),
"Data is not long enough to contain keys"
);
const
KeyType
*
keys
=
reinterpret_cast
<
const
KeyType
*>
((
const
char
*
)
data
);
const
char
*
record_data
=
((
const
char
*
)
data
)
+
sizeof
(
KeyArrayType
);
size_t
record_len
=
data_len
-
sizeof
(
KeyArrayType
);
return
(
context
.
*
(
method
))(
t_id
,
keys
,
record_data
,
record_len
)
+
sizeof
(
KeyArrayType
);
return
(
context
.
*
(
method
))(
t_id
,
bta
,
keys
,
record_data
,
record_len
)
+
sizeof
(
KeyArrayType
);
}
public:
using
context_aware_api
::
context_aware_api
;
int
store
(
const
scope_name
&
scope
,
const
name
&
table
,
const
scope
_name
&
bta
,
array_ptr
<
const
char
>
data
,
size_t
data_len
)
{
auto
res
=
call
(
&
apply_context
::
store_record
<
ObjectType
>
,
scope
,
table
,
data
,
data_len
);
int
store
(
const
scope_name
&
scope
,
const
name
&
table
,
const
account
_name
&
bta
,
array_ptr
<
const
char
>
data
,
size_t
data_len
)
{
auto
res
=
call
(
&
apply_context
::
store_record
<
ObjectType
>
,
scope
,
table
,
bta
,
data
,
data_len
);
//ilog("STORE [${scope},${code},${table}] => ${res} :: ${HEX}", ("scope",scope)("code",context.receiver)("table",table)("res",res)("HEX", fc::to_hex(data, data_len)));
return
res
;
}
int
update
(
const
scope_name
&
scope
,
const
name
&
table
,
const
scope
_name
&
bta
,
array_ptr
<
const
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
update_record
<
ObjectType
>
,
scope
,
table
,
data
,
data_len
);
int
update
(
const
scope_name
&
scope
,
const
name
&
table
,
const
account
_name
&
bta
,
array_ptr
<
const
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
update_record
<
ObjectType
>
,
scope
,
table
,
bta
,
data
,
data_len
);
}
int
remove
(
const
scope_name
&
scope
,
const
name
&
table
,
const
scope
_name
&
bta
,
const
KeyArrayType
&
keys
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
scope
,
context
.
receiver
,
table
);
return
context
.
remove_record
<
ObjectType
>
(
t_id
,
keys
);
int
remove
(
const
scope_name
&
scope
,
const
name
&
table
,
const
account
_name
&
bta
,
const
KeyArrayType
&
keys
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
context
.
receiver
,
scope
,
table
);
return
context
.
remove_record
<
ObjectType
>
(
t_id
,
bta
,
keys
);
}
};
...
...
@@ -584,8 +583,8 @@ class db_index_api : public context_aware_api {
using
ContextMethodType
=
int
(
apply_context
::*
)(
const
table_id_object
&
,
KeyType
*
,
char
*
,
size_t
);
int
call
(
ContextMethodType
method
,
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
maybe_t_id
=
context
.
find_table
(
scope
,
context
.
receiver
,
table
);
int
call
(
ContextMethodType
method
,
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
maybe_t_id
=
context
.
find_table
(
context
.
receiver
,
scope
,
table
);
if
(
maybe_t_id
==
nullptr
)
{
return
-
1
;
}
...
...
@@ -607,34 +606,34 @@ class db_index_api : public context_aware_api {
public:
using
context_aware_api
::
context_aware_api
;
int
load
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
res
=
call
(
&
apply_context
::
load_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
load
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
res
=
call
(
&
apply_context
::
load_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
//ilog("LOAD [${scope},${code},${table}] => ${res} :: ${HEX}", ("scope",scope)("code",code)("table",table)("res",res)("HEX", fc::to_hex(data, data_len)));
return
res
;
}
int
front
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
front_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
front
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
front_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
}
int
back
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
back_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
back
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
back_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
}
int
next
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
next_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
next
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
next_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
}
int
previous
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
previous_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
previous
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
previous_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
}
int
lower_bound
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
lower_bound_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
lower_bound
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
lower_bound_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
}
int
upper_bound
(
const
scope_name
&
scope
,
const
account_name
&
cod
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
upper_bound_record
<
IndexType
,
Scope
>
,
scope
,
cod
e
,
table
,
data
,
data_len
);
int
upper_bound
(
const
account_name
&
code
,
const
scope_name
&
scop
e
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
upper_bound_record
<
IndexType
,
Scope
>
,
code
,
scop
e
,
table
,
data
,
data_len
);
}
};
...
...
libraries/testing/tester.cpp
浏览文件 @
7e19d137
...
...
@@ -255,7 +255,7 @@ namespace eosio { namespace testing {
const
asset_symbol
&
symbol
,
const
account_name
&
account
)
const
{
const
auto
&
db
=
control
->
get_database
();
const
auto
*
tbl
=
db
.
find
<
contracts
::
table_id_object
,
contracts
::
by_
scope_code_table
>
(
boost
::
make_tuple
(
account
,
code
,
N
(
account
)));
const
auto
*
tbl
=
db
.
find
<
contracts
::
table_id_object
,
contracts
::
by_
code_scope_table
>
(
boost
::
make_tuple
(
code
,
account
,
N
(
account
)));
share_type
result
=
0
;
// the balance is implied to be 0 if either the table or row does not exist
...
...
plugins/chain_plugin/chain_plugin.cpp
浏览文件 @
7e19d137
...
...
@@ -333,7 +333,7 @@ read_only::get_table_rows_result read_only::get_table_rows( const read_only::get
vector
<
asset
>
read_only
::
get_currency_balance
(
const
read_only
::
get_currency_balance_params
&
p
)
const
{
vector
<
asset
>
results
;
walk_table
<
contracts
::
key_value_index
,
contracts
::
by_scope_primary
>
(
p
.
account
,
p
.
code
,
N
(
account
),
[
&
](
const
contracts
::
key_value_object
&
obj
){
walk_table
<
contracts
::
key_value_index
,
contracts
::
by_scope_primary
>
(
p
.
code
,
p
.
account
,
N
(
account
),
[
&
](
const
contracts
::
key_value_object
&
obj
){
share_type
balance
;
fc
::
datastream
<
const
char
*>
ds
(
obj
.
value
.
data
(),
obj
.
value
.
size
());
fc
::
raw
::
unpack
(
ds
,
balance
);
...
...
plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
浏览文件 @
7e19d137
...
...
@@ -164,8 +164,8 @@ public:
struct
get_table_rows_params
{
bool
json
=
false
;
name
scope
;
name
code
;
name
scope
;
name
table
;
// string table_type;
string
table_key
;
...
...
@@ -230,10 +230,10 @@ public:
}
template
<
typename
IndexType
,
typename
Scope
,
typename
Function
>
void
walk_table
(
const
name
&
scope
,
const
name
&
cod
e
,
const
name
&
table
,
Function
f
)
const
void
walk_table
(
const
name
&
code
,
const
name
&
scop
e
,
const
name
&
table
,
Function
f
)
const
{
const
auto
&
d
=
db
.
get_database
();
const
auto
*
t_id
=
d
.
find
<
chain
::
contracts
::
table_id_object
,
chain
::
contracts
::
by_
scope_code_table
>
(
boost
::
make_tuple
(
scope
,
cod
e
,
table
));
const
auto
*
t_id
=
d
.
find
<
chain
::
contracts
::
table_id_object
,
chain
::
contracts
::
by_
code_scope_table
>
(
boost
::
make_tuple
(
code
,
scop
e
,
table
));
if
(
t_id
!=
nullptr
)
{
const
auto
&
idx
=
d
.
get_index
<
IndexType
,
Scope
>
();
decltype
(
t_id
->
id
)
next_tid
(
t_id
->
id
.
_id
+
1
);
...
...
@@ -255,7 +255,7 @@ public:
abi_serializer
abis
;
abis
.
set_abi
(
abi
);
const
auto
*
t_id
=
d
.
find
<
chain
::
contracts
::
table_id_object
,
chain
::
contracts
::
by_
scope_code_table
>
(
boost
::
make_tuple
(
p
.
scope
,
p
.
cod
e
,
p
.
table
));
const
auto
*
t_id
=
d
.
find
<
chain
::
contracts
::
table_id_object
,
chain
::
contracts
::
by_
code_scope_table
>
(
boost
::
make_tuple
(
p
.
code
,
p
.
scop
e
,
p
.
table
));
if
(
t_id
!=
nullptr
)
{
const
auto
&
idx
=
d
.
get_index
<
IndexType
,
Scope
>
();
decltype
(
t_id
->
id
)
next_tid
(
t_id
->
id
.
_id
+
1
);
...
...
@@ -376,7 +376,7 @@ 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
)(
scope
)(
cod
e
)(
table
)(
table_key
)(
lower_bound
)(
upper_bound
)(
limit
)
)
FC_REFLECT
(
eosio
::
chain_apis
::
read_only
::
get_table_rows_params
,
(
json
)(
code
)(
scop
e
)(
table
)(
table_key
)(
lower_bound
)(
upper_bound
)(
limit
)
)
FC_REFLECT
(
eosio
::
chain_apis
::
read_only
::
get_table_rows_result
,
(
rows
)(
more
)
);
FC_REFLECT
(
eosio
::
chain_apis
::
read_only
::
get_currency_balance_params
,
(
code
)(
account
)(
symbol
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录