Skip to content

Commit

Permalink
Replaced blockcyper api with sochain api to fetch fees in satoshi
Browse files Browse the repository at this point in the history
  • Loading branch information
SDargarh committed Jan 23, 2024
1 parent be877c9 commit 524ee81
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@

### 2.0.4 (2024-01-09)

- Updated Sochain api key
- Updated Sochain api key

### 2.0.5 (2024-01-23)

- Replaced blockcyper api with sochain api to fetch fees in satoshi
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/vault-bitcoin-controller",
"version": "2.0.4",
"version": "2.0.5",
"description": "",
"engines": {
"node": ">= 10"
Expand Down
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 = {
SOCHAIN_API_KEY: 'jsGr7ioLvkz1Hfo6uwH_CGYdOnIpWtrJ',
SOCHAIN_BASE_URL: "https://sochain.com/api/v3/",
BLOCKCYPHER_BASE_URL: "https://api.blockcypher.com/v1/btc/"
}
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const axios = require("axios");
const helpers = require('./helper/index')

const { bitcoin: { HD_PATH_MAINNET, HD_PATH_TESTNET }, bitcoin_transaction: { NATIVE_TRANSFER }, bitcoin_network: { MAINNET, TESTNET }} = require('./config/index')
const { SOCHAIN_API_KEY, SOCHAIN_BASE_URL, BLOCKCYPHER_BASE_URL } = require('./constants/index')
const { SOCHAIN_API_KEY, SOCHAIN_BASE_URL } = require('./constants/index')

class KeyringController {

Expand Down Expand Up @@ -148,28 +148,33 @@ class KeyringController {
async getFees(rawTransaction) {
const { networkType } = this.store.getState()
const { from } = rawTransaction

try {
const URL = BLOCKCYPHER_BASE_URL + `${networkType === TESTNET.NETWORK ? 'test3' : "main"}/`
const headers = { "API-KEY": SOCHAIN_API_KEY}

const URL = SOCHAIN_BASE_URL + "network_info/" + `${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}`
const response = await axios({
url : `${URL}`,
method: 'GET',
headers: headers,
});

let blocks = response.data.data['mempool'].blocks.slice(0,3)

let fees = {
slow: {
satPerByte: parseInt(response.data.low_fee_per_kb/1000),
satPerByte: parseInt(blocks[2].median_fee_rate),
},
standard: {
satPerByte: parseInt(response.data.medium_fee_per_kb/1000),
satPerByte: parseInt(blocks[1].median_fee_rate),
},
fast: {
satPerByte: parseInt(response.data.high_fee_per_kb/1000)
satPerByte: parseInt(blocks[0].median_fee_rate)
}
}

// get transaction size
const sochainURL = SOCHAIN_BASE_URL + `unspent_outputs/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${from}`
const headers = { "API-KEY": SOCHAIN_API_KEY}

let { transactionSize } = await helpers.getTransactionSize(sochainURL, headers)

Expand Down

0 comments on commit 524ee81

Please sign in to comment.