Skip to content

Commit

Permalink
Consolidate request_body logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dannydeezy committed Dec 11, 2023
1 parent 6666d45 commit 3169c73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
18 changes: 2 additions & 16 deletions deezy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,10 @@ function check_api_key() {
throw new Error('DEEZY_API_KEY must be set')
}
}
async function post_scan_request({ utxo, exchange_address, rare_sat_address, extraction_fee_rate, excluded_tags = null, included_tags = null, min_tag_sizes = null, tag_by_address = null }) {
async function post_scan_request(request_body) {
check_api_key()
if (!process.env.RARE_SAT_ADDRESS) {
throw new Error('RARE_SAT_ADDRESS must be set')
}
const url = `${BASE_URL}/sat-hunting/scan`
const body = {
utxo_to_scan: utxo,
extract: true,
special_sat_addresses: [
rare_sat_address
],
regular_funds_addresses: [
exchange_address
],
extraction_fee_rate,
}
const { data } = await axios.post(url, body, { headers: { 'x-api-token': process.env.DEEZY_API_KEY } }).catch(err => {
const { data } = await axios.post(url, request_body, { headers: { 'x-api-token': process.env.DEEZY_API_KEY } }).catch(err => {
console.error(err)
return { data: {} }
})
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ async function run() {
}
console.log(`Will use fee rate of ${fee_rate} sat/vbyte`)
const request_body = {
utxo,
exchange_address,
rare_sat_address,
utxo_to_scan: utxo,
extract: true,
regular_funds_addresses: [ exchange_address ],
special_sat_addresses: [ rare_sat_address ],
extraction_fee_rate: fee_rate
}
const {
Expand Down

0 comments on commit 3169c73

Please sign in to comment.