[Ethereum] call mapping as arguments of function

mappingsolidity

I'd like to call mapping as arguments of function. I've tried the following code, but it returned the error. Could I call mapping as arguments as a function?

mapping ( uint256 => mapping (bytes32 => bytes32)) public users;

function add( uint256 id, bytes32[] list, mapping ( uint256 => mapping (bytes32 => bytes32) table){
    for( var i=0; i< list.length; i++ ){
        table[id][list[i]] = list[i];
    }
}

Error: Type is required to live outside storage.
function add( uint256 id, bytes32[] list, mapping ( uint256 => mapping (bytes32 => bytes32)) table){
^——————————————————^ Error:
Internal type is not allowed for public or external functions.
function add( uint256 id, bytes32[] kv_list, mapping ( uint256 => mapping (bytes32 => bytes32)) table){

Best Answer

The second error you get tells you that external functions cannot have internal types as arguments (i.e. structs and mappings). You can solve that one by specifying internal or private for your function.

For the first error, im not sure if it is a bug or not, but you cannot pass mappings as arguments. What you could do is wrap them in a struct and pass the struct as a parameter.

One final notice is that if you declare your mapping as a state variable then you have access to it directly in your function. So in you example table could just be a state variable...especially since you only use it for storage purposes.