Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated raw transaction paramaters, amount to be accepted in satoshi #27

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@
- Added HD PATH for testnet
- Updated tests to add assertions
- Added constants for base URLs
- Updated node version in CI
- Updated node version in CI
- Updated raw transaction paramaters, amount to be accepted in satoshi
1 change: 0 additions & 1 deletion src/constants/index.js
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
7 changes: 2 additions & 5 deletions src/helper/signTransaction.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
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");
}

//Set transaction input
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);
Expand Down
5 changes: 2 additions & 3 deletions src/helper/utils/generateAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down