未验证 提交 2a774eb5 编写于 作者: W wanderingbort 提交者: GitHub

Merge pull request #2422 from larryk85/ricardian_misc

Ricardian misc PR for eos #2389
......@@ -32,6 +32,7 @@ add_subdirectory(noop)
add_subdirectory(dice)
add_subdirectory(tic_tac_toe)
file(GLOB SKELETONS RELATIVE ${CMAKE_SOURCE_DIR}/contracts "skeleton/*")
# Documented multiple output support is broken, so properly setting up the multiple
......
file(GLOB ABI_FILES "*.abi")
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
add_wast_executable(TARGET hello
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc libc++ eosiolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)
{
"____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2018-04-16T13:37:55",
"types": [],
"structs": [{
"name": "hi",
"base": "",
"fields": [{
"name": "user",
"type": "account_name"
}
]
}
],
"actions": [{
"name": "hi",
"type": "hi",
"ricardian_contract": "# CONTRACT FOR hello::hi## ACTION NAME: hi\n### Parameters### Parameters\nInput paramters:Input paramters:\n\n* `user` (string to include in the output)* `user` (string to include in the output)\n\nImplied parameters: Implied parameters: \n\n* `account_name` (name of the party invoking and signing the contract)* `account_name` (name of the party invoking and signing the contract)\n\n### Intent### Intent\nINTENT. The intention of the author and the invoker of this contract is to print output. It shall have no other effect.INTENT. The intention of the author and the invoker of this contract is to print output. It shall have no other effect.\n\n### Term### Term\nTERM. This Contract expires at the conclusion of code execution.TERM. This Contract expires at the conclusion of code execution.\n"
}
],
"tables": [],
"ricardian_clauses": [{
"id": "Warranty",
"body": "WARRANTY. The invoker of the contract action shall uphold its Obligations under this Contract in a timely and workmanlike manner, using knowledge and recommendations for performing the services which meet generally acceptable standards set forth by EOS.IO Blockchain Block Producers.\n\n"
},{
"id": "Default",
"body": "DEFAULT. The occurrence of any of the following shall constitute a material default under this Contract: \n\n"
},{
"id": "Remedies",
"body": "REMEDIES. In addition to any and all other rights a party may have available according to law, if a party defaults by failing to substantially perform any provision, term or condition of this Contract, the other party may terminate the Contract by providing written notice to the defaulting party. This notice shall describe with sufficient detail the nature of the default. The party receiving such notice shall promptly be removed from being a Block Producer and this Contract shall be automatically terminated. \n \n"
},{
"id": "Force Majeure",
"body": "FORCE MAJEURE. If performance of this Contract or any obligation under this Contract is prevented, restricted, or interfered with by causes beyond either party's reasonable control (\"Force Majeure\"), and if the party unable to carry out its obligations gives the other party prompt written notice of such event, then the obligations of the party invoking this provision shall be suspended to the extent necessary by such event. The term Force Majeure shall include, without limitation, acts of God, fire, explosion, vandalism, storm or other similar occurrence, orders or acts of military or civil authority, or by national emergencies, insurrections, riots, or wars, or strikes, lock-outs, work stoppages, or supplier failures. The excused party shall use reasonable efforts under the circumstances to avoid or remove such causes of non-performance and shall proceed to perform with reasonable dispatch whenever such causes are removed or ceased. An act or omission shall be deemed within the reasonable control of a party if committed, omitted, or caused by such party, or its employees, officers, agents, or affiliates. \n \n"
},{
"id": "Dispute Resolution",
"body": "DISPUTE RESOLUTION. Any controversies or disputes arising out of or relating to this Contract will be resolved by binding arbitration under the default rules set forth by the EOS.IO Blockchain. The arbitrator's award will be final, and judgment may be entered upon it by any court having proper jurisdiction. \n \n"
},{
"id": "Entire Agreement",
"body": "ENTIRE AGREEMENT. This Contract contains the entire agreement of the parties, and there are no other promises or conditions in any other agreement whether oral or written concerning the subject matter of this Contract. This Contract supersedes any prior written or oral agreements between the parties. \n\n"
},{
"id": "Severability",
"body": "SEVERABILITY. If any provision of this Contract will be held to be invalid or unenforceable for any reason, the remaining provisions will continue to be valid and enforceable. If a court finds that any provision of this Contract is invalid or unenforceable, but that by limiting such provision it would become valid and enforceable, then such provision will be deemed to be written, construed, and enforced as so limited. \n\n"
},{
"id": "Amendment",
"body": "AMENDMENT. This Contract may be modified or amended in writing by mutual agreement between the parties, if the writing is signed by the party obligated under the amendment. \n\n"
},{
"id": "Governing Law",
"body": "GOVERNING LAW. This Contract shall be construed in accordance with the Maxims of Equity. \n\n"
},{
"id": "Notice",
"body": "NOTICE. Any notice or communication required or permitted under this Contract shall be sufficiently given if delivered to a verifiable email address or to such other email address as one party may have publicly furnished in writing, or published on a broadcast contract provided by this blockchain for purposes of providing notices of this type. \n"
},{
"id": "Waiver of Contractual Right",
"body": "WAIVER OF CONTRACTUAL RIGHT. The failure of either party to enforce any provision of this Contract shall not be construed as a waiver or limitation of that party's right to subsequently enforce and compel strict compliance with every provision of this Contract. \n\n"
},{
"id": "Arbitrator's Fees to Prevailing Party",
"body": "ARBITRATOR’S FEES TO PREVAILING PARTY. In any action arising hereunder or any separate action pertaining to the validity of this Agreement, both sides shall pay half the initial cost of arbitration, and the prevailing party shall be awarded reasonable arbitrator's fees and costs.\n \n"
},{
"id": "Construction and Interpretation",
"body": "CONSTRUCTION AND INTERPRETATION. The rule requiring construction or interpretation against the drafter is waived. The document shall be deemed as if it were drafted by both parties in a mutual effort. \n \n"
}
]
}
\ No newline at end of file
#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) )
# CONTRACT FOR hello::hi
## ACTION NAME: hi
### Parameters
Input paramters:
* `user` (string to include in the output)
Implied parameters:
* `account_name` (name of the party invoking and signing the contract)
### Intent
INTENT. The intention of the author and the invoker of this contract is to print output. It shall have no other effect.
### Term
TERM. This Contract expires at the conclusion of code execution.
### CLAUSE NAME: Warranty
WARRANTY. The invoker of the contract action shall uphold its Obligations under this Contract in a timely and workmanlike manner, using knowledge and recommendations for performing the services which meet generally acceptable standards set forth by EOS.IO Blockchain Block Producers.
### CLAUSE NAME: Default
DEFAULT. The occurrence of any of the following shall constitute a material default under this Contract:
### CLAUSE NAME: Remedies
REMEDIES. In addition to any and all other rights a party may have available according to law, if a party defaults by failing to substantially perform any provision, term or condition of this Contract, the other party may terminate the Contract by providing written notice to the defaulting party. This notice shall describe with sufficient detail the nature of the default. The party receiving such notice shall promptly be removed from being a Block Producer and this Contract shall be automatically terminated.
### CLAUSE NAME: Force Majeure
FORCE MAJEURE. If performance of this Contract or any obligation under this Contract is prevented, restricted, or interfered with by causes beyond either party's reasonable control ("Force Majeure"), and if the party unable to carry out its obligations gives the other party prompt written notice of such event, then the obligations of the party invoking this provision shall be suspended to the extent necessary by such event. The term Force Majeure shall include, without limitation, acts of God, fire, explosion, vandalism, storm or other similar occurrence, orders or acts of military or civil authority, or by national emergencies, insurrections, riots, or wars, or strikes, lock-outs, work stoppages, or supplier failures. The excused party shall use reasonable efforts under the circumstances to avoid or remove such causes of non-performance and shall proceed to perform with reasonable dispatch whenever such causes are removed or ceased. An act or omission shall be deemed within the reasonable control of a party if committed, omitted, or caused by such party, or its employees, officers, agents, or affiliates.
### CLAUSE NAME: Dispute Resolution
DISPUTE RESOLUTION. Any controversies or disputes arising out of or relating to this Contract will be resolved by binding arbitration under the default rules set forth by the EOS.IO Blockchain. The arbitrator's award will be final, and judgment may be entered upon it by any court having proper jurisdiction.
### CLAUSE NAME: Entire Agreement
ENTIRE AGREEMENT. This Contract contains the entire agreement of the parties, and there are no other promises or conditions in any other agreement whether oral or written concerning the subject matter of this Contract. This Contract supersedes any prior written or oral agreements between the parties.
### CLAUSE NAME: Severability
SEVERABILITY. If any provision of this Contract will be held to be invalid or unenforceable for any reason, the remaining provisions will continue to be valid and enforceable. If a court finds that any provision of this Contract is invalid or unenforceable, but that by limiting such provision it would become valid and enforceable, then such provision will be deemed to be written, construed, and enforced as so limited.
### CLAUSE NAME: Amendment
AMENDMENT. This Contract may be modified or amended in writing by mutual agreement between the parties, if the writing is signed by the party obligated under the amendment.
### CLAUSE NAME: Governing Law
GOVERNING LAW. This Contract shall be construed in accordance with the Maxims of Equity.
### CLAUSE NAME: Notice
NOTICE. Any notice or communication required or permitted under this Contract shall be sufficiently given if delivered to a verifiable email address or to such other email address as one party may have publicly furnished in writing, or published on a broadcast contract provided by this blockchain for purposes of providing notices of this type.
### CLAUSE NAME: Waiver of Contractual Right
WAIVER OF CONTRACTUAL RIGHT. The failure of either party to enforce any provision of this Contract shall not be construed as a waiver or limitation of that party's right to subsequently enforce and compel strict compliance with every provision of this Contract.
### CLAUSE NAME: Arbitrator's Fees to Prevailing Party
ARBITRATOR’S FEES TO PREVAILING PARTY. In any action arising hereunder or any separate action pertaining to the validity of this Agreement, both sides shall pay half the initial cost of arbitration, and the prevailing party shall be awarded reasonable arbitrator's fees and costs.
### CLAUSE NAME: Construction and Interpretation
CONSTRUCTION AND INTERPRETATION. The rule requiring construction or interpretation against the drafter is waived. The document shall be deemed as if it were drafted by both parties in a mutual effort.
### CLAUSE NAME: In Witness Whereof
IN WITNESS WHEREOF, the parties hereto have caused this Agreement to be executed by themselves or their duly authorized representatives as of the date of execution, and authorized as proven by the cryptographic signature on the transaction that invokes this contract.
......@@ -77,7 +77,6 @@ void test_action::test_cf_action() {
eosio::action act = eosio::get_action( 0, 0 );
cf_action cfa = act.data_as<cf_action>();
if ( cfa.payload == 100 ) {
// verify read of get_context_free_data, also verifies system api access
int size = get_context_free_data( cfa.cfd_idx, nullptr, 0 );
......
......@@ -12,7 +12,7 @@ namespace eosio {
}
// #include <eosiolib/transaction.hpp>
//#include <eosiolib/transaction.hpp>
// NOTE: including eosiolib/transaction.hpp here causes !"unresolvable": env._ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
// errors in api_tests/memory_tests
......
......@@ -23,6 +23,10 @@ void abi_generator::set_verbose(bool verbose) {
this->verbose = verbose;
}
void abi_generator::set_ricardian_contracts(const ricardian_contracts& contracts) {
this->rc = contracts;
}
void abi_generator::set_abi_context(const string& abi_context) {
this->abi_context = abi_context;
}
......@@ -130,7 +134,7 @@ bool abi_generator::inspect_type_methods_for_actions(const Decl* decl) { try {
full_types[method_name] = method_name;
output->actions.push_back({method_name, method_name, ""});
output->actions.push_back({method_name, method_name, rc[method_name]});
at_least_one_action = true;
};
......@@ -237,7 +241,7 @@ void abi_generator::handle_decl(const Decl* decl) { try {
ABI_ASSERT(ac->type == type_name, "Same action name with different type ${action}",("action",action));
continue;
}
output->actions.push_back({action, type_name, ""});
output->actions.push_back({action, type_name, rc[action]});
}
} else if (type == "table") {
......
......@@ -4,6 +4,9 @@
#include <regex>
#include <algorithm>
#include <memory>
#include <map>
#include <fstream>
#include <sstream>
#include <eosio/chain/contracts/abi_serializer.hpp>
#include <eosio/chain/contracts/types.hpp>
......@@ -55,6 +58,102 @@ namespace eosio {
} \
FC_MULTILINE_MACRO_END \
)
class ricardian_contracts {
public:
ricardian_contracts() = default;
ricardian_contracts( const string& context, const string& contract, const vector<string>& actions ) {
ifstream clauses_file( context+"/"+contract+"_rc.md");
if ( !clauses_file.good() )
wlog("Warning, no ricardian clauses found for ${con}\n", ("con", contract));
else
parse_clauses( clauses_file );
for ( auto act : actions ) {
ifstream contract_file( context+"/"+contract+"."+act+"_rc.md" );
if ( !contract_file.good() )
wlog("Warning, no ricardian contract found for ${act}\n", ("act", act));
else {
parse_contract( contract_file );
}
}
}
vector<clause_pair> get_clauses() {
return _clauses;
}
string operator[]( string key ) {
return _contracts[key];
}
private:
inline string is_clause_decl( string line ) {
smatch match;
if ( regex_match( line, match, regex("(###[ ]+CLAUSE[ ]+NAME[ ]*:[ ]*)(.*)", regex_constants::ECMAScript) ) ) {
FC_ASSERT( match.size() == 3, "Error, malformed clause declaration" );
return match[2].str();
}
return {};
}
inline string is_action_decl( string line ) {
smatch match;
if ( regex_match( line, match, regex("(##[ ]+ACTION[ ]+NAME[ ]*:[ ]*)(.*)", regex_constants::ECMAScript) ) ) {
FC_ASSERT( match.size() == 3, "Error, malformed action declaration" );
return match[2].str();
}
return {};
}
void parse_contract( ifstream& contract_file ) {
string line;
string name;
string _name;
stringstream body;
bool first_time = true;
while ( contract_file.peek() != EOF ) {
getline( contract_file, line );
body << line;
if ( !(_name = is_action_decl( line )).empty() ) {
name = _name;
first_time = false;
}
else
if ( !first_time )
body << line << '\n';
}
_contracts.emplace(name, body.str());
}
void parse_clauses( ifstream& clause_file ) {
string line;
string name;
string _name;
stringstream body;
bool first_time = true;
while ( clause_file.peek() != EOF ) {
getline( clause_file, line );
if ( !(_name = is_clause_decl( line )).empty() ) {
if ( !first_time ) {
if (body.str().empty() ) {
FC_ASSERT( false, "Error, invalid input in ricardian clauses, no body found" );
}
_clauses.emplace_back( name, body.str() );
body.str("");
}
name = _name;
first_time = false;
}
else
if ( !first_time )
body << line << '\n';
}
}
vector<clause_pair> _clauses;
map<string, string> _contracts;
};
/**
* @brief Generates eosio::abi_def struct handling events from ASTConsumer
......@@ -71,6 +170,7 @@ namespace eosio {
clang::ASTContext* ast_context;
string target_contract;
vector<string> target_actions;
ricardian_contracts rc;
public:
enum optimization {
......@@ -116,6 +216,13 @@ namespace eosio {
*/
void set_abi_context(const string& abi_context);
/**
* @brief Set the ricardian_contracts object with parsed contracts and clauses
* @param ricardian_contracts contracts
*/
void set_ricardian_contracts(const ricardian_contracts& contracts);
/**
* @brief Set the single instance of the Clang compiler
* @param compiler_instance compiler instance
......@@ -277,6 +384,7 @@ namespace eosio {
};
class generate_abi_action : public ASTFrontendAction {
private:
......@@ -287,12 +395,15 @@ namespace eosio {
generate_abi_action(bool verbose, bool opt_sfs, string abi_context,
abi_def& output, const string& contract, const vector<string>& actions) {
ricardian_contracts rc( abi_context, contract, actions );
abi_gen.set_output(output);
abi_gen.set_verbose(verbose);
abi_gen.set_abi_context(abi_context);
abi_gen.set_target_contract(contract, actions);
abi_gen.set_ricardian_contracts( rc );
output.ricardian_clauses = rc.get_clauses();
if(opt_sfs)
abi_gen.enable_optimizaton(abi_generator::OPT_SINGLE_FIELD_STRUCT);
}
......
......@@ -97,16 +97,6 @@ struct native_to_wasm<T *> {
/**
* Mappings for native types
*/
/*
template<>
struct native_to_wasm<float32_t> {
using type = F32;
};
template<>
struct native_to_wasm<float64_t> {
using type = F64;
};
*/
template<>
struct native_to_wasm<float> {
using type = F32;
......@@ -189,21 +179,11 @@ inline auto convert_wasm_to_native(native_to_wasm_t<T> val) {
template<typename T>
struct wasm_to_value_type;
template<>
struct wasm_to_value_type<float32_t> {
static constexpr auto value = ValueType::f32;
};
template<>
struct wasm_to_value_type<F32> {
static constexpr auto value = ValueType::f32;
};
template<>
struct wasm_to_value_type<float64_t> {
static constexpr auto value = ValueType::f64;
};
template<>
struct wasm_to_value_type<F64> {
static constexpr auto value = ValueType::f64;
......@@ -226,15 +206,6 @@ template<>
struct wasm_to_rvalue_type<F32> {
static constexpr auto value = ResultType::f32;
};
template<>
struct wasm_to_rvalue_type<float32_t> {
static constexpr auto value = ResultType::f32;
};
template<>
struct wasm_to_rvalue_type<float64_t> {
static constexpr auto value = ResultType::f64;
};
template<>
struct wasm_to_rvalue_type<F64> {
static constexpr auto value = ResultType::f64;
......
......@@ -89,7 +89,6 @@ int main(int argc, const char **argv) { abi_def output; try {
result = Tool.run(create_factory(abi_verbose, abi_opt_sfs, abi_context, output, contract, actions).get());
if(!result) {
abi_serializer(output).validate();
fc::variant vabi;
to_variant(output, vabi);
......
......@@ -740,7 +740,8 @@ BOOST_FIXTURE_TEST_CASE(abigen_double_action, abi_gen_helper)
"type" : "C",
"ricardian_contract" : ""
}],
"tables": []
"tables": [],
"ricardian_clauses":[]
}
)=====";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册