Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

get table array values not being returned #2350

Closed
brianjohnson5972 opened this issue Apr 12, 2018 · 3 comments
Closed

get table array values not being returned #2350

brianjohnson5972 opened this issue Apr 12, 2018 · 3 comments
Assignees
Milestone

Comments

@brianjohnson5972
Copy link
Contributor

brianjohnson5972 commented Apr 12, 2018

Specific example is tic_tac_toe tutorial, "get table" returns:

{
"rows": [{
"challenger": "player2",
"host": "player1",
"turn": "player2",
"winner": "none",
"board": []
}
],
"more": false
}

even though board is a uint8_t[9] and has values

@brianjohnson5972
Copy link
Contributor Author

brianjohnson5972 commented Apr 12, 2018

@wanderingbort
I think the issue is that in the abi the type is defined as "uint8_t[]" which maps to a vector for pack/unpack, but in tic_tack_toe.hpp the parameter is:
uint8_t board[9];
Which will NOT be mapped to operator<< with vector, so the packing/unpacking don't match.

I think it is calling "DataStream& operator << ( DataStream& ds, const std::array<T,N>& v )" which is more efficient for packing/unpacking in contracts, but there is nothing on the abi that could handle this (since no size is stored in the packed format and we don't have anything in the abi that indicates a fixed size array).

The easiest solution to this is to change the implementation of "DataStream& operator << ( DataStream& ds, const std::array<T,N>& v )" to match vector, which is not as efficient, but not terribly. Harder solution is extending the abi to include "yyyy[#]" where # indicates the fixed size of the array and passes that size along with the pack/unpack to indicate size to read/write.

@brianjohnson5972 brianjohnson5972 self-assigned this Apr 12, 2018
@brianjohnson5972
Copy link
Contributor Author

Handling this by implementing operator<< for std::array and adding one for "T (&v)[N}" and using a similar implementation to std::vector so that there is a size for abi serializer to use to size the vector that it will allocate to handle all of these types.

@heifner heifner added this to the RC2 milestone Apr 13, 2018
brianjohnson5972 added a commit to brianjohnson5972/eos that referenced this issue Apr 16, 2018
brianjohnson5972 added a commit to brianjohnson5972/eos that referenced this issue Apr 16, 2018
brianjohnson5972 added a commit to brianjohnson5972/eos that referenced this issue Apr 16, 2018
…so that abi serializer can serialize both types the same way. GH EOSIO#2350
brianjohnson5972 added a commit to brianjohnson5972/eos that referenced this issue Apr 16, 2018
…s are packed/unpacked according to the abi definition and cleanup of tests. GH EOSIO#2350
@brianjohnson5972 brianjohnson5972 added code review in code review and removed in progress labels Apr 16, 2018
brianjohnson5972 added a commit to brianjohnson5972/eos that referenced this issue Apr 17, 2018
brianjohnson5972 added a commit to brianjohnson5972/eos that referenced this issue Apr 17, 2018
@brianjohnson5972 brianjohnson5972 added needs testing and removed code review in code review labels Apr 18, 2018
@andriantolie andriantolie self-assigned this Apr 19, 2018
@andriantolie
Copy link
Contributor

Played the tic_tac_toe contract and can verify for each step the board is printed properly by cleos get table command

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants