1

Lets say you have very large array file in the following format:

[{
   "address": "0x123",
   "state": true
},
{
   "address: "0x234",
   "state": false
}]

Implement a function that would allow you to record this data into smart contract.

1

I'll assume that by "very large" you mean that it will be too big to fit all the uploads into a single transaction (or block).

The first approach that you linked in your comments doesn't seem to actually need a mapping (the array method seems to work).

function whitelistAddresses(address[] _addresses) onlyOwner {
    require(!whitelistInitialized);
    for (uint256 i = 0; i < _addresses.length; i++) {
        addresses[_addresses[i]] = true;
    }
    whitelistInitialized = true;
}

Let's assume you have other reasons to want a struct/mapping, like an expiration date field. You could approach it in roughly the same way:

mapping (address => uint) public expirations;

function whitelistAddresses(address[] _addresses, uint[] expirations) onlyOwner {
    require(!whitelistInitialized);
    for (uint256 i = 0; i < _addresses.length; i++) {
        addresses[_addresses[i]] = expirations[i];
    }
    whitelistInitialized = true;
}

But you have too much to fit in one block, so you could split the array into chunks, call whitelist repeatedly, and then lock it down:

mapping (address => uint) public expirations;

function whitelistAddresses(address[] _addresses, uint[] expirations) onlyOwner {
    require(!whitelistInitialized);
    for (uint256 i = 0; i < _addresses.length; i++) {
        addresses[_addresses[i]] = expirations[i];
    }
}

function whitelistLockdown() onlyOwner {
    whitelistInitialized = true;
}
  • Wow! I didn't think about that. Thank you very much for your answer – rstormsf Aug 19 '17 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.