Skip to content

Commit

Permalink
feat: added doge getTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
0x31 committed Sep 25, 2020
1 parent c3b0d6a commit d2d8a09
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 56 deletions.
28 changes: 11 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,43 @@ All notable changes to this project will be documented in this file. See [standa

### [0.2.19](https://github.com/renproject/send-crypto/compare/v0.2.18...v0.2.19) (2020-09-25)


### Bug Fixes

* fixed fetchTransactions calling fetchUTXos instead ([e09da7e](https://github.com/renproject/send-crypto/commit/e09da7e0af6435bea07581244ac6e90d51128095))
- fixed fetchTXs calling fetchUTXos instead ([e09da7e](https://github.com/renproject/send-crypto/commit/e09da7e0af6435bea07581244ac6e90d51128095))

### [0.2.18](https://github.com/renproject/send-crypto/compare/v0.2.17...v0.2.18) (2020-09-25)

### [0.2.17](https://github.com/renproject/send-crypto/compare/v0.2.16...v0.2.17) (2020-09-25)


### Features

* added fetchTXs endpoints ([7582026](https://github.com/renproject/send-crypto/commit/75820269260fc5646a5318a179e8b70067907671))
- added fetchTXs endpoints ([7582026](https://github.com/renproject/send-crypto/commit/75820269260fc5646a5318a179e8b70067907671))

### [0.2.16](https://github.com/renproject/send-crypto/compare/v0.2.15...v0.2.16) (2020-09-18)


### Features

* added initial doge api support, updated dependencies ([34cb062](https://github.com/renproject/send-crypto/commit/34cb062a6601f0baf371d9cbb92efd574fd7c2f0))
- added initial doge api support, updated dependencies ([34cb062](https://github.com/renproject/send-crypto/commit/34cb062a6601f0baf371d9cbb92efd574fd7c2f0))

### [0.2.15](https://github.com/renproject/send-crypto/compare/v0.2.14...v0.2.15) (2020-09-09)


### Bug Fixes

* remove bn.js imports ([71fa3f2](https://github.com/renproject/send-crypto/commit/71fa3f2d8a1a570ac76ce6889c21235209a3447c))
- remove bn.js imports ([71fa3f2](https://github.com/renproject/send-crypto/commit/71fa3f2d8a1a570ac76ce6889c21235209a3447c))

### [0.2.14](https://github.com/renproject/send-crypto/compare/v0.2.13...v0.2.14) (2020-07-13)

### [0.2.13](https://github.com/renproject/send-crypto/compare/v0.2.12...v0.2.13) (2020-07-13)


### Features

* added getUTXO to wrap around fetchUTXO ([e146c94](https://github.com/renproject/send-crypto/commit/e146c94400a71308c34b0bdc4cd9dfcac9ca9930))
- added getUTXO to wrap around fetchUTXO ([e146c94](https://github.com/renproject/send-crypto/commit/e146c94400a71308c34b0bdc4cd9dfcac9ca9930))

### [0.2.12](https://github.com/renproject/send-crypto/compare/v0.2.11...v0.2.12) (2020-07-13)


### Features

* add fetchUTXO ([e543cd2](https://github.com/renproject/send-crypto/commit/e543cd23bb5dbd89b60fbe084d469b46c2bc9b10))
- add fetchUTXO ([e543cd2](https://github.com/renproject/send-crypto/commit/e543cd23bb5dbd89b60fbe084d469b46c2bc9b10))

### [0.2.11](https://github.com/renproject/send-crypto/compare/v0.2.10...v0.2.11) (2020-06-26)

Expand Down Expand Up @@ -118,20 +112,20 @@ interface UTXO {

### [0.1.4](https://github.com/renproject/send-crypto/compare/v0.1.3...v0.1.4) (2019-12-05)

* Added `approve` option for ERC20s
- Added `approve` option for ERC20s

### [0.1.3](https://github.com/renproject/send-crypto/compare/v0.1.2...v0.1.3) (2019-12-03)

* Randomized API fallback order
- Randomized API fallback order

### [0.1.2](https://github.com/renproject/send-crypto/compare/v0.1.1...v0.1.2) (2019-12-03)

* Renamed `balanceOf` to `getBalance`
* Exposed getUTXOs in BTC, ZEC and BCH handlers
- Renamed `balanceOf` to `getBalance`
- Exposed getUTXOs in BTC, ZEC and BCH handlers

### [0.1.1](https://github.com/renproject/send-crypto/compare/v0.1.0...v0.1.1) (2019-12-02)

* Allowed importing without `.default`
- Allowed importing without `.default`

### 0.1.0 (2019-12-02)

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/BCH/BCHHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ test(
test(
"BCHHandler: Testnet BCH TXs",
testEndpoints,
_apiFallbacks.fetchTransactions(true, testnetAddress)
_apiFallbacks.fetchTXs(true, testnetAddress)
);

test(
"BCHHandler: Mainnet BCH TXs",
testEndpoints,
_apiFallbacks.fetchTransactions(false, mainnetAddress)
_apiFallbacks.fetchTXs(false, mainnetAddress)
);

// Test confirmations endpoint /////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/BCH/BCHHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const _apiFallbacks = {
),
],

fetchTransactions: (
fetchTXs: (
testnet: boolean,
address: string,
confirmations: number = 0
Expand Down Expand Up @@ -121,7 +121,7 @@ export class BCHHandler implements Handler {
? options.confirmations
: 0;

const endpoints = _apiFallbacks.fetchTransactions(
const endpoints = _apiFallbacks.fetchTXs(
testnet,
address,
confirmations
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/BTC/BTCHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ test(
test(
"BTCHandler: Testnet BTC TXs",
testEndpoints,
_apiFallbacks.fetchTransactions(true, testnetAddress)
_apiFallbacks.fetchTXs(true, testnetAddress)
);

test(
"BTCHandler: Mainnet BTC TXs",
testEndpoints,
_apiFallbacks.fetchTransactions(false, mainnetAddress)
_apiFallbacks.fetchTXs(false, mainnetAddress)
);

// Test confirmations endpoint /////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/BTC/BTCHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const _apiFallbacks = {
),
],

fetchTransactions: (
fetchTXs: (
testnet: boolean,
address: string,
confirmations: number = 0
Expand Down Expand Up @@ -130,7 +130,7 @@ export class BTCHandler implements Handler {
? options.confirmations
: 0;

const endpoints = _apiFallbacks.fetchTransactions(
const endpoints = _apiFallbacks.fetchTXs(
testnet,
options.address,
confirmations
Expand Down
87 changes: 64 additions & 23 deletions src/handlers/DOGE/DOGEHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ export const _apiFallbacks = {
),
],

fetchTXs: (
testnet: boolean,
address: string,
confirmations: number = 0
) => [
() =>
Sochain.fetchTXs(testnet ? "DOGETEST" : "DOGE")(
address,
confirmations
),
...shuffleArray(
onlyMainnet(
() =>
Blockchair.fetchTXs(Blockchair.networks.DOGECOIN)(
address,
confirmations
),
testnet
)
),
],

broadcastTransaction: (testnet: boolean, hex: string) => [
() => Sochain.broadcastTransaction(testnet ? "DOGETEST" : "DOGE")(hex),
...shuffleArray(
Expand All @@ -51,28 +73,47 @@ export const _apiFallbacks = {
],
};

export const getUTXOs = async (
testnet: boolean,
options: { address: string; confirmations?: number }
): Promise<readonly UTXO[]> => {
const confirmations =
options && options.confirmations !== undefined
? options.confirmations
: 0;
class DogeHandler {
static getUTXOs = async (
testnet: boolean,
options: { address: string; confirmations?: number }
): Promise<readonly UTXO[]> => {
const confirmations =
options && options.confirmations !== undefined
? options.confirmations
: 0;

const endpoints = _apiFallbacks.fetchUTXOs(
testnet,
options.address,
confirmations
);
return retryNTimes(() => fallback(endpoints), 2);
};
const endpoints = _apiFallbacks.fetchUTXOs(
testnet,
options.address,
confirmations
);
return retryNTimes(() => fallback(endpoints), 2);
};

export const getUTXO = async (
testnet: boolean,
txHash: string,
vOut: number
): Promise<UTXO> => {
const endpoints = _apiFallbacks.fetchUTXO(testnet, txHash, vOut);
return retryNTimes(() => fallback(endpoints), 2);
};
static getUTXO = async (
testnet: boolean,
txHash: string,
vOut: number
): Promise<UTXO> => {
const endpoints = _apiFallbacks.fetchUTXO(testnet, txHash, vOut);
return retryNTimes(() => fallback(endpoints), 2);
};

static getTransactions = async (
testnet: boolean,
options: { address: string; confirmations?: number }
): Promise<readonly UTXO[]> => {
const confirmations =
options && options.confirmations !== undefined
? options.confirmations
: 0;

const endpoints = _apiFallbacks.fetchTXs(
testnet,
options.address,
confirmations
);
return retryNTimes(() => fallback(endpoints), 2);
};
}
4 changes: 2 additions & 2 deletions src/handlers/ZEC/ZECHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ test(
test(
"ZECHandler: Testnet ZEC TXs",
testEndpoints,
_apiFallbacks.fetchTransactions(true, testnetAddress),
_apiFallbacks.fetchTXs(true, testnetAddress),
/(zechain.net)|(zcash.blockexplorer.com)/ // ignore errors
);

test(
"ZECHandler: Mainnet ZEC TXs",
testEndpoints,
_apiFallbacks.fetchTransactions(false, mainnetAddress),
_apiFallbacks.fetchTXs(false, mainnetAddress),
/(zechain.net)|(zcash.blockexplorer.com)/ // ignore errors
);

Expand Down
8 changes: 2 additions & 6 deletions src/handlers/ZEC/ZECHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ export const _apiFallbacks = {
),
],

fetchTransactions: (
testnet: boolean,
address: string,
confirmations: number = 0
) =>
fetchTXs: (testnet: boolean, address: string, confirmations: number = 0) =>
testnet
? [
...shuffleArray(() =>
Expand Down Expand Up @@ -222,7 +218,7 @@ export class ZECHandler implements Handler {
? options.confirmations
: 0;

const endpoints = _apiFallbacks.fetchTransactions(
const endpoints = _apiFallbacks.fetchTXs(
testnet,
options.address,
confirmations
Expand Down

0 comments on commit d2d8a09

Please sign in to comment.