I want to calculate the ram usage when I conduct an action in contract, if ram is over the limit, I will let the action fail automatically.
How can I get the current ram usage in contract?
resource_limits.cpp, it seems like in
eosio code, they use
_db to retrieve the resource consumption, which needs access to the chainbase database running.
As far as I know, this cannot be accessed from smart contract directly, thus, assuming all RAM usage for your contract can be tracked, two suboptimal solutions would be:
cleos get accountdata)
Interested in hearing about better solutions as well.