EOSIO Contract Inheritance not working
CDT: 1.6.3
The basic idea was to use C++ inheritance capabilities to extend common use contracts, like the eosio.token contract.
I think this is very useful as to inherit all the upgrades and possible security fixes that a standard contract might get, without having to copy and paste all the code and verify that it doesn't break any other functionality that our derived contract might have added to the base.
And actually this is possible in other platforms like Ethereum, for instance, as it is a common practice to extend ERC20 contract and implement only our own logic.
Having tested it in EOSIO, I wasn't able to make it work, not only the ABI generator was not grabbing the methods/tables/etc from the base contract, which is a pain to do manually in large contract codebases, but also the WASM interface wasn't supplying the correct methods.
The only change that I had to do to eosio.token contract was substituting the private: clause for protected: to enable the use of the intrinsics of the standard eosio token contract by my derived one...
An example of this issue in bananas.cpp:
#include <eosio/eosio.hpp>
#include <eosio.token/eosio.token.hpp>
typedef typename eosio::token BaseToken;
CONTRACT bananas : public BaseToken
{
public:
using BaseToken::BaseToken;
bananas(eosio::name receiver, eosio::name code, eosio::datastream<const char *> ds)
: BaseToken(receiver, code, ds) {}
ACTION doit() {}
};
This contract builds perfectly fine, but the generated bananas.abi was like this:
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.1",
"types": [],
"structs": [
{
"name": "doit",
"base": "",
"fields": []
}
],
"actions": [
{
"name": "doit",
"type": "doit",
"ricardian_contract": ""
}
],
"tables": [],
"ricardian_clauses": [],
"variants": []
}
Only contains the actions/tables/etc from the derived contract, ignoring all the actions/tables/etc from the base contract. And the same seems to be valid to the methods on the WASM interface.
If the eosio-cpp compiler could be changed to include the inherited functionality, it would open a complete new set of possibilities for EOSIO ecosystem to evolve, without copy/paste mentality, and inherit all the benefits of C++ to build more solid contracts and improve our beloved platform to new grounds, enabling easier collaboration/extension of existing basis, as it is already done in other platforms.
This is the only thing that is preventing full C++ inheritance in contracts, so I think it might be a good thing to improve our EOSIO platform.
Please check eosio-token-inherit project here on GitHub for a demonstration of this problem in a working project with EOSLime tests.
Thanks.
same problem +1 in eosio.cdt v1.7