EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

Eos.modules.format.decodeName is not returning the expected name #302

Closed cipherzzz closed 6 years ago

cipherzzz commented 6 years ago

Using "eosjs": "^16.0.0",

Hello! I have been creating records in my eos contract with the account_name being populated and everything is working within the contract.

//@abi action
            void addschool(const account_name account, string name) {
                require_auth(account);
                schoolIndex schools(_self, _self);
                schools.emplace(account, [&](auto& _school) {
                    _school.account_name = account;
                    _school.key = schools.available_primary_key();
                    _school.name = name;
                    _school.status = 0;
                });
            }
 //@abi table school i64
            struct school {
                uint64_t account_name;
                uint64_t key;
                string name;
                uint64_t status;

                uint64_t primary_key() const { return key; }

                EOSLIB_SERIALIZE(school, (account_name)(key)(name)(status))
            };

            typedef multi_index<N(school), school> schoolIndex;

If I update the school, I can check that the caller is the same account by doing name{account} == name{school.account_name}

However, when I get into eosjs land I can't seem to get decodeName described here to work: https://github.com/EOSIO/eosjs/blob/master/docs/format.md#decodeName

I am trying something like:

return data?data.rows.filter((school)=> 
            {
                console.log("Encoded:", school.account_name)
                console.log("Decoded:", Eos.modules.format.decodeName(school.account_name))
                return true // for now
            }):[]

Output is: Encoded: 3631283935532548096 Decoded: ......4.x5m32

I saw something related to littleEndian in the issues but couldn't understand what was being proposed https://github.com/EOSIO/eosjs/issues/155

Thanks in advance!

jcalfee commented 6 years ago

I am missing an argument in the documentation:

/** @arg {boolean} [littleEndian = true] - Little or Bigendian encoding */

Try with encodeName(name, false) ..

cipherzzz commented 6 years ago

Thanks @jcalfee - you rock