Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Upgrade CI to GH Actions #23

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build
on:
push:
branches:
- master
tags:
- '*'
pull_request:
types: [opened, reopened, synchronize]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
- uses: actions/checkout@v1
- run: npm install
- run: npm run lint

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
- uses: actions/checkout@v1
- run: npm install
- run: npm run coverage
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 13.x, 14.x]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v1
- run: npm install
- run: npm run test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
package-lock.json
package-lock.json
.nyc_output
coverage
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
semi: false
singleQuote: true
trailingComma: none
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

56 changes: 35 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# SYNOPSIS
[![NPM Package](https://img.shields.io/npm/v/ethashjs.svg?style=flat-square)](https://www.npmjs.org/package/ethashjs)
[![Build Status](https://travis-ci.org/ethereumjs/ethashjs.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereumjs/ethashjs)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethashjs.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethashjs)
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode

Implements [Ethash](https://github.com/ethereum/wiki/wiki/Ethash)
[![NPM Package](https://img.shields.io/npm/v/ethashjs.svg)](https://www.npmjs.org/package/ethashjs)
[![Actions Status](https://github.com/ethereumjs/ethashjs/workflows/Build/badge.svg)](https://github.com/ethereumjs/ethashjs/actions)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethashjs.svg)](https://coveralls.io/r/ethereumjs/ethashjs)
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg)](https://gitter.im/ethereum/ethereumjs-lib)

# CONTACT
[Scrollback](https://scrollback.io/ethereumjs/all/all-messages) or #ethereumjs on freenode
Implements [Ethash](https://github.com/ethereum/wiki/wiki/Ethash).

# INSTALL

`npm install ethashjs`

# USAGE

```javascript
const Ethash = require('ethashjs')
const Block = require('ethereumjs-block')
Expand All @@ -23,61 +23,75 @@ var cacheDB = levelup('', {
db: memdown
})

var ethash = new Ethash(cacheDB);
var validblockRlp = "f90667f905fba0a8d5b7a4793baaede98b5236954f634a0051842df6a252f6a80492fd888678bda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0f93c8db1e931daa2e22e39b5d2da6fb4074e3d544094857608536155e3521bc1a0bb7495628f9160ddbcf6354380ee32c300d594e833caec3a428041a66e7bade1a0c7778a7376099ee2e5c455791c1885b5c361b95713fddcbe32d97fd01334d296b90100000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000400000000000000000000000000000000000000000000000000000008302000001832fefd882560b84559c17b9b9040001020304050607080910111213141516171819202122232410000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000a09c7b47112a3afb385c12924bf6280d273c106eea7caeaf5131d8776f61056c148876ae05d46b58d1fff866f864800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d8785012a05f200801ba01d2c92cfaeb04e53acdff2b5d42005ff6aacdb0105e64eb8c30c273f445d2782a01e7d50ffce57840360c57d94977b8cdebde614da23e8d1e77dc07928763cfe21c0"
var ethash = new Ethash(cacheDB)
var validblockRlp =
'f90667f905fba0a8d5b7a4793baaede98b5236954f634a0051842df6a252f6a80492fd888678bda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0f93c8db1e931daa2e22e39b5d2da6fb4074e3d544094857608536155e3521bc1a0bb7495628f9160ddbcf6354380ee32c300d594e833caec3a428041a66e7bade1a0c7778a7376099ee2e5c455791c1885b5c361b95713fddcbe32d97fd01334d296b90100000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000400000000000000000000000000000000000000000000000000000008302000001832fefd882560b84559c17b9b9040001020304050607080910111213141516171819202122232410000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000a09c7b47112a3afb385c12924bf6280d273c106eea7caeaf5131d8776f61056c148876ae05d46b58d1fff866f864800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d8785012a05f200801ba01d2c92cfaeb04e53acdff2b5d42005ff6aacdb0105e64eb8c30c273f445d2782a01e7d50ffce57840360c57d94977b8cdebde614da23e8d1e77dc07928763cfe21c0'

var validblock = new Block(new Buffer(validblockRlp, 'hex'))
var validblock = new Block(Buffer.from(validblockRlp, 'hex'))

ethash.verifyPOW(validblock, function (result) {
console.log(result)
})
```

# BROWSER
Yep, You can [browserify](http://browserify.org/) it.
# BROWSER

Yep, you can [browserify](http://browserify.org/) it.

# API

- [`new Ethash([cacheDB])`](#newethashcachedb)
- [`ethash.verifyPOW(block, cb)`](#ethashverifypowblock-cb)
- [`ethash.mkcache(cacheSize, seed)`](#ethashmkcachecachesize-seed)
- [`ethash.run(val, nonce, fullsize)`](#ethashrunval-nonce-fullsize)

### `new Ethash([cacheDB])`

Creates a new instance of `Ethash`.

**Parameters**

- `cacheDB` - an instance of a levelup db which is used to store the cache(s)

### `ethash.verifyPOW(block, cb)`

Verifies the POW on a block and its uncles

**Parameters**
**Parameters**

- `block` - the [block](https://github.com/ethereum/ethereumjs-block) to verify
- `cb` - the callback which is given a `Boolean` determining the validaty of the block
- `cb` - the callback which is given a `Boolean` determining the validaty of the block

### `ethash.mkcache(cacheSize, seed)`
Creates a cache. NOTE: this is automatically done for in - [`ethash.verifyPOW(block, cb)`](#ethashverifypowblock-cb) so you do not need to use this function if you are just validating blocks

**Parameters**
Creates a cache. NOTE: this is automatically done for in - [`ethash.verifyPOW(block, cb)`](#ethashverifypowblock-cb) so you do not need to use this function if you are just validating blocks

**Parameters**

- `cachSize` - the size of the cach
- `seed` - the seed as a `Buffer`


### `ethash.run(val, nonce, fullsize)`

Runs ethash on a give val/nonce pair. NOTE: you need to run [`ethash.mkcache(cacheSize, seed)`](#ethashverifypowcachesize-seed) first before using this function.

**Parameters**
**Parameters**

- `val` - value to run ethash on e.g. the header hash
- `nonce` - the nonce used for this hash attempt
- `fullsize` - the fullsize of the cache.

**Return**
and `Object` containing
- `hash` - the hash of the value
**Returns**

An `Object` containing:

- `hash` - the hash of the value
- `mix` - the mis result

# TESTS

`npm test`

# LICENSE

[MPL-2.0](https://www.mozilla.org/MPL/2.0/)
4 changes: 2 additions & 2 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Ethash = require('../index.js')

var ethash = new Ethash()
// make the 1000 cache items with a seed of 0 * 32
ethash.mkcache(1000, new Buffer(32).fill(0))
ethash.mkcache(1000, Buffer.alloc(32).fill(0))

var result = ethash.run(new Buffer('test'), new Buffer([0]), 1000)
var result = ethash.run(Buffer.from('test'), Buffer.from([0]), 1000)
console.log(result.hash.toString('hex'))
7 changes: 5 additions & 2 deletions example/rawExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ethash.prototype.verifySubmit = function (number, headerHash, nonce, cb) {
this.loadEpoc(number, function () {
console.log('EPOC set')
console.log(self.seed.toString('hex'))
var a = self.run(headerHash, new Buffer(nonce, 'hex'))
var a = self.run(headerHash, Buffer.from(nonce, 'hex'))
cb(a.hash)
})
}
Expand All @@ -19,7 +19,10 @@ var cacheDB = levelup('', {

var ethash = new Ethash(cacheDB)

var header = Buffer('0e2887aa1a0668bf8254d1a6ae518927de99e3e5d7f30fd1f16096e2608fe05e', 'hex')
var header = Buffer.from(
'0e2887aa1a0668bf8254d1a6ae518927de99e3e5d7f30fd1f16096e2608fe05e',
'hex'
)

ethash.verifySubmit(35414, header, 'e360b6170c229d15', function (result) {
console.log(result.toString('hex'))
Expand Down
Loading