Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
3d8fc22c
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,发现更多精彩内容 >>
提交
3d8fc22c
编写于
4月 27, 2017
作者:
N
Nathan Hourt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ref #15: Implement CreateAccount
上级
76148312
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
90 addition
and
7 deletion
+90
-7
libraries/chain/database.cpp
libraries/chain/database.cpp
+1
-0
libraries/chain/include/eos/chain/account_object.hpp
libraries/chain/include/eos/chain/account_object.hpp
+21
-5
libraries/chain/include/eos/chain/authority.hpp
libraries/chain/include/eos/chain/authority.hpp
+20
-1
plugins/native_system_contract_plugin/native_system_contract_plugin.cpp
..._system_contract_plugin/native_system_contract_plugin.cpp
+48
-1
未找到文件。
libraries/chain/database.cpp
浏览文件 @
3d8fc22c
...
...
@@ -738,6 +738,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
a
.
name
=
"sys"
;
});
register_message_type
(
"sys"
,
"Transfer"
);
register_message_type
(
"sys"
,
"CreateAccount"
);
// Create initial accounts
for
(
const
auto
&
acct
:
genesis_state
.
initial_accounts
)
{
...
...
libraries/chain/include/eos/chain/account_object.hpp
浏览文件 @
3d8fc22c
...
...
@@ -29,11 +29,28 @@
namespace
eos
{
namespace
chain
{
class
shared_authority
{
struct
shared_authority
{
shared_authority
(
chainbase
::
allocator
<
char
>
alloc
)
:
accounts
(
alloc
),
keys
(
alloc
)
{}
shared_authority
&
operator
=
(
const
Authority
&
a
)
{
threshold
=
a
.
threshold
;
accounts
=
decltype
(
accounts
)(
a
.
accounts
.
begin
(),
a
.
accounts
.
end
(),
accounts
.
get_allocator
());
keys
=
decltype
(
keys
)(
a
.
keys
.
begin
(),
a
.
keys
.
end
(),
keys
.
get_allocator
());
return
*
this
;
}
shared_authority
&
operator
=
(
Authority
&&
a
)
{
threshold
=
a
.
threshold
;
accounts
.
reserve
(
a
.
accounts
.
size
());
for
(
auto
&
p
:
a
.
accounts
)
accounts
.
emplace_back
(
std
::
move
(
p
));
keys
.
reserve
(
a
.
keys
.
size
());
for
(
auto
&
p
:
a
.
keys
)
keys
.
emplace_back
(
std
::
move
(
p
));
return
*
this
;
}
uint32_t
threshold
=
0
;
shared_vector
<
PermissionLevel
>
accounts
;
shared_vector
<
KeyPermission
>
keys
;
...
...
@@ -41,10 +58,10 @@ namespace eos { namespace chain {
class
account_object
:
public
chainbase
::
object
<
account_object_type
,
account_object
>
{
OBJECT_CTOR
(
account_object
,
(
name
)
)
OBJECT_CTOR
(
account_object
)
id_type
id
;
shared_string
name
;
account_name
name
;
uint64_t
balance
=
0
;
uint64_t
votes
=
0
;
uint64_t
converting_votes
=
0
;
...
...
@@ -56,8 +73,7 @@ namespace eos { namespace chain {
account_object
,
indexed_by
<
ordered_unique
<
tag
<
by_id
>
,
member
<
account_object
,
account_object
::
id_type
,
&
account_object
::
id
>>
,
ordered_unique
<
tag
<
by_name
>
,
member
<
account_object
,
shared_string
,
&
account_object
::
name
>
,
chainbase
::
strcmp_less
>
ordered_unique
<
tag
<
by_name
>
,
member
<
account_object
,
account_name
,
&
account_object
::
name
>>
>
>
;
...
...
libraries/chain/include/eos/chain/authority.hpp
浏览文件 @
3d8fc22c
...
...
@@ -19,8 +19,27 @@ namespace eos { namespace chain {
uint32_t
threshold
=
0
;
vector
<
PermissionLevel
>
accounts
;
vector
<
KeyPermission
>
keys
;
bool
validate
()
const
{
if
(
threshold
==
0
)
return
false
;
uint32_t
score
=
0
;
for
(
const
auto
&
p
:
accounts
)
score
+=
p
.
weight
;
for
(
const
auto
&
p
:
keys
)
score
+=
p
.
weight
;
return
score
>=
threshold
;
}
set
<
account_name
>
referenced_accounts
()
const
{
set
<
account_name
>
results
;
std
::
transform
(
accounts
.
begin
(),
accounts
.
end
(),
std
::
inserter
(
results
,
results
.
begin
()),
[](
const
PermissionLevel
&
p
)
{
return
p
.
account
;
});
return
results
;
}
};
}
}
// eos::chain
FC_REFLECT
(
eos
::
chain
::
Authority
,
(
threshold
)(
accounts
)(
keys
)
)
FC_REFLECT
(
eos
::
chain
::
PermissionLevel
,
(
account
)(
level
)(
weight
))
FC_REFLECT
(
eos
::
chain
::
KeyPermission
,
(
key
)(
weight
))
FC_REFLECT
(
eos
::
chain
::
Authority
,
(
threshold
)(
accounts
)(
keys
))
plugins/native_system_contract_plugin/native_system_contract_plugin.cpp
浏览文件 @
3d8fc22c
...
...
@@ -14,7 +14,7 @@ void Transfer_validate_preconditions(chain::precondition_validate_context& conte
const
auto
&
db
=
context
.
db
;
auto
transfer
=
context
.
msg
.
as
<
Transfer
>
();
const
auto
&
from
=
db
.
get_account
(
context
.
msg
.
sender
);
EOS_ASSERT
(
from
.
balance
>
transfer
.
amount
,
message_precondition_exception
,
"Insufficient Funds"
,
EOS_ASSERT
(
from
.
balance
>
=
transfer
.
amount
,
message_precondition_exception
,
"Insufficient Funds"
,
(
"from.balance"
,
from
.
balance
)(
"transfer.amount"
,
transfer
.
amount
));
}
void
Transfer_apply
(
chain
::
apply_context
&
context
)
{
...
...
@@ -30,6 +30,52 @@ void Transfer_apply(chain::apply_context& context) {
});
}
void
CreateAccount_validate
(
chain
::
message_validate_context
&
context
)
{
auto
create
=
context
.
msg
.
as
<
CreateAccount
>
();
EOS_ASSERT
(
create
.
owner
.
validate
(),
message_validate_exception
,
"Invalid owner authority"
);
EOS_ASSERT
(
create
.
active
.
validate
(),
message_validate_exception
,
"Invalid active authority"
);
}
void
CreateAccount_validate_preconditions
(
chain
::
precondition_validate_context
&
context
)
{
const
auto
&
db
=
context
.
db
;
auto
create
=
context
.
msg
.
as
<
CreateAccount
>
();
auto
existing_account
=
db
.
find
<
account_object
,
by_name
>
(
create
.
new_account
);
EOS_ASSERT
(
existing_account
==
nullptr
,
message_precondition_exception
,
"Cannot create account named ${name}, as that name is already taken"
,
(
"name"
,
create
.
new_account
));
const
auto
&
creator
=
db
.
get_account
(
context
.
msg
.
sender
);
EOS_ASSERT
(
creator
.
balance
>=
create
.
initial_balance
,
message_precondition_exception
,
"Insufficient Funds"
);
for
(
const
auto
&
account
:
create
.
owner
.
referenced_accounts
())
db
.
get_account
(
account
);
for
(
const
auto
&
account
:
create
.
active
.
referenced_accounts
())
db
.
get_account
(
account
);
}
void
CreateAccount_apply
(
chain
::
apply_context
&
context
)
{
auto
&
db
=
context
.
mutable_db
;
auto
create
=
context
.
msg
.
as
<
CreateAccount
>
();
db
.
modify
(
db
.
get_account
(
context
.
msg
.
sender
),
[
&
create
](
account_object
&
a
)
{
a
.
balance
-=
create
.
initial_balance
;
});
const
auto
&
new_account
=
db
.
create
<
account_object
>
([
&
create
](
account_object
&
a
)
{
a
.
name
=
create
.
new_account
;
a
.
balance
=
create
.
initial_balance
;
});
const
auto
&
owner_permission
=
db
.
create
<
permission_object
>
([
&
create
,
&
new_account
](
permission_object
&
p
)
{
p
.
name
=
"owner"
;
p
.
parent
=
0
;
p
.
owner
=
new_account
.
id
;
p
.
auth
=
std
::
move
(
create
.
owner
);
});
db
.
create
<
permission_object
>
([
&
create
,
&
owner_permission
](
permission_object
&
p
)
{
p
.
name
=
"active"
;
p
.
parent
=
owner_permission
.
id
;
p
.
owner
=
owner_permission
.
owner
;
p
.
auth
=
std
::
move
(
create
.
active
);
});
}
class
native_system_contract_plugin_impl
{
public:
native_system_contract_plugin_impl
(
database
&
db
)
...
...
@@ -61,5 +107,6 @@ void native_system_contract_plugin::install(database& db) {
db.set_apply_handler("sys", "sys", #name, &name ## _apply)
SET_HANDLERS
(
Transfer
);
SET_HANDLERS
(
CreateAccount
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录