I am doing a balance upload (copying and modifying the balances from a chain to another)
I have a json file containing all i need, i compute the new balance, and i batch calls doing a setBalance().
I have ~16000 calls to batch. Once everything passed, i run a check script that, for every addresses, fetch their balance from the chain, and check if it matches the one i was expected. and, out of my 16000 calls, i get ~500 accounts that doesn't have the right value. and the difference is very big, no not negligible.
why does this happens ? Why doesn't i have an error ? How can i prevent this ?
here is the code (simplified) :
import balances from "./balances.json"
/*
format:
0x000: {
address: 0x000 // same as key
free: ...
reserved: ...
Total: ...
}
*/
import crowdloan from "./crowdloan.json"
/*
format:
0x000: value
*/
for (balance in balances) {
let new_balance = (balance.Total / 100) * 10 ** 12
const deposit = crowdloan[balance.address]
if (deposit != undefined) {
new_balance += deposit * kab_per_ksm /* constant */ * 10 ** 12
}
const free_balance = parseInt((new_balance * (3 / 10))
const reserved_balance = parseInt((new_balance * (7 / 10))
await api.tx.sudo.sudo(
api.tx.balances.setBalance(address, free_balance.toString(),
reserved_balance.toString())
).signAndSend(sudo, { nonce: -1 })
}