Giter Site home page Giter Site logo

rainblock / ethereum-block Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 0.0 384 KB

☔️📦 An Ethereum Block Decoder with Native Bindings

License: Apache License 2.0

Python 2.35% JavaScript 4.96% C 27.46% TypeScript 65.23%
ethereum block bigint native n-api

ethereum-block's Introduction

☔️📦 RainBlock's Ethereum Block Decoder

NPM Package Build Status Coverage Status

@rainblock/ethereum-block is a decoder for the Ethereum block format. It uses native bindings to improve the performance of transaction verification. A fallback is provided when bindings cannot be used. Native bindings provide about a 30-50% speedup over pure javascript. Unlike the EthereumJS library the API exports BigInts. Typescript definitions are provided.

Install

Add @rainblock/ethereum-block to your project with:

npm install @rainblock/ethereum-block

Usage

Basic API documentation can be found here, but the following example shows basic use:

import {decodeBlock} from '@rainblock/ethereum-block';

// Block decoded to RLP format by RLP-Stream
const rlpBlock : RlpList = RlpDecode(raw);
const block : EthereumBlock = decodeBlock(rlpBlock);

Benchmarks

Benchmarks can be run by executing npm run benchmark from the package directory.

An example run on a 2016 15-inch Macbook:

no-op: 795262551±0.22% ops/s 1.26±0.013 ns/op (91 runs)
decodeBlock: 159±0.95% ops/s 6304084.39±271699.554 ns/op (79 runs)
decodeHeader: 305267±5.32% ops/s 3275.82±799.828 ns/op (81 runs)
decodeTx (js): 8450±1.97% ops/s 118344.55±11168.747 ns/op (88 runs)
decodeTx (native): 12455±1.08% ops/s 80287.49±4157.742 ns/op (89 runs)

Native is about 30-50% faster than the pure js version.

ethereum-block's People

Contributors

no2chem avatar soujanyaponnapalli avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ethereum-block's Issues

encodeHeaderAsRLP mixHash and nonce

encodeHeaderAsRlp returns different values for mixHash and nonce while rlp encoding block headers:

For encoding the genesisBlock header:
Expected:

mixHash:  <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>,
nonce:  <Buffer 00 00 00 00 00 00 00 42> 

Received:

mixHash:  <Buffer >,
nonce:  <Buffer 42> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.