0

I have been stuck on this for a while, I have a mapping
mapping (uint => bytes) idToEmail;

A function to populate the mapping
function addRecord(uint id, bytes email) public payable { idToEmail[id] = email; }

I need a function to fetch multiple values for an input of multiple keys, like
function fetchRecords(uint[] ids) returns (bytes[]) {..}

How do I go about doing this?

1

You cannot return a dynamic array in solidity at the moment however, you can return a byte array of fixed size. Try Solidity: Can you return dynamic arrays in a function? for more information

  • Can I concatenate or serialize the elements of the dynamic array and return that as a string? – Shivam D Sep 14 '17 at 14:34
  • yes you can, solidity doesn't support concatenation but you can manually concatenate bytes together and return a string representation like so: ethereum.stackexchange.com/questions/729/… – Ayodeji Agboola Sep 14 '17 at 14:43
  • Also, note that you can use the solidity-stringutils package to split strings : github.com/Arachnid/solidity-stringutils – Ayodeji Agboola Sep 14 '17 at 14:48
  • Great! :) I'm assuming that since contract calls are inexpensive (free?) this operation should not cost anything? – Shivam D Sep 14 '17 at 16:00

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.