I have a contract with different categories. We can assume them to be the following here:
- Cities
- Countries
- Counties
Suppose I want to add a new city to the category cities. I'm assuming this has to be an array as I need to be iterable.
This code does not compile but it shows the type of thing I want to achieve
mapping(string => string[]) Categories;
// Add a record
function addCity(string _type, string _city) {
Categories[_type].push(_city);
}
I will need these strings (the cities) to be passed around and apparently that is not possible in Ethereum yet (see here).
Alternatively, I tried doing this (omitting irrelevant code)
mapping(string => bytes32[]) Categories;
function addCity(string _type, bytes32 _city) {
Categories[_type].push(_city);
}
Which does compile. However, when I add
599437d068e6196203c2ec23
I get back
0x3539393433376430363865363139363230336332656332330000000000000000
and I don't know what to do to convert it to 599437d068e6196203c2ec23 when fetching the value. I've tried web3.toAscii() but it didn't work.
My question is: is there an alternative way which I'm missing or, if not, how to I convert the value back when I need to?