How to use the ethereumjs-util.toBuffer function in ethereumjs-util

To help you get started, we’ve selected a few ethereumjs-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gonetwork-project / gonetwork-state-channel / test / throughput / client1.js View on Github external
p2pClient.on('status-changed', (s) => {
  // console.log('STATUS', s)
  if (s === 'connected') {
    start = Date.now();
    for (var i = 0; i < 1000; i++) {
      transferredAmount = transferredAmount.add(new util.BN(1));
      engine.sendDirectTransfer(util.toBuffer(acct4), transferredAmount);
      //var msg = sendQueue[sendQueue.length -1];
    }
    end = Date.now();
    cl("Direct Transfers Sent Per SECOND per USER " + 1000 / ((end - start) / 1000));
  }
}
)
github matter-labs / PlasmaContract / test / buyout.js View on Github external
assert(exitRecord[6].toNumber() === 0)
        assert(exitRecord[7] === true)
        assert(exitRecord[8] === false)

        //now lets offer a buyoyt for half of the amount
        // function publishPreacceptedBuyout(
        //     bytes22 _index,
        //     uint256 _amount,
        //     address _beneficiary,
        //     uint8 v,
        //     bytes32 r, 
        //     bytes32 s
        // )

        const valueBuffer = (new BN(50)).toBuffer("be", 32)
        const dataToSign = Buffer.concat([ethUtil.toBuffer(exitRecordHash), valueBuffer, ethUtil.toBuffer(bob)])
        const hashToSign = ethUtil.hashPersonalMessage(dataToSign)
        const signature = ethUtil.ecsign(hashToSign, aliceKey)
        const {v, r, s} = signature
        let oldBalanceAlice = await web3.eth.getBalance(alice);
        submissionReceipt = await plasma.publishPreacceptedBuyout(
            exitRecordHash,
            50,
            bob,
            v,
            ethUtil.bufferToHex(r),
            ethUtil.bufferToHex(s),
            {from: bob, value: 50})
        assert(submissionReceipt.logs.length == 1);
        let offer = await plasma.exitBuyoutOffers(exitRecordHash);
        assert(offer[1] === bob);
        assert(offer[0].toString(10) === "50");
github ethereumjs / ethereumjs-block / test / header.ts View on Github external
function compareDefaultHeader(st: tape.Test, header: BlockHeader) {
      st.deepEqual(header.parentHash, utils.zeros(32))
      st.equal(header.uncleHash.toString('hex'), utils.KECCAK256_RLP_ARRAY_S)
      st.deepEqual(header.coinbase, utils.zeros(20))
      st.deepEqual(header.stateRoot, utils.zeros(32))
      st.equal(header.transactionsTrie.toString('hex'), utils.KECCAK256_RLP_S)
      st.equal(header.receiptTrie.toString('hex'), utils.KECCAK256_RLP_S)
      st.deepEqual(header.bloom, utils.zeros(256))
      st.deepEqual(header.difficulty, Buffer.from([]))
      st.deepEqual(header.number, utils.toBuffer(1150000))
      st.deepEqual(header.gasLimit, Buffer.from('ffffffffffffff', 'hex'))
      st.deepEqual(header.gasUsed, Buffer.from([]))
      st.deepEqual(header.timestamp, Buffer.from([]))
      st.deepEqual(header.extraData, Buffer.from([]))
      st.deepEqual(header.mixHash, utils.zeros(32))
      st.deepEqual(header.nonce, utils.zeros(8))
    }
github kyokan / plasma / rpc-test-client / index.js View on Github external
toRpc() {
        const res = {
            blockNum: toRPC(this.blockNum),
            txIdx: toRPC(this.txIdx),
            outIdx: toRPC(this.outIdx),
            owner: ejs.toBuffer(this.owner),
            depositNonce: toRPC(this.depositNonce)
        };
        return res;
    }
