I am still a solidity noob, so I apologize if the question is too basic.
I am trying to write a contract which saves the hash of a (potentially) large bunch of data on chain.
For this reason, I would like to write a function which performs the hash externally (i.e. on the caller machine, something like a view function), and then it saves back the result on the chain. Is it possible? A code example here:
contract Test {
bytes32[] hashes;
function extCall(bytes _data) external view {
bytes32 hash = keccak256(_data);
_intCall(hash);
}
function _intCall(bytes32 _hash) private {
hashes.push(_hash)
}
}
The intention here was to exclude the possibility to save the hash on the chain without having the original data. For this reason, the only way to call the function _intCall would be by means of calling it through extCall. But, it seems that by doing this trick, also extCall is called on chain and consumes gas. In particular, i get this warning while testing on truffle:
Warning: Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
P.s. there is a (BIG) chance that I totally misunderstood the topic, so every help is really accepted!