1

What is going on? :D I write data, but cannot find it after I write it.

The following code successfully emplaces the row into the multi-index table:

See specifically the vector<vector <structnamex::plot >> map parameter which is what I am dubious about.

ACTION structnamex::createland(name land_id, string land_name, uint8_t x_size,
uint8_t y_size, vector<vector<structnamex::plot>> map) {

        require_auth( get_self() );
    
        lands_index _southlands( get_self(), get_self().value );
     
        uint8_t find_y = map.size();
        uint8_t find_x;
        if(find_y > 0)
        { find_x = map[0].size(); }
    
        check((x_size == find_x), "x_size value does not match x value in map[y][x]");
        check((y_size == find_y), "y_size value does not match y value in map[y][x]");
        check((x_size > 0), "x_size value must be greater than 0");
        check((y_size > 0), "y_size value must be greater than 0");
    
        //check all x values
        for (int i = 0; i < y_size; i++) {
             check((map[i].size() == x_size), "x_size value does not match x value in map[y][x] in later rows");
        }
    
        print("X val: ", find_x, " -- Y val: ", find_y);
        _southlands.emplace( get_self(), [&]( auto& land_row ) {
            land_row.land_id    = land_id;
            land_row.land_name  = land_name;
            land_row.x_size     = x_size;
            land_row.y_size     = y_size;
            land_row.map        = map;
    
            print("-- data emplaced!");
        });
    }

In the header file we have the structures declared as follows

    // ... inside contract declaration ...

    /// the plot struct from the header file is as follows:
    struct plot {
       name owner;
       uint16_t type;

       EOSLIB_SERIALIZE(plot, (owner)(type));
    };
    
    // the multi-index table is as follows
    TABLE lands {
    name          land_id;
    string        land_name;
    uint8_t       x_size;
    uint8_t       y_size;
    vector<vector<structnamex::plot>>  map;

    auto primary_key() const { return land_id.value; };

    };

I write this data in EOS Studio:

land_id: funland
land_name: Fun Land Central
x_size: 2
y_size: 2

map: [[{"owner": "useraccount","type": 20},{"owner": "useraccount","type": 20}],
[{"owner": "useraccount","type": 20},{"owner": "useraccount","type": 20}]]

According to the console output, it successfully writes. If I try to write this data again, it fails, saying that index already exists.

confirmed successfully adding row

This data will not display in EOS Studio when you refresh the multi-index table. It produces the error, " FC Exception encountered while processing chain.get_table_rows "

error

Even though it wont display in EOS Studio, I use some smart contract code to see if it's there:

ACTION structnamex::testprint(name land_id, uint8_t x, uint8_t y) {

    lands_index _southlands( get_self(), get_self().value );

    auto itr = _southlands.find(land_id.value);

    if(itr != _southlands.end()) {
        print("found!");
    }
    else {
        print("land not found"); }
};

The function when run with the following submits the transaction without error, but the console gives no output.

land_id:  funland
x: 1
y: 1

enter image description here

1
  • It was suggested to see if maybe I had a prior table format inside my multi-index table. I tried deleting my local node instance and deploying from scratch. Same result as above, still bugged. Feb 16 at 13:50
0

A couple of comments:

  1. about when you try to write again, it fails, saying that index already exists; the code just uses tblIndex.emplace() method to populate the data no matter what, actually he should use tblndex.modify() when the data exists.
        lands_index _southlands( get_self(), get_self().value );

        auto iter = lands_index.find(land_id.value); 
        if (iter == lands_index.end()) 
        { 
            lands_index.emplace(get_self(), [&](auto &row) { 
            row.land_id    = land_id;
                        ...assign other fields...
                    });
        } 
        else 
        { 
            lands_index.modify(iter,get_self(), [&]( auto& row ) { 
                        ...assign other fields...
                    }); 
        } 
  1. Also try to use typedef to deal with vector<vector>
i.e typedef 
    vector<structnamex::plot> vec_plot;
replace
    vector<vector<structnamex::plot>> with vector<vec_plot>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.