Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
recipientAddress,
amount,
walletType,
memo = ""
) => {
// generate our btc addresses for sender and recipient
const senderBtcAddress = c32ToB58(senderAddress);
const recipientBtcAddress = c32ToB58(recipientAddress);
// define token type (always stacks)
const tokenType = "STACKS";
const tokenAmount = toBigInt(amount); // convert to bigi
// get an estimate
const utxos = await config.network.getUTXOs(senderBtcAddress);
const numUTXOs = utxos.length;
const estimate =
(await transactions.estimateTokenTransfer(
recipientBtcAddress,
tokenType,
tokenAmount,
memo,
numUTXOs
)) + 5500;
// current BTC balance
const btcBalance = sumUTXOs(utxos);
// account status
const accountStatus = await config.network.getAccountStatus(
tokenType,
tokenAmount,
memo,
numUTXOs
)) + 5500;
// current BTC balance
const btcBalance = sumUTXOs(utxos);
// account status
const accountStatus = await config.network.getAccountStatus(
senderBtcAddress,
tokenType
);
// current STACKS balance
const currentAccountBalance = await config.network.getAccountBalance(
senderBtcAddress,
tokenType
);
// current Block Height
const blockHeight = await config.network.getBlockHeight();
// check for our errors
// not enough btc
if (btcBalance < estimate) {
return {
...ERRORS.INSUFFICIENT_BTC_BALANCE,
estimate,
btcBalance,
difference: estimate - btcBalance
export function getMultiSigInfo(publicKeys, signersRequired) {
const redeem = btc.payments.p2ms({ m: signersRequired, pubkeys: publicKeys })
const script = btc.payments.p2sh({ redeem })
const address = script.address
return {
address: bskConfig.network.coerceAddress(address),
redeemScript: redeem.output.toString('hex')
}
}
.then(result => {
this.address = bskConfig.network.coerceAddress(result.bitcoinAddress)
return this.address
})
.catch(err => {
renderView(view) {
switch(view) {
case VIEWS.DEFAULT:
return ;
default:
return <div></div>;
}
}
return dispatch => {
logger.info('Broadcasting bitcoin transaction')
logger.debug('Transaction hex:', txHex)
dispatch(broadcastTransaction())
if (regTestMode) {
logger.info('Using regtest network to broadcast transaction')
config.network = network.defaults.LOCAL_REGTEST
config.network.blockstackAPIUrl = 'http://localhost:6270'
}
return config.network
.broadcastTransaction(txHex)
.then(res => {
logger.info(`Broadcasting bitcoin transaction succesful: ${res}`)
dispatch(broadcastTransactionSuccess())
})
.catch(err => {
logger.error(`Failed to broadcast bitcoin transaction: ${err}`)
dispatch(broadcastTransactionError(err.message || err.toString()))
})
}
}
function getTransactionBitcoind (txId) {
const bitcoindUrl = bskConfig.network.btc.bitcoindUrl
const bitcoindCredentials = bskConfig.network.btc.bitcoindCredentials
const jsonRPC = {
jsonrpc: '1.0',
method: 'getrawtransaction',
params: [txId]
}
const authString = Buffer.from(`${bitcoindCredentials.username}:${bitcoindCredentials.password}`)
.toString('base64')
const headers = { Authorization: `Basic ${authString}` }
return fetch(bitcoindUrl, {
method: 'POST',
body: JSON.stringify(jsonRPC),
headers
})
renderView(view) {
switch(view) {
case VIEWS.DEFAULT:
return ;
default:
return <div></div>;
}
}
.map( output => {
if (btc.script.toASM(output.script).startsWith('OP_RETURN')) {
const nullData = btc.script.decompile(output.script)[1]
return { 'op_return_data': nullData.toString('hex'),
amount: '0',
'script_type': 'PAYTOOPRETURN' }
} else {
const address = bskConfig.network.coerceAddress(
btc.address.fromOutputScript(output.script))
return { address,
amount: `${output.value}`,
'script_type': 'PAYTOADDRESS' }
}
})
}
return TrezorSigner.getPublicKeys([hdpath]).then(pks => {
const address = btc.payments.p2pkh({ pubkey: Buffer.from(pks[0], "hex") })
.address;
return bskConfig.network.coerceAddress(address);
});
}