Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
784f1b59
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,发现更多精彩内容 >>
提交
784f1b59
编写于
8月 22, 2017
作者:
K
Kevin Heifner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added comments to wallet_manager
上级
c7786893
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
82 addition
and
20 deletion
+82
-20
plugins/wallet_api_plugin/include/eos/wallet_api_plugin/wallet_api_plugin.hpp
...lugin/include/eos/wallet_api_plugin/wallet_api_plugin.hpp
+18
-12
plugins/wallet_api_plugin/wallet_api_plugin.cpp
plugins/wallet_api_plugin/wallet_api_plugin.cpp
+5
-1
plugins/wallet_plugin/include/eos/wallet_plugin/wallet_manager.hpp
...allet_plugin/include/eos/wallet_plugin/wallet_manager.hpp
+52
-3
plugins/wallet_plugin/include/eos/wallet_plugin/wallet_plugin.hpp
...wallet_plugin/include/eos/wallet_plugin/wallet_plugin.hpp
+3
-1
plugins/wallet_plugin/wallet_manager.cpp
plugins/wallet_plugin/wallet_manager.cpp
+3
-2
tests/tests/wallet_tests.cpp
tests/tests/wallet_tests.cpp
+1
-1
未找到文件。
plugins/wallet_api_plugin/include/eos/wallet_api_plugin/wallet_api_plugin.hpp
浏览文件 @
784f1b59
#pragma once
#include <eos/wallet_plugin/wallet_plugin.hpp>
#include <eos/http_plugin/http_plugin.hpp>
...
...
@@ -6,20 +7,25 @@
namespace
eos
{
using
namespace
appbase
;
using
namespace
appbase
;
class
wallet_api_plugin
:
public
plugin
<
wallet_api_plugin
>
{
public:
APPBASE_PLUGIN_REQUIRES
((
wallet_plugin
)
(
http_plugin
))
class
wallet_api_plugin
:
public
plugin
<
wallet_api_plugin
>
{
public:
APPBASE_PLUGIN_REQUIRES
((
wallet_plugin
)(
http_plugin
))
wallet_api_plugin
()
=
default
;
wallet_api_plugin
(
const
wallet_api_plugin
&
)
=
delete
;
wallet_api_plugin
(
wallet_api_plugin
&&
)
=
delete
;
wallet_api_plugin
&
operator
=
(
const
wallet_api_plugin
&
)
=
delete
;
wallet_api_plugin
&
operator
=
(
wallet_api_plugin
&&
)
=
delete
;
virtual
~
wallet_api_plugin
()
override
=
default
;
wallet_api_plugin
()
=
default
;
virtual
~
wallet_api_plugin
()
=
default
;
virtual
void
set_program_options
(
options_description
&
,
options_description
&
)
override
{}
void
plugin_initialize
(
const
variables_map
&
)
{}
void
plugin_startup
();
void
plugin_shutdown
()
{}
virtual
void
set_program_options
(
options_description
&
cli
,
options_description
&
cfg
)
override
{}
void
plugin_initialize
(
const
variables_map
&
vm
)
{}
void
plugin_startup
();
void
plugin_shutdown
()
{}
private:
};
private:
};
}
plugins/wallet_api_plugin/wallet_api_plugin.cpp
浏览文件 @
784f1b59
...
...
@@ -37,6 +37,10 @@ using namespace eos;
#define INVOKE_R_R(api_handle, call_name, in_param) \
auto result = api_handle.call_name(fc::json::from_string(body).as<in_param>());
#define INVOKE_R_R_R(api_handle, call_name, in_param0, in_param1) \
const auto& vs = fc::json::json::from_string(body).as<fc::variants>(); \
auto result = api_handle.call_name(vs.at(0).as<in_param0>(), vs.at(1).as<in_param1>());
#define INVOKE_R_V(api_handle, call_name) \
auto result = api_handle.call_name();
...
...
@@ -61,7 +65,7 @@ void wallet_api_plugin::plugin_startup() {
app
().
get_plugin
<
http_plugin
>
().
add_api
({
CALL
(
wallet
,
wallet_mgr
,
sign_transaction
,
INVOKE_R_R
(
wallet_mgr
,
sign_transaction
,
chain
::
SignedTransaction
)),
INVOKE_R_R
_R
(
wallet_mgr
,
sign_transaction
,
chain
::
SignedTransaction
,
chain
::
chain_id_type
)),
CALL
(
wallet
,
wallet_mgr
,
create
,
INVOKE_R_R
(
wallet_mgr
,
create
,
std
::
string
)),
CALL
(
wallet
,
wallet_mgr
,
open
,
...
...
plugins/wallet_plugin/include/eos/wallet_plugin/wallet_manager.hpp
浏览文件 @
784f1b59
...
...
@@ -8,24 +8,73 @@ namespace fc { class variant; }
namespace
eos
{
namespace
wallet
{
/// Provides associate of wallet name to wallet and manages the interaction with each wallet.
///
/// The name of the wallet is also used as part of the file name by wallet_api. See wallet_manager#create.
class
wallet_manager
{
public:
wallet_manager
()
=
default
;
wallet_manager
(
const
wallet_manager
&
)
=
delete
;
wallet_manager
(
wallet_manager
&&
)
=
delete
;
wallet_manager
&
operator
=
(
const
wallet_manager
&
)
=
delete
;
wallet_manager
&
operator
=
(
wallet_manager
&&
)
=
delete
;
~
wallet_manager
()
=
default
;
/// Set the path for location of wallet files.
/// @param p path to override default ./ location of wallet files.
void
set_dir
(
const
boost
::
filesystem
::
path
&
p
)
{
dir
=
p
;
}
chain
::
SignedTransaction
sign_transaction
(
const
chain
::
SignedTransaction
&
txn
)
const
;
/// Sign transaction with all the keys from all the unlocked wallets.
/// @param txn the transaction to sign.
/// @param id the chain_id to sign transaction with.
/// @return txn signed
/// @throws fc::exception if no unlocked wallets
chain
::
SignedTransaction
sign_transaction
(
const
chain
::
SignedTransaction
&
txn
,
const
chain
::
chain_id_type
&
id
)
const
;
/// Create a new wallet.
/// A new wallet is created in file dir/{name}.wallet see wallet_manager#set_dir.
/// The new wallet is unlocked after creation.
/// @param name of the wallet and name of the file without ext .wallet.
/// @return Plaintext password that is needed to unlock wallet. Caller is responsible for saving password otherwise
/// they will not be able to unlock their wallet. Note user supplied passwords are not supported.
/// @throws fc::exception if wallet with name already exists (or filename already exists)
std
::
string
create
(
const
std
::
string
&
name
);
/// Open an existing wallet file dir/{name}.wallet.
/// Note this does not unlock the wallet, see wallet_manager#unlock.
/// @param name of the wallet file (minus ext .wallet) to open.
/// @throws fc::exception if unable to find/open the wallet file.
void
open
(
const
std
::
string
&
name
);
/// @return A list of wallet names with " *" appended if the wallet is unlocked.
std
::
vector
<
std
::
string
>
list_wallets
()
const
;
/// @return A list of unlocked wallet names and their private keys.
/// Wallet name entry followed by private key entries.
std
::
vector
<
std
::
string
>
list_keys
()
const
;
/// Locks all the unlocked wallets.
void
lock_all
();
/// Lock the specified wallet.
/// No-op if wallet already locked.
/// @param name the name of the wallet to lock.
/// @throws fc::exception if wallet with name not found.
void
lock
(
const
std
::
string
&
name
);
/// Unlock the specified wallet.
/// The wallet remains unlocked until wallet_manager#lock is called or program exit.
/// @param name the name of the wallet to lock.
/// @param password the plaintext password returned from wallet_manager#create.
/// @throws fc::exception if wallet not found or invalid password.
void
unlock
(
const
std
::
string
&
name
,
const
std
::
string
&
password
);
/// Import private key into specified wallet.
/// Imports a WIF Private Key into specified wallet.
/// Wallet must be opened and unlocked.
/// @param name the name of the wallet to import into.
/// @param wif_key the WIF Private Key to import, e.g. 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
/// @throws fc::exception if wallet not found or locked.
void
import_key
(
const
std
::
string
&
name
,
const
std
::
string
&
wif_key
);
private:
...
...
@@ -33,7 +82,7 @@ private:
boost
::
filesystem
::
path
dir
=
"."
;
};
}
}
}
// namespace wallet
}
// namespace eos
plugins/wallet_plugin/include/eos/wallet_plugin/wallet_plugin.hpp
浏览文件 @
784f1b59
...
...
@@ -22,7 +22,9 @@ public:
wallet_plugin
();
wallet_plugin
(
const
wallet_plugin
&
)
=
delete
;
wallet_plugin
(
wallet_plugin
&&
)
=
delete
;
virtual
~
wallet_plugin
()
=
default
;
wallet_plugin
&
operator
=
(
const
wallet_plugin
&
)
=
delete
;
wallet_plugin
&
operator
=
(
wallet_plugin
&&
)
=
delete
;
virtual
~
wallet_plugin
()
override
=
default
;
virtual
void
set_program_options
(
options_description
&
cli
,
options_description
&
cfg
)
override
;
void
plugin_initialize
(
const
variables_map
&
options
);
...
...
plugins/wallet_plugin/wallet_manager.cpp
浏览文件 @
784f1b59
...
...
@@ -110,7 +110,8 @@ void wallet_manager::import_key(const std::string& name, const std::string& wif_
w
->
import_key
(
wif_key
);
}
chain
::
SignedTransaction
wallet_manager
::
sign_transaction
(
const
chain
::
SignedTransaction
&
txn
)
const
{
chain
::
SignedTransaction
wallet_manager
::
sign_transaction
(
const
chain
::
SignedTransaction
&
txn
,
const
chain
::
chain_id_type
&
id
)
const
{
chain
::
SignedTransaction
stxn
(
txn
);
size_t
num_sigs
=
0
;
...
...
@@ -123,7 +124,7 @@ chain::SignedTransaction wallet_manager::sign_transaction(const chain::SignedTra
if
(
!
key
)
{
FC_THROW
(
"Invalid private key in wallet ${w}"
,
(
"w"
,
name
));
}
stxn
.
sign
(
*
key
,
chain
::
chain_id_type
{}
);
stxn
.
sign
(
*
key
,
id
);
++
num_sigs
;
}
}
...
...
tests/tests/wallet_tests.cpp
浏览文件 @
784f1b59
...
...
@@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(wallet_manager_test)
trx
.
scope
=
{
sender
,
recipient
};
trx
.
emplaceMessage
(
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
sender
,
"active"
}},
"transfer"
,
types
::
transfer
{
sender
,
recipient
,
amount
});
trx
=
wm
.
sign_transaction
(
trx
);
trx
=
wm
.
sign_transaction
(
trx
,
chain_id_type
{}
);
const
auto
&
pks
=
trx
.
get_signature_keys
(
chain_id_type
{});
BOOST_CHECK_EQUAL
(
3
,
pks
.
size
());
fc
::
optional
<
fc
::
ecc
::
private_key
>
optional_private_key
=
utilities
::
wif_to_key
(
key1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录