@atomicfinance/bitcoin-esplora-batch-api-provider 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/BitcoinEsploraBatchApiProvider.d.ts +24 -0
- package/dist/BitcoinEsploraBatchApiProvider.js +45 -0
- package/dist/BitcoinEsploraBatchApiProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/lib/BitcoinEsploraBatchApiProvider.ts +66 -0
- package/lib/index.ts +3 -0
- package/package.json +51 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @atomicfinance/bitcoin-esplora-batch-api-provider
|
|
2
|
+
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- a06082e: Create unified standalone `bitcoin-abstraction-layer` package
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [a06082e]
|
|
12
|
+
- @atomicfinance/types@3.0.0
|
|
13
|
+
- @atomicfinance/bitcoin-esplora-api-provider@3.0.0
|
|
14
|
+
- @atomicfinance/node-provider@3.0.0
|
|
15
|
+
- @atomicfinance/utils@3.0.0
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BitcoinEsploraApiProvider, esplora, EsploraApiProviderOptions } from '@atomicfinance/bitcoin-esplora-api-provider';
|
|
2
|
+
import { NodeProvider } from '@atomicfinance/node-provider';
|
|
3
|
+
import { Address } from '@atomicfinance/types';
|
|
4
|
+
interface EsploraBatchApiProviderOptions extends EsploraApiProviderOptions {
|
|
5
|
+
batchUrl: string;
|
|
6
|
+
}
|
|
7
|
+
export default class BitcoinEsploraBatchApiProvider extends BitcoinEsploraApiProvider {
|
|
8
|
+
_batchAxios: NodeProvider;
|
|
9
|
+
constructor(options: EsploraBatchApiProviderOptions);
|
|
10
|
+
getUnspentTransactions(_addresses: (Address | string)[]): Promise<{
|
|
11
|
+
address: string;
|
|
12
|
+
satoshis: number;
|
|
13
|
+
amount: number;
|
|
14
|
+
blockHeight: number;
|
|
15
|
+
txid: string;
|
|
16
|
+
vout: number;
|
|
17
|
+
status: esplora.TxStatus;
|
|
18
|
+
value: number;
|
|
19
|
+
}[]>;
|
|
20
|
+
getAddressTransactionCounts(_addresses: (Address | string)[]): Promise<{
|
|
21
|
+
[index: string]: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bitcoin_esplora_api_provider_1 = require("@atomicfinance/bitcoin-esplora-api-provider");
|
|
4
|
+
const node_provider_1 = require("@atomicfinance/node-provider");
|
|
5
|
+
const types_1 = require("@atomicfinance/types");
|
|
6
|
+
const utils_1 = require("@atomicfinance/utils");
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
class BitcoinEsploraBatchApiProvider extends bitcoin_esplora_api_provider_1.BitcoinEsploraApiProvider {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options);
|
|
11
|
+
this._batchAxios = new node_provider_1.NodeProvider({
|
|
12
|
+
baseURL: options.batchUrl,
|
|
13
|
+
responseType: 'text',
|
|
14
|
+
transformResponse: undefined,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async getUnspentTransactions(_addresses) {
|
|
18
|
+
const addresses = _addresses.map(utils_1.addressToString);
|
|
19
|
+
const data = await this._batchAxios.nodePost('/addresses/utxo', {
|
|
20
|
+
addresses: lodash_1.uniq(addresses),
|
|
21
|
+
});
|
|
22
|
+
const utxos = data.map(({ address, utxo }) => {
|
|
23
|
+
return utxo.map((obj) => ({
|
|
24
|
+
...obj,
|
|
25
|
+
address,
|
|
26
|
+
satoshis: obj.value,
|
|
27
|
+
amount: new types_1.BigNumber(obj.value).dividedBy(1e8).toNumber(),
|
|
28
|
+
blockHeight: obj.status.block_height,
|
|
29
|
+
}));
|
|
30
|
+
});
|
|
31
|
+
return lodash_1.flatten(utxos);
|
|
32
|
+
}
|
|
33
|
+
async getAddressTransactionCounts(_addresses) {
|
|
34
|
+
const addresses = _addresses.map(utils_1.addressToString);
|
|
35
|
+
const data = await this._batchAxios.nodePost('/addresses', {
|
|
36
|
+
addresses: lodash_1.uniq(addresses),
|
|
37
|
+
});
|
|
38
|
+
return data.reduce((acc, obj) => {
|
|
39
|
+
acc[obj.address] = obj.chain_stats.tx_count + obj.mempool_stats.tx_count;
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = BitcoinEsploraBatchApiProvider;
|
|
45
|
+
//# sourceMappingURL=BitcoinEsploraBatchApiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinEsploraBatchApiProvider.js","sourceRoot":"","sources":["../lib/BitcoinEsploraBatchApiProvider.ts"],"names":[],"mappings":";;AAAA,8FAIqD;AACrD,gEAA4D;AAC5D,gDAA0D;AAC1D,gDAAuD;AACvD,mCAAuC;AAQvC,MAAqB,8BAA+B,SAAQ,wDAAyB;IAGnF,YAAY,OAAuC;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,WAAW,GAAG,IAAI,4BAAY,CAAC;YAClC,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,YAAY,EAAE,MAAM;YACpB,iBAAiB,EAAE,SAAS;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,UAAgC;QAC3D,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,uBAAe,CAAC,CAAC;QAClD,MAAM,IAAI,GAAe,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CACtD,iBAAiB,EACjB;YACE,SAAS,EAAE,aAAI,CAAC,SAAS,CAAC;SAC3B,CACF,CAAC;QAEF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;YAC3C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBACxB,GAAG,GAAG;gBACN,OAAO;gBACP,QAAQ,EAAE,GAAG,CAAC,KAAK;gBACnB,MAAM,EAAE,IAAI,iBAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;gBAC1D,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,YAAY;aACrC,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,OAAO,gBAAO,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,2BAA2B,CAAC,UAAgC;QAChE,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,uBAAe,CAAC,CAAC;QAClD,MAAM,IAAI,GAAsB,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAC7D,YAAY,EACZ;YACE,SAAS,EAAE,aAAI,CAAC,SAAS,CAAC;SAC3B,CACF,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAgC,EAAE,GAAG,EAAE,EAAE;YAC3D,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC;YACzE,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF;AAjDD,iDAiDC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BitcoinEsploraBatchApiProvider = void 0;
|
|
7
|
+
const BitcoinEsploraBatchApiProvider_1 = __importDefault(require("./BitcoinEsploraBatchApiProvider"));
|
|
8
|
+
exports.BitcoinEsploraBatchApiProvider = BitcoinEsploraBatchApiProvider_1.default;
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;AAAA,sGAA8E;AAErE,yCAFF,wCAA8B,CAEE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BitcoinEsploraApiProvider,
|
|
3
|
+
esplora,
|
|
4
|
+
EsploraApiProviderOptions,
|
|
5
|
+
} from '@atomicfinance/bitcoin-esplora-api-provider';
|
|
6
|
+
import { NodeProvider } from '@atomicfinance/node-provider';
|
|
7
|
+
import { Address, BigNumber } from '@atomicfinance/types';
|
|
8
|
+
import { addressToString } from '@atomicfinance/utils';
|
|
9
|
+
import { flatten, uniq } from 'lodash';
|
|
10
|
+
|
|
11
|
+
type BatchUTXOs = { address: string; utxo: esplora.UTXO[] }[];
|
|
12
|
+
|
|
13
|
+
interface EsploraBatchApiProviderOptions extends EsploraApiProviderOptions {
|
|
14
|
+
batchUrl: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class BitcoinEsploraBatchApiProvider extends BitcoinEsploraApiProvider {
|
|
18
|
+
_batchAxios: NodeProvider;
|
|
19
|
+
|
|
20
|
+
constructor(options: EsploraBatchApiProviderOptions) {
|
|
21
|
+
super(options);
|
|
22
|
+
|
|
23
|
+
this._batchAxios = new NodeProvider({
|
|
24
|
+
baseURL: options.batchUrl,
|
|
25
|
+
responseType: 'text',
|
|
26
|
+
transformResponse: undefined, // https://github.com/axios/axios/issues/907,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getUnspentTransactions(_addresses: (Address | string)[]) {
|
|
31
|
+
const addresses = _addresses.map(addressToString);
|
|
32
|
+
const data: BatchUTXOs = await this._batchAxios.nodePost(
|
|
33
|
+
'/addresses/utxo',
|
|
34
|
+
{
|
|
35
|
+
addresses: uniq(addresses),
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const utxos = data.map(({ address, utxo }) => {
|
|
40
|
+
return utxo.map((obj) => ({
|
|
41
|
+
...obj,
|
|
42
|
+
address,
|
|
43
|
+
satoshis: obj.value,
|
|
44
|
+
amount: new BigNumber(obj.value).dividedBy(1e8).toNumber(),
|
|
45
|
+
blockHeight: obj.status.block_height,
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return flatten(utxos);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async getAddressTransactionCounts(_addresses: (Address | string)[]) {
|
|
53
|
+
const addresses = _addresses.map(addressToString);
|
|
54
|
+
const data: esplora.Address[] = await this._batchAxios.nodePost(
|
|
55
|
+
'/addresses',
|
|
56
|
+
{
|
|
57
|
+
addresses: uniq(addresses),
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return data.reduce((acc: { [index: string]: number }, obj) => {
|
|
62
|
+
acc[obj.address] = obj.chain_stats.tx_count + obj.mempool_stats.tx_count;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
65
|
+
}
|
|
66
|
+
}
|
package/lib/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atomicfinance/bitcoin-esplora-batch-api-provider",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"directories": {
|
|
8
|
+
"dist": "dist",
|
|
9
|
+
"src": "lib"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "../../node_modules/.bin/tsc --project tsconfig.json",
|
|
17
|
+
"lint": "../../node_modules/.bin/eslint --ignore-path ../../.eslintignore -c ../../.eslintrc.js .",
|
|
18
|
+
"lint:fix": "../../node_modules/.bin/eslint --fix --ignore-path ../../.eslintignore -c ../../.eslintrc.js .",
|
|
19
|
+
"test": "../../node_modules/.bin/nyc --reporter=lcov --reporter=text --extension=.ts ../../node_modules/.bin/mocha --recursive \"tests/**/*.test.*\""
|
|
20
|
+
},
|
|
21
|
+
"author": "Atomic Finance <info@atomic.finance>",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=14"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@atomicfinance/bitcoin-esplora-api-provider": "^3.0.0",
|
|
28
|
+
"@atomicfinance/node-provider": "^3.0.0",
|
|
29
|
+
"@atomicfinance/types": "^3.0.0",
|
|
30
|
+
"@atomicfinance/utils": "^3.0.0",
|
|
31
|
+
"@babel/runtime": "^7.12.1",
|
|
32
|
+
"bignumber.js": "^9.0.0",
|
|
33
|
+
"lodash": "^4.17.20"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/liquality/chainabstractionlayer#readme",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/liquality/chainabstractionlayer.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/liquality/chainabstractionlayer/issues"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/lodash": "^4.14.168",
|
|
48
|
+
"nock": "^10.0.6"
|
|
49
|
+
},
|
|
50
|
+
"sideEffects": false
|
|
51
|
+
}
|