Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #644 from rsksmart/hotfix/btcTx
Browse files Browse the repository at this point in the history
  • Loading branch information
patogallaiovlabs authored Mar 23, 2021
2 parents 308cf1d + f4790b6 commit 51a0b4e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/common/transaction/btccoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const getTransactionInputs = async ({
* @returns {object} Transaction builder
*/
export const buildTransaction = ({
inputs, fromAddress, addressType, toAddress, netType, amount, fees, publicKey,
inputs, fromAddress, addressType, toAddress, netType, amount, fees, privateKey,
}) => {
const network = netType === 'Mainnet' ? bitcoin.networks.bitcoin : bitcoin.networks.testnet;
const cost = amount + fees;
Expand All @@ -63,6 +63,8 @@ export const buildTransaction = ({
// Calculate redeem script
let redeemScript = null;
if (addressType === BtcAddressType.segwit) {
const buf = Buffer.from(privateKey, 'hex');
const { publicKey } = bitcoin.ECPair.fromPrivateKey(buf, { network });
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: publicKey, network });
const p2sh = bitcoin.payments.p2sh({ redeem: p2wpkh, network });
redeemScript = p2sh.redeem.output;
Expand Down
4 changes: 2 additions & 2 deletions src/common/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Transaction {
console.log('Transaction.processTransaction start');
let result = null;
const {
symbol, privateKey, netType, sender, receiver, value, data, memo, gasFee, contractAddress, addressType, publicKey,
symbol, privateKey, netType, sender, receiver, value, data, memo, gasFee, contractAddress, addressType,
} = this;
try {
if (symbol === 'BTC') {
Expand All @@ -67,7 +67,7 @@ export default class Transaction {
netType,
amount,
fees,
publicKey,
privateKey,
});
result = btc.signTransaction({
transactionBuilder, inputs, privateKey, netType, addressType,
Expand Down
8 changes: 4 additions & 4 deletions src/common/wallet/btccoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Coin {
this.path = `m/44'/${this.coinType}'/${this.account}'/0/0`;
}

deriveSegwit= (root, network) => {
deriveSegwit = (root, network) => {
const path = `m/84'/${this.coinType}'/${this.account}'/0/0`;
const keyPair = root.derivePath(path);
const { address } = payments.p2wpkh({ pubkey: keyPair.publicKey, network });
Expand Down Expand Up @@ -119,9 +119,9 @@ export default class Coin {
address, chain, type, symbol,
} = this;
return address === json.address
&& chain === json.chain
&& type === json.type
&& symbol === json.symbol;
&& chain === json.chain
&& type === json.type
&& symbol === json.symbol;
}

/**
Expand Down

0 comments on commit 51a0b4e

Please sign in to comment.