Byte-per-byte comparisons. Conversions needed. reddit link is dead. Why do you need to access msg.data
directly?
EDIT: Convert a uint256 from calldata bytes to a proper uint256 in Solidity: https://gist.github.com/anonymous/a734a5d299ffa7b5a834
EDIT: The typing system and posting rules on this site are super weird. Anyways that works. It should always return true.
The struct used as the parameter type in your updatePrices
has a particularity, it contains a member which type is another struct. We will come back to that later, for now let's look how it goes with a "simple" struct.
contract Contract {
struct Simple {
int a;
int b;
}
Simple[] public array;
function add(Simple[] memory _array) public {
for(uint i=0; i<_array.length; i++){
array.push(_array[i]);
}
}
}
You can see it's rather simple. On Remix, if you want to call add
, it's simple too. You just create an array, like you would for any other type, and then add "sub-arrays" which will represent each struct.
Here's an example :
[[1,2],[3,4]]
You are adding two structs. The first one contains 1
and 2
, which will be respectively assigned to the a
and b
members of the struct, and same thing for the second one which has 3
and 4
.
Now, back to your contract.
Logically, we would call updatePrices
with the following input [[5,[2,2]]]
. It's an array of length 1
, with 5
being the currencyInt
member and [2,2]
the corresponding values for the Price
struct.
It's not possible on remix.ethereum.org for now, it won't work.
However, it's implemented on alpha remix, and if you used the input above, it will work fine.
Regarding your contract itself
I think there is an error on this line
priceByCurrencyType[_array[0].currencyInt].price=_array[i].price;
^
You probably intended to do _array[i]
.
Best Answer
I'm not really sure of what your are looking for but if you want to send more parameters than required in the signature you can do something like that