提交 3dbd4c0a 编写于 作者: A Anton Perkov

trustrow replaced with account_name (flag 'trusted' was redundant)

上级 86b0873d
......@@ -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" ]
......
......@@ -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 );
}
}
......
......@@ -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 fc::variant(nullptr);
return false;
}
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_trustrow("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_trustrow("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.
先完成此消息的编辑!
想要评论请 注册