All Projects → jaimehgb → RaiBlocksWebAssemblyPoW

jaimehgb / RaiBlocksWebAssemblyPoW

Licence: BSD-3-Clause license
WebAssembly Nanocurrency PoW implementation

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to RaiBlocksWebAssemblyPoW

jNano
A comprehensive Java library for the Nano cryptocurrency.
Stars: ✭ 25 (-24.24%)
Mutual labels:  nano, proof-of-work, nano-currency, nanocurrency
RaiBlocksPHP
A bunch of PHP methods to build and sign transactions
Stars: ✭ 20 (-39.39%)
Mutual labels:  nano, nano-currency, nanocurrency
nano-rs
An implementation of Nano in Rust using Tokio
Stars: ✭ 29 (-12.12%)
Mutual labels:  nano, nano-currency, nanocurrency
nanook
Ruby library for making and receiving payments and managing a nano currency node
Stars: ✭ 17 (-48.48%)
Mutual labels:  nano, nano-currency, nanocurrency
Nano.Net
A .NET library for Nano
Stars: ✭ 19 (-42.42%)
Mutual labels:  nano, nanocurrency
MyNanoNinja
The perfect tool for Nano representatives lists and network statistics
Stars: ✭ 33 (+0%)
Mutual labels:  nano, nanocurrency
Nault
⚡ The most advanced Nano wallet with focus on security, speed and robustness
Stars: ✭ 228 (+590.91%)
Mutual labels:  nano, nanocurrency
hashseq
A simple proof of work, mainly designed to mitigate DDoS attacks.
Stars: ✭ 20 (-39.39%)
Mutual labels:  pow, proof-of-work
py-cryptonight
Python Cryptonight binding / extension. Monero hash function, proof-of-work, cn_slow_hash()
Stars: ✭ 20 (-39.39%)
Mutual labels:  pow, proof-of-work
Nano Node
Nano is a cryptocurrency
Stars: ✭ 3,336 (+10009.09%)
Mutual labels:  nano, nanocurrency
nano-update-tx-work
Rebroadcast unconfirmed Nano transactions with higher proof-of-work (PoW) to help restart expired elections.
Stars: ✭ 14 (-57.58%)
Mutual labels:  nano, nanocurrency
nano-vanity
A NANO vanity address generator (supports OpenCL)
Stars: ✭ 83 (+151.52%)
Mutual labels:  nano, nano-currency
reblocks
React Components for Nano cryptocurrency (formerly RaiBlocks) - including Payments via Brainblocks
Stars: ✭ 21 (-36.36%)
Mutual labels:  nano, nanocurrency
rai
🗿 rai is a pythonic client for interacting with Raiblocks nodes
Stars: ✭ 21 (-36.36%)
Mutual labels:  nano, nano-currency
windows-container
Docker files for various Windows Container build
Stars: ✭ 30 (-9.09%)
Mutual labels:  nano
privcy
Official Repository for PRiVCY Coin $PRiV
Stars: ✭ 26 (-21.21%)
Mutual labels:  pow
nano-node-docker
Setup a fully automated NANO cryptocurrency node as part of an dockerized stack with fast-syncing and easy SSL support.
Stars: ✭ 77 (+133.33%)
Mutual labels:  nanocurrency
blockchain consensus algorithm
代码实现五种区块链共识算法 The code implements five blockchain consensus algorithms
Stars: ✭ 251 (+660.61%)
Mutual labels:  pow
TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an Arduino, such as Nano, UNO, Mega, etc. It now supports 16 ISR-based timers, while consuming only 1 hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behavin…
Stars: ✭ 76 (+130.3%)
Mutual labels:  nano
Awesome Cheatsheets
超级速查表 - 编程语言、框架和开发工具的速查表,单个文件包含一切你需要知道的东西 ⚡
Stars: ✭ 7,930 (+23930.3%)
Mutual labels:  nano

RaiBlocksWebAssemblyPoW

Overview

This repo contains a simple RaiBlocks PoW implementation compiled to WebAssembly to boost its performance on browsers. That's been done using emscripten. Compiling to WebAssembly, the result is around 10 times faster than a pure JS PoW implementation (e.g.: RaiBlocksJS).
This basically makes possible to generate proofs of work on modern browsers in a reasonable time. So yep, lets see...


Installation and usage

All the PoW thing takes place at functions.cpp. There is the main loop which calculates stuff and a function which can be called from JS and runs the loop (the iterations function).

To compile it to webassembly you need to install emscripten:

git clone https://github.com/juj/emsdk.git
cd emsdk

# on Linux or Mac OS X
./emsdk install --build=Release sdk-incoming-64bit binaryen-master-64bit
./emsdk activate --global --build=Release sdk-incoming-64bit binaryen-master-64bit

# on Windows
emsdk install --build=Release sdk-incoming-64bit binaryen-master-64bit
emsdk activate --global --build=Release sdk-incoming-64bit binaryen-master-64bit

Then:

# on Linux or Mac OS X
source ./emsdk_env.sh

# on Windows
emsdk_env.bat

(From here)

With that done, at the repo folder run this:

emcc functions.cpp blake2/blake2b-ref.cpp  -o pow.js -s WASM=1 -std=gnu++11 -O3 -s EXPORTED_FUNCTIONS="['_launchPoW']"

It will output 2 files: pow.js and pow.wasm, place those files together somewhere and include pow.js in your html as usual.

To call the "launchPoW" function you can do 2 things:

var hash = "SOME_RAIBLOCKS_HASH_HERE_AND_STUFF_HEX_ENCODED_32_BYTES";
var pow = Module.ccall("launchPoW", "string", ["string"], hash);
console.log(pow);

OR

var hash = "SOME_RAIBLOCKS_HASH_HERE_AND_STUFF_HEX_ENCODED_32_BYTES";
var calculatePoW = Module.cwrap("launchPoW", "string", ["string"]);
var pow = calculatePoW(hash);
console.log(pow);

I prefer the second option :D

What that function does is to try to find a valid PoW in 10,000,000 iterations. If it finds it it will return the result as a hex string. If it does not find it, will return a 64bit hex 0 (0000000000000000). Keep that in mind :P

BUT ... but. You cannot call the function before WebAssembly is loaded and compiled. How do we know when that happens? Well, we have:

Module['onRuntimeInitialized'] = function() {
    // Its all fine here
    // do stuff
    // ...
}

If Module['onRuntimeInitialized'] is a function it will be called once its all ready to run. So yeah, be aware of that :)
There are more docs about the Module API and emscripten itself here http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/index.html.


Compatibility

This implementation has just been tested in Chrome (Windows 64bit), Firefox (Windows 64bit) and Chrome (Android) but should also work in all the devices supporting WASM.


Examples

I've made two examples for you to see/use/improve/whatever. They are at the /examples folder. One of them uses webworkers to multithread this stuff. The other one is single threaded.
Yeah, take a look there :P

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].