Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function migrateState({ subtrees, lastRoot, commitments, nullifiers, newInstance }) {
const loadBy = 100
let commitmentsToLoad
let nullifiersToLoad
await newInstance.methods.initializeTreeForMigration(subtrees, lastRoot).send({
gas: numberToHex(2500000),
gasPrice: toHex(toWei('12', 'gwei')),
from: web3Target.eth.defaultAccount
})
for(let i=0; i < commitments.length / loadBy; i++) {
commitmentsToLoad = commitments.slice(i*loadBy, (i+1)*loadBy)
nullifiersToLoad = nullifiers.slice(i*loadBy, (i+1)*loadBy)
console.log(`Uploading commitments and nullifiers from ${i*loadBy} to ${(i+1)*loadBy}:`)
// console.log('Commitments:\n', commitmentsToLoad)
// console.log('Nullifiers:\n', nullifiersToLoad)
const tx = await newInstance.methods.migrateState(
commitmentsToLoad,
nullifiersToLoad
).send({
gas: numberToHex(6500000),
gasPrice: toHex(toWei('12', 'gwei')),
var inputPostFormatter = function (post) {
// post.payload = utils.toHex(post.payload);
if (post.ttl)
post.ttl = utils.numberToHex(post.ttl);
if (post.workToProve)
post.workToProve = utils.numberToHex(post.workToProve);
if (post.priority)
post.priority = utils.numberToHex(post.priority);
// fallback
if (!_.isArray(post.topics)) {
post.topics = post.topics ? [post.topics] : [];
}
// format the following options
post.topics = post.topics.map(function (topic) {
// convert only if not hex
return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
});
return post;
};
tx.gasPrice < 0 ||
tx.chainId < 0) {
error = new Error('Gas, gasPrice, nonce or chainId is lower than 0');
}
if (error) {
callback(error);
return Promise.reject(error);
}
try {
var transaction = helpers.formatters.inputCallFormatter(_.clone(tx));
transaction.to = transaction.to || '0x';
transaction.data = transaction.data || '0x';
transaction.value = transaction.value || '0x';
transaction.chainId = utils.numberToHex(transaction.chainId);
// Because tx has no ethereumjs-tx signing options we use fetched vals.
if (!hasTxSigningOptions) {
transactionOptions.common = Common.forCustomChain(
'mainnet',
{
name: 'custom-network',
networkId: transaction.networkId,
chainId: transaction.chainId
},
'petersburg'
);
delete transaction.networkId;
} else {
if (transaction.common) {
error = new Error('Gas, gasPrice, nonce or chainId is lower than 0');
}
if (error) {
callback(error);
return Promise.reject(new Error('"gas" is missing'));
}
try {
tx = helpers.formatters.inputCallFormatter(tx);
var transaction = tx;
transaction.to = tx.to || '0x';
transaction.data = tx.data || '0x';
transaction.value = tx.value || '0x';
transaction.chainId = utils.numberToHex(tx.chainId);
var rlpEncoded = RLP.encode([
Bytes.fromNat(transaction.nonce),
Bytes.fromNat(transaction.gasPrice),
Bytes.fromNat(transaction.gas),
transaction.to.toLowerCase(),
Bytes.fromNat(transaction.value),
transaction.data,
Bytes.fromNat(transaction.chainId || "0x1"),
"0x",
"0x"]);
var hash = Hash.keccak256(rlpEncoded);
var signature = Account.makeSigner(Nat.toNumber(transaction.chainId || "0x1") * 2 + 35)(Hash.keccak256(rlpEncoded), privateKey);
hoverBar (hoverGasPercent) {
const low = [0, 210, 180]
const high = [250, 100, 155]
const w1 = hoverGasPercent
const w2 = 1 - w1
const hoverGasColor = `rgba(${Math.round(low[0] * w1 + high[0] * w2)}, ${Math.round(low[1] * w1 + high[1] * w2)}, ${Math.round(low[2] * w1 + high[2] * w2)}, 1)`
const fast = this.store('main.gasPrice.levels.fast')
const slow = this.store('main.gasPrice.levels.slow')
const top = parseInt(fast, 16) * 4
const bottom = parseInt(slow, 16) / 10
const percentBuffer = Math.round((bottom / top) * 100) / 100
hoverGasPercent = hoverGasPercent + percentBuffer
const hoverGasPrice = utils.numberToHex(Math.round(top * hoverGasPercent))
this.setState({ hoverGasPercent, hoverGasColor, hoverGasPrice })
}
}).forEach(function (key) {
options[key] = utils.numberToHex(options[key]);
});
function createMessage({
recipient,
value,
transactionHash,
bridgeAddress,
expectedMessageLength
}) {
recipient = strip0x(recipient)
assert.strictEqual(recipient.length, 20 * 2)
value = Web3Utils.numberToHex(value)
value = Web3Utils.padLeft(value, 32 * 2)
value = strip0x(value)
assert.strictEqual(value.length, 64)
transactionHash = strip0x(transactionHash)
assert.strictEqual(transactionHash.length, 32 * 2)
bridgeAddress = strip0x(bridgeAddress)
assert.strictEqual(bridgeAddress.length, 20 * 2)
const message = `0x${recipient}${value}${transactionHash}${bridgeAddress}`
assert.strictEqual(message.length, 2 + 2 * expectedMessageLength)
return message
}
formatForRlpEncoding () {
return [this.outputType, this.outputGuard, this.token, utils.numberToHex(this.amount)]
}