From 812d9e4344158ab2e03ac17a8ca058718fbfbcc0 Mon Sep 17 00:00:00 2001 From: Suraj Singla Date: Fri, 16 Sep 2022 13:41:25 +0530 Subject: [PATCH] UTXO calculation fix --- CHANGELOG.md | 8 +++++++- package-lock.json | 17 +++++++++++++++-- package.json | 7 ++++--- src/helper/calculateFeeAndInput.js | 3 ++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 668e579..7741873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,4 +32,10 @@ ##### UTXO calculation fix -- UTXO.satoshi calculation fix. \ No newline at end of file +- UTXO.satoshi calculation fix. + +### 1.2.3 (2022-09-16) + +##### UTXO calculation fix + +- UTXO.satoshi calculation and adding package `satoshi-bitcoin`. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5d027fd..b871544 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@getsafle/vault-bitcoin-controller", - "version": "1.2.2", + "version": "1.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -222,6 +222,11 @@ "safe-buffer": "^5.0.1" } }, + "big.js": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-3.2.0.tgz", + "integrity": "sha512-+hN/Zh2D08Mx65pZ/4g5bsmNiZUuChDiQfTUQ7qJr4/kuopCr88xZsAXv6mBoZEsUI4OuGHlX59qE94K2mMW8Q==" + }, "binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -2233,6 +2238,14 @@ "events": "^3.0.0" } }, + "satoshi-bitcoin": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/satoshi-bitcoin/-/satoshi-bitcoin-1.0.5.tgz", + "integrity": "sha512-iCUOSe8yTOqetYcj/n4ziv0psqRMRZT4+YhcMrQIYpjnx3Pgn9uiTlaUItNMMB/0sldINEGkJvxwTW55OfrYPg==", + "requires": { + "big.js": "^3.1.3" + } + }, "semver": { "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", @@ -2800,4 +2813,4 @@ "dev": true } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 96e5615..c290b6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@getsafle/vault-bitcoin-controller", - "version": "1.2.2", + "version": "1.2.3", "description": "", "engines": { "node": ">= 10" @@ -31,7 +31,8 @@ "bitcoinjs-lib": "^5.2.0", "bitcoinjs-message": "^2.2.0", "bitcore-lib": "^8.25.10", - "obs-store": "^4.0.3" + "obs-store": "^4.0.3", + "satoshi-bitcoin": "^1.0.5" }, "devDependencies": { "@metamask/eslint-config": "^4.0.0", @@ -41,4 +42,4 @@ "eslint-plugin-node": "^11.1.0", "mocha": "^8.1.3" } -} \ No newline at end of file +} diff --git a/src/helper/calculateFeeAndInput.js b/src/helper/calculateFeeAndInput.js index 8688b51..eeff59a 100644 --- a/src/helper/calculateFeeAndInput.js +++ b/src/helper/calculateFeeAndInput.js @@ -1,4 +1,5 @@ const axios = require('axios') +var sb = require("satoshi-bitcoin"); const { SATOSHI } = require("../config/index") async function getFeeAndInput(URL, satPerByte) { @@ -13,7 +14,7 @@ async function getFeeAndInput(URL, satPerByte) { let inputs = []; utxos.data.data.txs.forEach(async (element) => { let utxo = {}; - utxo.satoshis = Math.ceil(parseFloat(element.value) * SATOSHI); + utxo.satoshis = sb.toSatoshi(parseFloat(element.value)); utxo.script = element.script_hex; utxo.address = utxos.data.data.address; utxo.txId = element.txid;