github OpenST / openst-contracts / test / delayed_recovery_module / utils.js View on Github external
function signResetRecoveryOwner(
  recoveryModuleAddress, oldRecoveryOwner, newRecoveryOwner, recoveryOwnerPrivateKey,
) {
  const resetRecoveryOwnerHash = hashRecoveryModuleResetOwner(
    recoveryModuleAddress, oldRecoveryOwner, newRecoveryOwner,
  );

  const signature = EthUtils.ecsign(
    EthUtils.toBuffer(resetRecoveryOwnerHash),
    EthUtils.toBuffer(recoveryOwnerPrivateKey),
  );

  return {
    resetRecoveryOwnerHash,
    signature,
  };
}
github ethereumjs / ethereumjs-block / test / difficulty.ts View on Github external
Object.keys(data).forEach(function(i) {
    if (i !== 'homestead' && typeof data[i] === 'string') {
      data[i] = isHexPrefixed(data[i]) ? new BN(utils.toBuffer(data[i])) : new BN(data[i])
    }
  })
}
github MetaMask / eth-json-rpc-middleware / providerEngineSubproviderAsMiddleware.js View on Github external
function toBufferBlock (jsonBlock) {
  return {
    number:           ethUtil.toBuffer(jsonBlock.number),
    hash:             ethUtil.toBuffer(jsonBlock.hash),
    parentHash:       ethUtil.toBuffer(jsonBlock.parentHash),
    nonce:            ethUtil.toBuffer(jsonBlock.nonce),
    sha3Uncles:       ethUtil.toBuffer(jsonBlock.sha3Uncles),
    logsBloom:        ethUtil.toBuffer(jsonBlock.logsBloom),
    transactionsRoot: ethUtil.toBuffer(jsonBlock.transactionsRoot),
    stateRoot:        ethUtil.toBuffer(jsonBlock.stateRoot),
    receiptsRoot:     ethUtil.toBuffer(jsonBlock.receiptRoot || jsonBlock.receiptsRoot),
    miner:            ethUtil.toBuffer(jsonBlock.miner),
    difficulty:       ethUtil.toBuffer(jsonBlock.difficulty),
    totalDifficulty:  ethUtil.toBuffer(jsonBlock.totalDifficulty),
    size:             ethUtil.toBuffer(jsonBlock.size),
    extraData:        ethUtil.toBuffer(jsonBlock.extraData),
    gasLimit:         ethUtil.toBuffer(jsonBlock.gasLimit),
    gasUsed:          ethUtil.toBuffer(jsonBlock.gasUsed),
    timestamp:        ethUtil.toBuffer(jsonBlock.timestamp),
github ethereumjs / ethereumjs-vm / examples / run-blockchain / index.ts View on Github external
async function putBlocks(blockchain: any, hardfork: string, testData: any) {
  for (const blockData of testData.blocks) {
    const block = new Block(utils.toBuffer(blockData.rlp), { hardfork })
    await promisify(blockchain.putBlock.bind(blockchain))(block)
  }
}
github BANKEX / PlasmaETHexchange / app / helpers / getAllUTXOsForAddress.js View on Github external
async function getUTXOforAddressWithIndex(addressString, cb) {
        addressString = ethUtil.addHexPrefix(addressString)
        if (!ethUtil.isValidAddress(addressString)){
            cb(true, null);
        }
        address = ethUtil.toBuffer(addressString);
        const utxos = [];
        const start = Buffer.concat([utxoIncludingAddressPrefix,
            address,
            Buffer.alloc(blockNumberLength), 
            Buffer.alloc(txNumberLength), 
            Buffer.alloc(txOutputNumberLength)])
        const stop = Buffer.concat([utxoIncludingAddressPrefix,
            address,
            Buffer.from("ff".repeat(blockNumberLength), 'hex'), 
            Buffer.from("ff".repeat(txNumberLength), 'hex'),
            Buffer.from("ff".repeat(txOutputNumberLength), 'hex')])
        const sliceStart = utxoIncludingAddressPrefix.length + address.length;
        levelDB.createReadStream({gte: start,
                                    lte: stop,
                                    reversed:true})
        .on('data', function (data) {