提交 70f12c4c 编写于 作者: A arhag

Merge branch 'master' into 1755-check-signatures

......@@ -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 prodcast" and "return transaction as json".
"don't broadcast" 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
```
......
......@@ -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())) ) }
......
......@@ -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));
......
......@@ -270,7 +270,7 @@ struct vetorecovery {
};
struct canceldelay {
uint32 sender_id;
uint128_t sender_id;
static account_name get_account() {
return config::system_account_name;
......
......@@ -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, uint32_t sender_id, const char* raw_data, size_t raw_size )
transaction_metadata( const transaction& t, const time_point& published, const account_name& sender, uint128_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, uint32_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, uint128_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)
......
......@@ -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)
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册