diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a7e04..849e7a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,4 +57,5 @@ - Added HD PATH for testnet - Updated tests to add assertions - Added constants for base URLs -- Updated node version in CI \ No newline at end of file +- Updated node version in CI +- Updated raw transaction paramaters, amount to be accepted in satoshi \ No newline at end of file diff --git a/src/constants/index.js b/src/constants/index.js index a1b0e9f..854c380 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -1,5 +1,4 @@ module.exports = { - SATOSHI: 100000000, SOCHAIN_API_KEY: 'F7RKphrzItSQV-MUoPY_S0XIuwTzxFpt', SOCHAIN_BASE_URL: "https://sochain.com/api/v3/", BLOCKCYPHER_BASE_URL: "https://api.blockcypher.com/v1/btc/" diff --git a/src/helper/signTransaction.js b/src/helper/signTransaction.js index 59415f8..280bb7b 100644 --- a/src/helper/signTransaction.js +++ b/src/helper/signTransaction.js @@ -1,17 +1,14 @@ const bitcore = require("bitcore-lib") -const { SATOSHI } = require("../constants/index") const getFeeAndInput = require('./calculateFeeAndInput') async function signTransaction(from, to, amountToSend, URL, privateKey, satPerByte, headers) { - const satoshiToSend = amountToSend * SATOSHI; - const transaction = new bitcore.Transaction(); const { totalAmountAvailable, inputs, fee } = await getFeeAndInput(URL, satPerByte, headers) - if (totalAmountAvailable - satoshiToSend - fee < 0) { + if (totalAmountAvailable - amountToSend - fee < 0) { throw new Error("Balance is too low for this transaction"); } @@ -19,7 +16,7 @@ async function signTransaction(from, to, amountToSend, URL, privateKey, satPerBy transaction.from(inputs); // set the recieving address and the amount to send - transaction.to(to, Math.floor(satoshiToSend)); + transaction.to(to, Math.floor(amountToSend)); // Set change address - Address to receive the left over funds after transfer transaction.change(from); diff --git a/src/helper/utils/generateAddress.js b/src/helper/utils/generateAddress.js index 620a439..b16df74 100644 --- a/src/helper/utils/generateAddress.js +++ b/src/helper/utils/generateAddress.js @@ -2,11 +2,10 @@ const bitcoinjs = require('bitcoinjs-lib') function generateAddress(bip32ExtendedKey, network, index) { - let wallet = "NA"; - wallet = bip32ExtendedKey.derive(index); + let wallet = bip32ExtendedKey.derive(index); const hasPrivkey = !wallet.isNeutered(); - let privkey = "NA"; + let privkey if (hasPrivkey) { privkey = wallet.toWIF(); } diff --git a/test/constants.js b/test/constants.js index c254964..f96ed7a 100644 --- a/test/constants.js +++ b/test/constants.js @@ -18,7 +18,7 @@ module.exports = { TRANSFER_BTC: { BTC_RECEIVER: 'tb1qt3vyrqgy7emqcr8sjr39zcjdca7grfer7lvxhp', // address at test index 1 - BTC_AMOUNT: 0.00001 + BTC_AMOUNT: 1000 }, BITCOIN_NETWORK: { MAINNET: 'MAINNET',