Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
70f12c4c
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,发现更多精彩内容 >>
提交
70f12c4c
编写于
4月 02, 2018
作者:
A
arhag
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into 1755-check-signatures
上级
e47ea81e
2a514ab1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
109 addition
and
14 deletion
+109
-14
TUTORIAL.md
TUTORIAL.md
+96
-1
libraries/chain/chain_controller.cpp
libraries/chain/chain_controller.cpp
+1
-2
libraries/chain/contracts/eosio_contract.cpp
libraries/chain/contracts/eosio_contract.cpp
+1
-1
libraries/chain/include/eosio/chain/contracts/types.hpp
libraries/chain/include/eosio/chain/contracts/types.hpp
+1
-1
libraries/chain/include/eosio/chain/transaction_metadata.hpp
libraries/chain/include/eosio/chain/transaction_metadata.hpp
+2
-2
programs/nodeos/CMakeLists.txt
programs/nodeos/CMakeLists.txt
+7
-5
programs/nodeos/main.cpp
programs/nodeos/main.cpp
+1
-2
未找到文件。
TUTORIAL.md
浏览文件 @
70f12c4c
...
...
@@ -300,7 +300,7 @@ balances be derivable by the sum of the transfer actions that reference them. It
receiver of funds be notified so they can automate handling deposits and withdraws.
If you want to see the actual transaction that was broadcast you can use the
`-d -j`
options to indicate
"don't
pro
dcast" and "return transaction as json".
"don't
broa
dcast" and "return transaction as json".
```
$ cleos push action eosio.token issue '["user", "100.0000 EOS", "memo"]' -p eosio -d -j
...
...
@@ -344,6 +344,101 @@ executed transaction: 06d0a99652c11637230d08a207520bf38066b8817ef7cafaab2f0344aa
# tester <= eosio.token::transfer {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}
```
## Hello World Contract
The next step we will create our first "hello world" contract. Create a new folder called "hello" and then create
a file "hello/hello.cpp" with the following contents:
#### hello/hello.cpp
```
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
class hello : public eosio::contract {
public:
using contract::contract;
/// @abi action
void hi( account_name user ) {
print( "Hello, ", name{user} );
}
};
EOSIO_ABI( hello, (hi) )
```
Then you can compile it to web assmebly (.wast) like so:
```
$ eosiocpp -o hello.wast hello.cpp
```
Then you can generate the abi:
```
$ eosiocpp -g hello.abi hello.cpp
Generated hello.abi
```
Then we create the account and upload contract
```
$ cleos create account eosio hello.code EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
...
$ cleos set contract hello.code ../hello -p hello.code
...
```
Now we can run the contract:
```
$ cleos push action hello.code hi '["user"]' -p user
executed transaction: 4c10c1426c16b1656e802f3302677594731b380b18a44851d38e8b5275072857 244 bytes 1000 cycles
# hello.code <= hello.code::hi {"user":"user"}
>> Hello, user
```
At this time the contract allows anyone to authorize it, we could also say:
```
$ cleos push action hello.code hi '["user"]' -p tester
executed transaction: 28d92256c8ffd8b0255be324e4596b7c745f50f85722d0c4400471bc184b9a16 244 bytes 1000 cycles
# hello.code <= hello.code::hi {"user":"user"}
>> Hello, user
```
In this case tester is the one who authorized it and user is just an argument. If we want our contact to authenticate the
user we are sying "hi" to, then we need to modify the contract:
We update the hi() function:
```
void hi( account_name user ) {
require_auth( user );
print( "Hello, ", name{user} );
}
```
Now if we attempt to mismatch the user and the authority the contract will throw an error:
```
$ cleos push action hello.code hi '["tester"]' -p user
Error 3030001: missing required authority
Ensure that you have the related authority inside your transaction!;
If you are currently using 'cleos push action' command, try to add the relevant authority using -p option.
Error Details:
missing authority of tester
```
We can fix this by giving the permission of tester:
```
$ cleos push action hello.code hi '["tester"]' -p tester
executed transaction: 235bd766c2097f4a698cfb948eb2e709532df8d18458b92c9c6aae74ed8e4518 244 bytes 1000 cycles
# hello.code <= hello.code::hi {"user":"tester"}
>> Hello, tester
```
## Deploy Exchange Contract
```
...
...
libraries/chain/chain_controller.cpp
浏览文件 @
70f12c4c
...
...
@@ -296,13 +296,12 @@ transaction_trace chain_controller::_push_transaction(const packed_transaction&
[
this
](
transaction_metadata
&
meta
)
{
return
delayed_transaction_processing
(
meta
);
}
);
}
result
.
_setup_profiling_us
=
setup_us
;
// notify anyone listening to pending transactions
on_pending_transaction
(
_pending_transaction_metas
.
back
(),
packed_trx
);
_pending_block
->
input_transactions
.
emplace_back
(
packed_trx
);
result
.
_setup_profiling_us
=
setup_us
;
return
result
;
}
FC_CAPTURE_AND_RETHROW
(
(
transaction_header
(
packed_trx
.
get_transaction
()))
)
}
...
...
libraries/chain/contracts/eosio_contract.cpp
浏览文件 @
70f12c4c
...
...
@@ -570,7 +570,7 @@ void apply_eosio_vetorecovery(apply_context& context) {
void
apply_eosio_canceldelay
(
apply_context
&
context
)
{
auto
cancel
=
context
.
act
.
data_as
<
canceldelay
>
();
const
auto
sender_id
=
cancel
.
sender_id
.
convert_to
<
uint32_t
>
()
;
const
auto
sender_id
=
cancel
.
sender_id
;
const
auto
&
generated_transaction_idx
=
context
.
controller
.
get_database
().
get_index
<
generated_transaction_multi_index
>
();
const
auto
&
generated_index
=
generated_transaction_idx
.
indices
().
get
<
by_sender_id
>
();
const
auto
&
itr
=
generated_index
.
lower_bound
(
boost
::
make_tuple
(
config
::
system_account_name
,
sender_id
));
...
...
libraries/chain/include/eosio/chain/contracts/types.hpp
浏览文件 @
70f12c4c
...
...
@@ -270,7 +270,7 @@ struct vetorecovery {
};
struct
canceldelay
{
uint
32
sender_id
;
uint
128_t
sender_id
;
static
account_name
get_account
()
{
return
config
::
system_account_name
;
...
...
libraries/chain/include/eosio/chain/transaction_metadata.hpp
浏览文件 @
70f12c4c
...
...
@@ -10,13 +10,13 @@ namespace eosio { namespace chain {
class
transaction_metadata
{
public:
transaction_metadata
(
const
transaction
&
t
,
const
time_point
&
published
,
const
account_name
&
sender
,
uint
32
_t
sender_id
,
const
char
*
raw_data
,
size_t
raw_size
)
transaction_metadata
(
const
transaction
&
t
,
const
time_point
&
published
,
const
account_name
&
sender
,
uint
128
_t
sender_id
,
const
char
*
raw_data
,
size_t
raw_size
)
:
id
(
t
.
id
())
,
published
(
published
)
,
sender
(
sender
),
sender_id
(
sender_id
),
raw_data
(
raw_data
),
raw_size
(
raw_size
),
_trx
(
&
t
)
{}
transaction_metadata
(
const
transaction
&
t
,
const
time_point
&
published
,
const
account_name
&
sender
,
uint
32
_t
sender_id
,
const
char
*
raw_data
,
size_t
raw_size
,
fc
::
time_point
deadline
)
transaction_metadata
(
const
transaction
&
t
,
const
time_point
&
published
,
const
account_name
&
sender
,
uint
128
_t
sender_id
,
const
char
*
raw_data
,
size_t
raw_size
,
fc
::
time_point
deadline
)
:
id
(
t
.
id
())
,
published
(
published
)
,
sender
(
sender
),
sender_id
(
sender_id
),
raw_data
(
raw_data
),
raw_size
(
raw_size
)
...
...
programs/nodeos/CMakeLists.txt
浏览文件 @
70f12c4c
...
...
@@ -45,11 +45,13 @@ endif()
target_link_libraries
(
nodeos
PRIVATE appbase
PRIVATE -Wl,
${
whole_archive_flag
}
account_history_api_plugin -Wl,
${
no_whole_archive_flag
}
account_history_plugin
PRIVATE -Wl,
${
whole_archive_flag
}
chain_api_plugin -Wl,
${
no_whole_archive_flag
}
producer_plugin chain_plugin
PRIVATE -Wl,
${
whole_archive_flag
}
wallet_api_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE net_plugin -Wl,
${
whole_archive_flag
}
net_api_plugin txn_test_gen_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE http_plugin -Wl,
${
whole_archive_flag
}
faucet_testnet_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE -Wl,
${
whole_archive_flag
}
account_history_api_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE -Wl,
${
whole_archive_flag
}
chain_api_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE -Wl,
${
whole_archive_flag
}
wallet_api_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE -Wl,
${
whole_archive_flag
}
net_api_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE -Wl,
${
whole_archive_flag
}
faucet_testnet_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE -Wl,
${
whole_archive_flag
}
txn_test_gen_plugin -Wl,
${
no_whole_archive_flag
}
PRIVATE account_history_plugin producer_plugin chain_plugin net_plugin http_plugin
PRIVATE eosio_chain fc
${
CMAKE_DL_LIBS
}
${
PLATFORM_SPECIFIC_LIBS
}
)
if
(
BUILD_MONGO_DB_PLUGIN
)
...
...
programs/nodeos/main.cpp
浏览文件 @
70f12c4c
...
...
@@ -8,7 +8,6 @@
#include <eosio/http_plugin/http_plugin.hpp>
#include <eosio/net_plugin/net_plugin.hpp>
#include <eosio/producer_plugin/producer_plugin.hpp>
#include <eosio/txn_test_gen_plugin/txn_test_gen_plugin.hpp>
#include <fc/log/logger_config.hpp>
#include <fc/log/appender.hpp>
...
...
@@ -85,7 +84,7 @@ int main(int argc, char** argv)
auto
root
=
fc
::
app_path
();
app
().
set_default_data_dir
(
root
/
"eosio/nodeos/data"
);
app
().
set_default_config_dir
(
root
/
"eosio/nodeos/config"
);
if
(
!
app
().
initialize
<
chain_plugin
,
http_plugin
,
net_plugin
,
txn_test_gen_plugin
,
producer_plugin
>
(
argc
,
argv
))
if
(
!
app
().
initialize
<
chain_plugin
,
http_plugin
,
net_plugin
,
producer_plugin
>
(
argc
,
argv
))
return
-
1
;
initialize_logging
();
ilog
(
"nodeos version ${ver}"
,
(
"ver"
,
eosio
::
nodeos
::
config
::
itoh
(
static_cast
<
uint32_t
>
(
app
().
version
()))));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录