Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
3dbd4c0a
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,发现更多精彩内容 >>
提交
3dbd4c0a
编写于
2月 01, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
trustrow replaced with account_name (flag 'trusted' was redundant)
上级
86b0873d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
56 deletion
+18
-56
contracts/identity/identity.abi
contracts/identity/identity.abi
+1
-8
contracts/identity/identity.hpp
contracts/identity/identity.hpp
+7
-28
tests/wasm_tests/identity_tests.cpp
tests/wasm_tests/identity_tests.cpp
+10
-20
未找到文件。
contracts/identity/identity.abi
浏览文件 @
3dbd4c0a
...
...
@@ -62,13 +62,6 @@
{"name":"identity", "type":"uint64"},
{"name":"creator", "type":"account_name"}
]
},{
"name": "trustrow",
"base": "",
"fields": [
{"name":"account", "type":"account_name"},
{"name":"trusted", "type":"uint8"}
]
},{
"name": "accountrow",
"base": "",
...
...
@@ -111,7 +104,7 @@
"key_types": [ "uint64" ]
},{
"name": "trust",
"type": "
trustrow
",
"type": "
account_name
",
"index_type": "i64",
"key_names" : [ "account" ],
"key_types": [ "account_name" ]
...
...
contracts/identity/identity.hpp
浏览文件 @
3dbd4c0a
...
...
@@ -181,24 +181,10 @@ namespace identity {
}
};
struct
trustrow
{
account_name
account
;
uint8_t
trusted
;
template
<
typename
DataStream
>
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
trustrow
&
r
){
return
ds
<<
r
.
account
<<
r
.
trusted
;
}
template
<
typename
DataStream
>
friend
DataStream
&
operator
>>
(
DataStream
&
ds
,
trustrow
&
r
){
return
ds
>>
r
.
account
>>
r
.
trusted
;
}
};
typedef
table_i64i64i64
<
code
,
N
(
certs
),
certrow
>
certs_table
;
typedef
table64
<
code
,
N
(
ident
),
identrow
>
idents_table
;
typedef
singleton
<
code
,
N
(
account
),
identity_name
>
accounts_table
;
typedef
table64
<
code
,
N
(
trust
),
trustrow
>
trust_table
;
typedef
table_i64i64i64
<
code
,
N
(
certs
),
certrow
>
certs_table
;
typedef
table64
<
code
,
N
(
ident
),
identrow
>
idents_table
;
typedef
singleton
<
code
,
N
(
account
),
identity_name
>
accounts_table
;
typedef
table64
<
code
,
N
(
trust
),
account_name
>
trust_table
;
static
identity_name
get_claimed_identity
(
account_name
acnt
)
{
return
accounts_table
::
get_or_default
(
acnt
,
0
);
...
...
@@ -278,10 +264,7 @@ namespace identity {
}
static
bool
is_trusted_by
(
account_name
trusted
,
account_name
by
)
{
trustrow
def
;
def
.
trusted
=
0
;
trustrow
row
=
trust_table
::
get_or_default
(
trusted
,
by
,
def
);
return
row
.
trusted
;
return
trust_table
::
exists
(
trusted
,
by
);
}
static
bool
is_trusted
(
account_name
acnt
)
{
...
...
@@ -303,13 +286,9 @@ namespace identity {
require_recipient
(
t
.
trusting
);
if
(
t
.
trust
!=
0
)
{
trustrow
row
{
.
account
=
t
.
trusting
,
.
trusted
=
t
.
trust
};
trust_table
::
set
(
row
,
t
.
trustor
);
trust_table
::
set
(
t
.
trusting
,
t
.
trustor
);
}
else
{
trustrow
row
{
.
account
=
t
.
trusting
,
.
trusted
=
t
.
trust
};
trust_table
::
remove
(
row
.
account
,
t
.
trustor
);
trust_table
::
remove
(
t
.
trusting
,
t
.
trustor
);
}
}
...
...
tests/wasm_tests/identity_tests.cpp
浏览文件 @
3dbd4c0a
...
...
@@ -221,23 +221,17 @@ public:
return success();
}
fc::variant get_trustrow
(const string& trustor, const string& trusting) {
bool get_trust
(const string& trustor, const string& trusting) {
const auto& db = control->get_database();
const auto* t_id = db.find<table_id_object, by_scope_code_table>(boost::make_tuple(string_to_name(trustor.c_str()), N(identity), N(trust)));
if (!t_id) {
return f
c::variant(nullptr)
;
return f
alse
;
}
uint64_t tng = string_to_name(trusting.c_str());
const auto& idx = db.get_index<key_value_index, by_scope_primary>();
auto itr = idx.lower_bound(boost::make_tuple(t_id->id, tng));
if ( itr != idx.end() && itr->t_id == t_id->id && tng == itr->primary_key ) {
vector<char> data;
read_only::copy_row(*itr, data);
return abi_ser.binary_to_variant("trustrow", data);
} else {
return fc::variant(nullptr);
}
return ( itr != idx.end() && itr->t_id == t_id->id && tng == itr->primary_key ); //true if found
}
public:
...
...
@@ -392,18 +386,14 @@ BOOST_FIXTURE_TEST_CASE( certify_decertify, identity_tester ) try {
BOOST_FIXTURE_TEST_CASE( trust_untrust, identity_tester ) try {
BOOST_REQUIRE_EQUAL(success(), settrust("bob", "alice", 1));
auto obj = get_trustrow("bob", "alice");
BOOST_REQUIRE_EQUAL(true, obj.is_object());
BOOST_REQUIRE_EQUAL( "alice", obj["account"].as_string() );
BOOST_REQUIRE_EQUAL( 1, obj["trusted"].as_uint64() );
BOOST_REQUIRE_EQUAL(true, get_trust("bob", "alice"));
obj = get_trustrow("alice", "bob");
BOOST_REQUIRE_EQUAL(
true, obj.is_null(
));
//relation of trust in opposite direction should not exist
BOOST_REQUIRE_EQUAL(
false, get_trust("alice", "bob"
));
//remove trust
BOOST_REQUIRE_EQUAL(success(), settrust("bob", "alice", 0));
obj = get_trustrow("bob", "alice");
BOOST_REQUIRE_EQUAL(true, obj.is_null());
BOOST_REQUIRE_EQUAL(false, get_trust("bob", "alice"));
} FC_LOG_AND_RETHROW() //trust_untrust
...
...
@@ -548,7 +538,7 @@ BOOST_FIXTURE_TEST_CASE( owner_certified_by_trusted_account, identity_tester ) t
//block producer trusts bob
BOOST_REQUIRE_EQUAL(success(), settrust("initb", "bob", 1));
BOOST_REQUIRE_EQUAL(true, get_trust
row("initb", "bob").is_object(
));
BOOST_REQUIRE_EQUAL(true, get_trust
("initb", "bob"
));
// bob (trusted account) certifies alice's ownership, it should result in trusted certification
BOOST_REQUIRE_EQUAL(success(), certify("bob", identity_val, vector<fc::variant>{ mutable_variant_object()
...
...
@@ -567,7 +557,7 @@ BOOST_FIXTURE_TEST_CASE( owner_certified_by_trusted_account, identity_tester ) t
//block producer stops trusting bob
BOOST_REQUIRE_EQUAL(success(), settrust("initb", "bob", 0));
BOOST_REQUIRE_EQUAL(
true, get_trustrow("initb", "bob").is_null(
));
BOOST_REQUIRE_EQUAL(
false, get_trust("initb", "bob"
));
//certification made by bob is still flaged as trusted
BOOST_REQUIRE_EQUAL( true, get_certrow(identity_val, "owner", 1, "bob").is_object() );
...
...
@@ -606,7 +596,7 @@ BOOST_FIXTURE_TEST_CASE( owner_certification_becomes_trusted, identity_tester )
//block producer trusts bob
BOOST_REQUIRE_EQUAL(success(), settrust("initb", "bob", 1));
BOOST_REQUIRE_EQUAL(true, get_trust
row("initb", "bob").is_object(
));
BOOST_REQUIRE_EQUAL(true, get_trust
("initb", "bob"
));
//old certification made by bob still shouldn't be flaged as trusted
BOOST_REQUIRE_EQUAL( true, get_certrow(identity_val, "owner", 0, "bob").is_object() );
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录