1

I am getting this error on the testnet:

Error 3070002: Runtime Error Processing WASM
Error Details:
access violation
pending console output:

testdauser11.hpp file:

#include "../eosiolib/eosio.hpp"
#include <string>    

using namespace std;
using namespace eosio;    


namespace eosio {
class test_da : public contract {
    public:
        test_da( account_name self ): contract( self ) {}       

        /// @abi action create
        void create( account_name user, string title, string content );     

/*      ///@abi action change
        void change( account_name user, uint64_t post_id, string title, string content );       

        /// @abi action dele
        void dele( account_name user, uint64_t post_id );   
*/
        /// @abi action getd
        void getd(uint64_t post_id, account_name user );

    private:
        /// @abi table data i64
        struct da
        {
            uint64_t post_id;
            account_name poster;
            string title;
            string content;     

            uint64_t primary_key() const { return post_id; }
            account_name get_poster() const { return poster; }      

            EOSLIB_SERIALIZE( da, (post_id) (poster) (title) (content));
        };      

        typedef multi_index<N(data), da, indexed_by<N(byposter), const_mem_fun<da, account_name, &da::get_poster>>> das;        

};
} /// namespace eosio

testdauser11.cpp file:

#include "testdauser11.hpp"    

using namespace eosio;    

void test_da::create(account_name user, string title, string content) {
    require_auth(user);
    das datable( _self, user );
    datable.emplace( user, [&] (da& d) {
        d.title = title;
        d.content = content;
        d.post_id = datable.available_primary_key();
        d.poster = user;
    });
}    

void test_da::getd(uint64_t post_id, account_name user ) {
    das datable( _self, _self );
    auto post_da = datable.find(post_id);
    print("Post id: ", post_da->post_id, ", title: ", post_da->title.c_str(), ", content: ", post_da->content.c_str());    

    auto post_index = datable.template get_index<N(byposter)>();
    auto pos = post_index.find(user);
    while( pos != post_index.end() ) {
        print( "Post_id: ", pos->post_id, ", Post_title: ", pos->title.c_str(), ", Post_content: ", pos->content.c_str() );
    } 
}
EOSIO_ABI(test_da, (create) (getd));

Command used:

cleos push action testdauser11 getd '[1, "drifeusr1eos"]' -p testdauser11

Can anyone help me understand the error (mentioned above)?

  • You have to check if the post really exists before accessing the data. after auto post_da = datable.find(post_id); you have to check if post_da != datatable.end() – damianodamiano Oct 2 '18 at 19:42
  • private: /// @abi table data i64 struct da { uint64_t post_id; account_name poster; string title; string content; replace da with data – Nirdesh Kumar Choudhary Oct 3 '18 at 6:58
  • @NirdeshKumarChoudhary why do I have to change from da -> data. No relevance at all w.r.t. my question. – Abhijit Roy Oct 4 '18 at 18:06
  • @damianodamiano I have done that already in while loop. Pls check. – Abhijit Roy Oct 4 '18 at 18:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.