diff --git a/lib/index.js b/lib/index.js index 54a9e12..5ea2de4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,6 +13,7 @@ function Crypto() { } function Key() { } function Signature() { } function Hash() { } +function Amount() { } Scalar.setupRandom = (value) => { return setupRandom(value); @@ -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; diff --git a/native/Cargo.lock b/native/Cargo.lock index 0c4bd70..00ab5db 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -269,7 +269,7 @@ dependencies = [ [[package]] name = "cryptonote-raw-crypto" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bindgen 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -293,7 +293,7 @@ dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "cryptonote-account 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "cryptonote-currency 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cryptonote-raw-crypto 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cryptonote-raw-crypto 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "cryptonote-varint 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -481,7 +481,7 @@ dependencies = [ name = "neon-vigcoin" version = "0.2.1" dependencies = [ - "cryptonote-raw-crypto 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cryptonote-raw-crypto 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "cryptonote-wallet 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "neon 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -962,7 +962,7 @@ dependencies = [ "checksum cryptonote-basic 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5daef26938c81c254ffd59e29262dd058a3e22e7059384758c1cf169ab0a3c" "checksum cryptonote-config 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5b4c422c45bf0a1dceb1e1a16f4871656546dfcd590cafbc362718913484327a" "checksum cryptonote-currency 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2450a8ef54a945c3a51ee80ae28a256725699a0c57fb5718579237b6152565a5" -"checksum cryptonote-raw-crypto 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "009e2f4fb8982e5ffad524f9ac00a92a1505c812018082fc669020432f73430c" +"checksum cryptonote-raw-crypto 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "70bcfaec2321029baa90d43786860dfa77fbbc73c1d63cc6fb9951690444d0ba" "checksum cryptonote-varint 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "121a0e47b63f472785fa05a8541953ccb077506135a9abfe925cd1f59b1906d5" "checksum cryptonote-wallet 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "537b43f40fe69ffadd0e5c23452d2dd4d3a120fd5eb5cdb13ba9981a4cdcdebf" "checksum cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "697c714f50560202b1f4e2e09cd50a421881c83e9025db75d15f276616f04f40" diff --git a/native/Cargo.toml b/native/Cargo.toml index aa9c8cc..7c8aa91 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -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" diff --git a/native/src/amount.rs b/native/src/amount.rs new file mode 100644 index 0000000..e736344 --- /dev/null +++ b/native/src/amount.rs @@ -0,0 +1,9 @@ +use cryptonote_raw_crypto::amount::Amount; +use neon::prelude::*; + +pub fn get_penalized(mut cx: FunctionContext) -> JsResult { + let amount = cx.argument::(0)?.value() as u64; + let median_size = cx.argument::(1)?.value() as usize; + let current_block_size = cx.argument::(2)?.value() as usize; + Ok(cx.number(Amount::get_penalized(amount, median_size, current_block_size) as f64)) +} \ No newline at end of file diff --git a/native/src/difficulty.rs b/native/src/difficulty.rs index 18e65eb..16e875e 100644 --- a/native/src/difficulty.rs +++ b/native/src/difficulty.rs @@ -1,5 +1,5 @@ -use cryptonote_raw_crypto::{*}; +use cryptonote_raw_crypto::{difficulty::Difficulty}; use neon::prelude::*; declare_types! { diff --git a/native/src/lib.rs b/native/src/lib.rs index 69f4fa8..e54cc4a 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -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::*; @@ -115,6 +117,7 @@ declare_types! { register_module!(mut cx, { cx.export_class::("Wallet")?; cx.export_class::("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)?; diff --git a/package-lock.json b/package-lock.json index 02ad5ff..60fad08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@vigcoin/neon", - "version": "0.2.2", + "version": "0.2.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5c6a05e..e335c70 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { "name": "@vigcoin/neon", - "version": "0.2.3", + "version": "0.2.4", "description": "", "main": "lib/index.js", "author": "calidion ", "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" } diff --git a/test/amount.js b/test/amount.js new file mode 100644 index 0000000..8d36f91 --- /dev/null +++ b/test/amount.js @@ -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)); + }); +}); \ No newline at end of file