Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function scenarioNodeVoteCast({nodeAddress, minipoolAddress, gas, signingAddress = nodeAddress, emptyVoteMessage = false, gotoEpochSecondQuarter = true, expectCanVote}){
const casper = await CasperInstance();
const rocketNodeValidator = await RocketNodeValidator.deployed();
// Get the current validator index and vote
let currentEpoch = parseInt(await casper.methods.current_epoch().call({from: nodeAddress}));
let validatorIndex = parseInt(await casper.methods.validator_indexes(minipoolAddress).call({from: nodeAddress}));
let targetHash = Buffer.from(removeTrailing0x(await casper.methods.recommended_target_hash().call({from: nodeAddress})), 'hex');
let sourceEpoch = parseInt(await casper.methods.recommended_source_epoch().call({from: nodeAddress}));
// RLP encode the required vote message
let sigHash = $web3.utils.keccak256(abi.encodePacked(RLP.encode([validatorIndex,targetHash,currentEpoch,sourceEpoch])));
// Sign it
let signature = signRaw(sigHash, getGanachePrivateKey(signingAddress));
// Combine and pad to 32 int length (same as casper python code)
let combinedSig = Buffer.from(paddy(signature.v, 64) + paddy(signature.r, 64) + paddy(signature.s, 64), 'hex');
// RLP encode the message params now
let voteMessage = !emptyVoteMessage ? RLP.encode([validatorIndex, targetHash, currentEpoch, sourceEpoch, combinedSig]) : '';
// Proceed to second quarter of epoch to allow voting
if (gotoEpochSecondQuarter) {
let blockNumber = parseInt(await $web3.eth.getBlockNumber());
let epochLength = parseInt(await casper.methods.EPOCH_LENGTH().call({from: nodeAddress}));
let epochBlockNumber = blockNumber % epochLength;
let epochFirstQuarter = Math.floor(epochLength / 4);
let blockAmount = (epochFirstQuarter - epochBlockNumber) + 1;
if (blockAmount > 0) await mineBlockAmount(blockAmount);
}
block.stateRoot,
block.transactionsRoot,
block.receiptsRoot,
block.logsBloom,
Web3Utils.toBN(block.difficulty),
Web3Utils.toBN(block.number),
block.gasLimit,
block.gasUsed,
Web3Utils.toBN(block.timestamp),
newExtraData, // Off-chain signed block
block.mixHash,
block.nonce
];
// Encode the offchain signed header
const offchainSignedHeader = '0x' + rlp.encode(newSignedHeader).toString('hex');
const offchainHeaderHash = Web3Utils.sha3(offchainSignedHeader);
await clique.SubmitBlock(TESTCHAINID, unsignedHeader, offchainSignedHeader, storage.address).should.be.rejected;
})
evaluatedTxs.map(async ({ txHash, sender, serializedTx, serializedReceipt }, i) => {
await receiptTrie.put(sha3Buffer(i.toString()), serializedReceipt);
await txTrie.put(sha3Buffer(i.toString()), serializedTx);
// Add lookup for transactions. txHash => [blockHash, txIndex, from].
await this.db.put(txHash, rlp.encode([blockHash, Buffer.from(i.toString()), sender.toBuffer()]));
}),
);
EV.trieValue = (path, value, parentNodes, root) => {
try{
var currentNode;
var len = parentNodes.length;
var rlpTxFromPrf = parentNodes[len - 1][parentNodes[len - 1].length - 1];
var nodeKey = root;
var pathPtr = 0;
path = path.toString('hex')
for (var i = 0 ; i < len ; i++) {
currentNode = parentNodes[i];
if(!nodeKey.equals( new Buffer(sha3(rlp.encode(currentNode)),'hex'))){
console.log("nodeKey != sha3(rlp.encode(currentNode)): ", nodeKey, new Buffer(sha3(rlp.encode(currentNode)),'hex'))
return false;
}
if(pathPtr > path.length){
console.log("pathPtr >= path.length ", pathPtr, path.length)
return false
}
switch(currentNode.length){
case 17://branch node
if(pathPtr == path.length){
if(currentNode[16] == rlp.encode(value)){
return true;
}else{
console.log('currentNode[16],rlp.encode(value): ', currentNode[16], rlp.encode(value))
return false
const en_key = (key:string):string=>{
return rlp.encode(key);
}
return this[fieldName]
}
let dataToEncode = [
this.prevHash instanceof Buffer ?
this.prevHash :
ethUtil.addHexPrefix(this.prevHash),
this.prevBlock,
ethUtil.toBuffer(this.tokenId),
this.newOwner,
this.type,
]
if (!(excludeSignature)) {
dataToEncode.push(this.signature)
}
this[fieldName] = RLP.encode(dataToEncode)
return this[fieldName]
}
return this[fieldName]
}
let dataToEncode = [
this.prevHash instanceof Buffer ?
this.prevHash :
ethUtil.addHexPrefix(this.prevHash),
this.prevBlock,
ethUtil.toBuffer(this.tokenId),
this.newOwner,
this.type,
]
if (!(excludeSignature)) {
dataToEncode.push(this.signature)
}
this[fieldName] = RLP.encode(dataToEncode)
return this[fieldName]
}
public rlpBytes(): Buffer {
return RLP.encode(this.toEncodeObject());
}
const recipient = bs58check.decode(recipients[0].replace('ak_', ''))
const txObj = {
tag: this.toHexBuffer(12),
version: this.toHexBuffer(1),
sender_id: Buffer.concat([this.toHexBuffer(1), Buffer.from(sender, 'hex')]),
recipient_id: Buffer.concat([this.toHexBuffer(1), recipient]),
amount: this.toHexBuffer(values[0]),
fee: this.toHexBuffer(fee),
ttl: this.toHexBuffer(10000),
nonce: this.toHexBuffer(nonce),
payload: Buffer.from('')
}
const txArray = Object.keys(txObj).map(a => txObj[a])
const rlpEncodedTx = rlp.encode(txArray)
const preparedTx = 'tx_' + bs58check.encode(rlpEncodedTx)
return {
transaction: preparedTx,
networkId: this.defaultNetworkId
}
}
async function deployContract(solcOutput, contractName, ctorArgs) {
const actualName = contractName;
const bytecode = solcOutput.contracts[actualName].bytecode;
const abi = solcOutput.contracts[actualName].interface;
const myContract = new web3.eth.Contract(JSON.parse(abi));
const deploy = myContract.deploy({data:"0x" + bytecode, arguments: ctorArgs});
let address = "0x" + web3.utils.sha3(RLP.encode([sender,nonce])).slice(12).substring(14);
address = web3.utils.toChecksumAddress(address);
await sendTx(deploy);
myContract.options.address = address;
return [address,myContract];
}