I am using truffle and I am trying to pass during the deployment execution script a double array of prices inside my contract's constructor. ie
In the migration file I have a 2 dimensional array. It's nested array contains a pair of prices.
var prices = [
['1223.456', '1223.456'],
['123.46', '12.1']
];
contract A {
struct Price {
string Price0;
string Price1;
}
mapping (uint => Price) prices;
constructor (int[][] memory _prices) public
{
for(uint i=0; i< _prices.length; i++)
{
prices[i] = Price(
_prices[i][0],
_prices[i][1]
);
}
}
}
How can I declare this inside my contract's constructor so that I can parse it right after? What I saw so far is that I can declare a 2 dimensional array with the same type ie
uint[][] prices;
// or
string[][] prices;
but these are not working since in my double array the 1-level key is of type integer and the value of the 2-level is of type string.
[1]
? – goodvibration Jan 4 at 14:45Price0
andPrice1
are of typestring
. The input_prices
array contains items of typeint
, which you cannot assign to variables of typestring
!!! – goodvibration Jan 4 at 16:34