Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
361 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# `@liquality/bitcoin-esplora-swap-find-provider` <img align="right" src="https://raw.githubusercontent.com/liquality/chainabstractionlayer/master/liquality-logo.png" height="80px" /> | ||
|
||
|
||
[![Build Status](https://travis-ci.com/liquality/chainabstractionlayer.svg?branch=master)](https://travis-ci.com/liquality/chainabstractionlayer) | ||
[![Coverage Status](https://coveralls.io/repos/github/liquality/chainabstractionlayer/badge.svg?branch=master)](https://coveralls.io/github/liquality/chainabstractionlayer?branch=master) | ||
[![Standard Code Style](https://img.shields.io/badge/codestyle-standard-brightgreen.svg)](https://github.com/standard/standard) | ||
[![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](../../LICENSE.md) | ||
[![@liquality/bitcoin-esplora-swap-find-provider](https://img.shields.io/npm/dt/@liquality/bitcoin-esplora-swap-find-provider.svg)](https://npmjs.com/package/@liquality/bitcoin-esplora-swap-find-provider) | ||
[![Gitter](https://img.shields.io/gitter/room/liquality/Lobby.svg)](https://gitter.im/liquality/Lobby?source=orgpage) | ||
[![Telegram](https://img.shields.io/badge/chat-on%20telegram-blue.svg)](https://t.me/Liquality) [![Greenkeeper badge](https://badges.greenkeeper.io/liquality/chainabstractionlayer.svg)](https://greenkeeper.io/) | ||
|
||
> :warning: This project is under heavy development. Expect bugs & breaking changes. | ||
### :pencil: [Introductory Blog Post: The Missing Tool to Cross-Chain Development](https://medium.com/liquality/the-missing-tool-to-cross-chain-development-2ebfe898efa1) | ||
|
||
|
||
Query different blockchains with account management using a single and simple interface. | ||
|
||
|
||
## Installation | ||
|
||
```bash | ||
npm i @liquality/bitcoin-esplora-swap-find-provider | ||
``` | ||
|
||
or | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@liquality/bitcoin-esplora-swap-find-provider@0.2.3/dist/bitcoin-esplora-swap-find-provider.min.js"></script> | ||
<!-- sourceMap at https://cdn.jsdelivr.net/npm/@liquality/bitcoin-esplora-swap-find-provider@0.2.3/dist/bitcoin-esplora-swap-find-provider.min.js.map --> | ||
<!-- available as window.BitcoinEsploraSwapFindProvider --> | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
import BitcoinEsploraSwapFindProvider from '@liquality/bitcoin-esplora-swap-find-provider' | ||
|
||
const apiProvider = new BitcoinEsploraSwapFindProvider('https://blockstream.info/testnet/api') | ||
|
||
await apiProvider.getBlockByNumber(1) | ||
``` | ||
|
||
|
||
## License | ||
|
||
[MIT](../../LICENSE.md) |
40 changes: 40 additions & 0 deletions
40
packages/bitcoin-esplora-swap-find-provider/lib/BitcoinEsploraSwapFindProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import axios from 'axios' | ||
import Provider from '@liquality/provider' | ||
|
||
import { version } from '../package.json' | ||
|
||
export default class BitcoinEsploraSwapFindProvider extends Provider { | ||
constructor (url) { | ||
super() | ||
this.url = url | ||
this._axios = axios.create({ | ||
baseURL: url, | ||
responseType: 'text', | ||
transformResponse: undefined // https://github.com/axios/axios/issues/907, | ||
}) | ||
} | ||
|
||
async findAddressTransaction (address, currentHeight, predicate) { | ||
// TODO: This does not go through pages as swap addresses have at most 2 transactions | ||
// Investigate whether retrieving more transactions is requiredl. | ||
const response = await this._axios.get(`/address/${address}/txs`) | ||
const transactions = response.data | ||
const transaction = transactions.find(tx => { | ||
const formattedTransaction = this.getMethod('formatTransaction')(tx, currentHeight) | ||
return predicate(formattedTransaction) | ||
}) | ||
if (transaction) return this.getMethod('formatTransaction')(transaction, currentHeight) | ||
} | ||
|
||
async findSwapTransaction (recipientAddress, refundAddress, secretHash, expiration, blockNumber, predicate) { | ||
const currentHeight = await this.getMethod('getBlockHeight')() | ||
const swapOutput = this.getMethod('getSwapOutput')(recipientAddress, refundAddress, secretHash, expiration) | ||
const paymentVariants = this.getMethod('getSwapPaymentVariants')(swapOutput) | ||
for (const paymentVariant of Object.values(paymentVariants)) { | ||
const addressTransaction = this.findAddressTransaction(paymentVariant.address, currentHeight, predicate) | ||
if (addressTransaction) return addressTransaction | ||
} | ||
} | ||
} | ||
|
||
BitcoinEsploraSwapFindProvider.version = version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import BitcoinEsploraSwapFindProvider from './BitcoinEsploraSwapFindProvider' | ||
|
||
export default BitcoinEsploraSwapFindProvider |
214 changes: 214 additions & 0 deletions
214
packages/bitcoin-esplora-swap-find-provider/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@liquality/bitcoin-esplora-swap-find-provider", | ||
"umdName": "BitcoinEsploraSwapFindProvider", | ||
"umdExport": "default", | ||
"version": "0.4.11", | ||
"description": "", | ||
"module": "lib/index.js", | ||
"main": "dist/index.cjs.js", | ||
"files": [ | ||
"dist", | ||
"lib" | ||
], | ||
"scripts": { | ||
"build:node": "webpack --config ../../webpack/webpack.node.config.js", | ||
"build:browser": "webpack --config ../../webpack/webpack.browser.config.js", | ||
"build": "webpack --config ../../webpack/webpack.config.js" | ||
}, | ||
"author": "Liquality <info@liquality.io>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.3", | ||
"@liquality/provider": "^0.4.11", | ||
"@liquality/utils": "^0.4.11", | ||
"axios": "^0.19.0", | ||
"bignumber.js": "^8.1.1", | ||
"lodash": "^4.17.11" | ||
}, | ||
"engines": { | ||
"node": "~8.12.0" | ||
}, | ||
"homepage": "https://github.com/liquality/chainabstractionlayer#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/liquality/chainabstractionlayer.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/liquality/chainabstractionlayer/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "1855d9ec369c8c577f74eb04e310a7c00b9eaa6c", | ||
"devDependencies": { | ||
"nock": "^10.0.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.