Skip to content

Commit

Permalink
add amount support
Browse files Browse the repository at this point in the history
  • Loading branch information
calidion committed Nov 6, 2019
1 parent 808712b commit e5a55ea
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 9 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function Crypto() { }
function Key() { }
function Signature() { }
function Hash() { }
function Amount() { }

Scalar.setupRandom = (value) => {
return setupRandom(value);
Expand Down Expand Up @@ -118,8 +119,13 @@ Hash.check = (buffer, difficulty) => {
return addon.checkHash(buffer, difficulty);
}

Amount.getPenalized = (amount, medianSize, currentBlockSize) => {
return addon.getPenalized(amount, medianSize, currentBlockSize);
}

module.exports.Scalar = Scalar;
module.exports.Crypto = Crypto;
module.exports.Key = Key;
module.exports.Signature = Signature;
module.exports.Hash = Hash;
module.exports.Amount = Amount;
8 changes: 4 additions & 4 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ neon-build = "0.3.1"
[dependencies]
neon = "0.3.1"
cryptonote-wallet = "0.2.0"
cryptonote-raw-crypto = "0.5.6"
cryptonote-raw-crypto = "0.5.7"
hex = "0.3.2"
9 changes: 9 additions & 0 deletions native/src/amount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use cryptonote_raw_crypto::amount::Amount;
use neon::prelude::*;

pub fn get_penalized(mut cx: FunctionContext) -> JsResult<JsNumber> {
let amount = cx.argument::<JsNumber>(0)?.value() as u64;
let median_size = cx.argument::<JsNumber>(1)?.value() as usize;
let current_block_size = cx.argument::<JsNumber>(2)?.value() as usize;
Ok(cx.number(Amount::get_penalized(amount, median_size, current_block_size) as f64))
}
2 changes: 1 addition & 1 deletion native/src/difficulty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use cryptonote_raw_crypto::{*};
use cryptonote_raw_crypto::{difficulty::Difficulty};
use neon::prelude::*;

declare_types! {
Expand Down
3 changes: 3 additions & 0 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ mod key;
mod signature;
mod hash;
mod difficulty;
mod amount;

use scalar::{*};
use key::{*};
use signature::{*};
use hash::{*};
use difficulty::{*};
use amount::{*};

use cryptonote_wallet::{Wallet};
use neon::prelude::*;
Expand Down Expand Up @@ -115,6 +117,7 @@ declare_types! {
register_module!(mut cx, {
cx.export_class::<JsWallet>("Wallet")?;
cx.export_class::<JsDifficulty>("Difficulty")?;
cx.export_function("getPenalized", get_penalized)?;
cx.export_function("getFastHash", get_fast_hash)?;
cx.export_function("getSlowHash", get_slow_hash)?;
cx.export_function("checkHash", check_with_difficulty)?;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "@vigcoin/neon",
"version": "0.2.3",
"version": "0.2.4",
"description": "",
"main": "lib/index.js",
"author": "calidion <[email protected]>",
"license": "GPL-3.0-or-later",
"dependencies": {
"neon-cli": "^0.2.0"
},
"scripts": {
"install": "neon build",
"test": "mocha"
},
"devDependencies": {
"neon-cli": "^0.2.0",
"mocha": "^6.1.4",
"n-readlines": "^1.0.0"
}
Expand Down
13 changes: 13 additions & 0 deletions test/amount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let vigcoin = require("../lib");
let assert = require("assert");
let Amount = vigcoin.Amount;


describe("Test Amount", () => {
it("should test amount", function () {
assert(0 === Amount.getPenalized(0, 1, 2));
assert(2 === Amount.getPenalized(2, 1, 1));
assert(7 === Amount.getPenalized(10, 1000, 1500));
assert(1 === Amount.getPenalized(2, 10, 11));
});
});

0 comments on commit e5a55ea

Please sign in to comment.