-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: new package for payment detection (#126)
- Loading branch information
1 parent
9ab725d
commit 7f2e5c2
Showing
57 changed files
with
242 additions
and
56 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
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
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 @@ | ||
{ | ||
"src/**/*.ts": ["tslint --project . --fix", "prettier --single-quote --write", "git add"] | ||
} |
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,22 @@ | ||
# @requestnetwork/payment-detection | ||
|
||
`@requestnetwork/payment-detection` is a typescript library part of the [Request Network protocol](https://github.com/RequestNetwork/requestNetwork). | ||
It contains client-side payment detection for all supported payment networks. | ||
|
||
### Payment and Refund detections | ||
|
||
If a payment network has been given to the request, the payment detection can be done. | ||
|
||
From the information provided in payment network, the library will feed the property `balance` of the request with: | ||
|
||
- `balance`: the sum of the amount of all payments minus the sum of amount of all refunds | ||
- `events`: all the payments and refunds events with the amount, timestamp etc... | ||
|
||
The payment networks available are: | ||
|
||
- `Types.Payment.PAYMENT_NETWORK_ID.BITCOIN_ADDRESS_BASED` ('pn-bitcoin-address-based'): handle Bitcoin payments associated to a BTC address to the request, every transaction hitting this address will be consider as a payment. Optionally, the payer can provide a BTC address for the refunds. Note that **the addresses must be used only for one and only one request** otherwise one transaction will be considered as a payment for more than one request. (see [the specification](https://github.com/RequestNetwork/requestNetwork/blob/master/packages/advanced-logic/specs/payment-network-btc-address-based-0.1.0-DRAFT.md)) | ||
- `Types.Payment.PAYMENT_NETWORK_ID.TESTNET_BITCOIN_ADDRESS_BASED` ('pn-testnet-bitcoin-address-based'): Same as previous but for the bitcoin testnet (for test purpose) | ||
- `Types.Payment.PAYMENT_NETWORK_ID.ERC20_ADDRESS_BASED`('pn-erc20-address-based'): Same as `BITCOIN_ADDRESS_BASED`, for ERC20 payments. | ||
- `Types.Payment.PAYMENT_NETWORK_ID.ERC20_PROXY_CONTRACT`('pn-erc20-proxy-contract'): uses an intermediary contract to document which request is being paid, through the `PaymentReference`. (see [the specification](https://github.com/RequestNetwork/requestNetwork/blob/master/packages/advanced-logic/specs/payment-network-erc20-address-based-0.1.0-DRAFT.md)) | ||
- `Types.Payment.PAYMENT_NETWORK_ID.ETH_INPUT_DATA`('pn-eth-input-data'): uses the transaction input data to pass the `PaymentReference`. (see [the specification](https://github.com/RequestNetwork/requestNetwork/blob/master/packages/advanced-logic/specs/payment-network-eth-input-data-0.1.0-DRAFT.md)) | ||
- `Types.Payment.PAYMENT_NETWORK_ID.DECLARATIVE`('pn-any-declarative'): a manual alternative, where payer can declare a payment sent, and payee can declare it received, working for any currency. (see [the specification](https://github.com/RequestNetwork/requestNetwork/blob/master/packages/advanced-logic/specs/payment-network-any-declarative-0.1.0-DRAFT.md)) |
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,72 @@ | ||
{ | ||
"name": "@requestnetwork/payment-detection", | ||
"version": "0.12.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Payment detection using ethers.", | ||
"keywords": [ | ||
"requestnetwork" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/RequestNetwork/requestNetwork.git" | ||
}, | ||
"homepage": "https://github.com/RequestNetwork/requestNetwork/tree/master/packages/payment-detection#readme", | ||
"bugs": { | ||
"url": "https://github.com/RequestNetwork/requestNetwork/issues" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"directories": { | ||
"lib": "src", | ||
"test": "test" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc -b", | ||
"clean": "shx rm -rf dist tsconfig.tsbuildinfo", | ||
"lint": "tslint --project . && eslint \"src/**/*.ts\"", | ||
"lint-staged": "lint-staged", | ||
"prepare": "yarn run build", | ||
"test": "nyc mocha --extension ts --require ts-node/register --require source-map-support/register \"test/**/*.ts\"", | ||
"test:watch": "yarn test --watch" | ||
}, | ||
"dependencies": { | ||
"@requestnetwork/types": "0.11.0", | ||
"@requestnetwork/utils": "0.10.0", | ||
"axios": "0.19.0", | ||
"bn.js": "4.11.8", | ||
"ethers": "4.0.43", | ||
"node-fetch": "2.6.0", | ||
"satoshi-bitcoin": "1.0.4" | ||
}, | ||
"devDependencies": { | ||
"@types/bn.js": "4.11.5", | ||
"@types/chai": "4.1.7", | ||
"@types/mocha": "5.2.7", | ||
"@types/sinon": "7.5.0", | ||
"@typescript-eslint/parser": "1.2.0", | ||
"chai": "4.2.0", | ||
"chai-as-promised": "7.1.1", | ||
"chai-spies": "1.0.0", | ||
"eslint": "5.13.0", | ||
"eslint-plugin-spellcheck": "0.0.14", | ||
"eslint-plugin-typescript": "0.14.0", | ||
"lint-staged": "8.1.3", | ||
"mocha": "6.2.2", | ||
"nyc": "15.0.0", | ||
"prettier": "1.16.4", | ||
"shx": "0.3.2", | ||
"sinon": "7.5.0", | ||
"source-map-support": "0.5.13", | ||
"tslint": "5.12.1", | ||
"typescript": "3.7.2" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,23 @@ | ||
import BtcMainnetPaymentNetwork from './mainnet-address-based'; | ||
import BtcTestnetPaymentNetwork from './testnet-address-based'; | ||
|
||
import DefaultBitcoinDetectionProvider from './default-bitcoin-detection-provider'; | ||
|
||
import BlockchainInfoProvider from './default-providers/blockchain-info'; | ||
import BlockcypherComProvider from './default-providers/blockcypher-com'; | ||
import BlockStreamInfoProvider from './default-providers/blockstream-info'; | ||
import ChainSoProvider from './default-providers/chain-so'; | ||
|
||
const providers = { | ||
BlockStreamInfoProvider, | ||
BlockchainInfoProvider, | ||
BlockcypherComProvider, | ||
ChainSoProvider, | ||
}; | ||
|
||
export { | ||
DefaultBitcoinDetectionProvider, | ||
BtcMainnetPaymentNetwork, | ||
BtcTestnetPaymentNetwork, | ||
providers as Providers, | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,4 @@ | ||
import AddressBased from './address-based'; | ||
import ProxyContract from './proxy-contract'; | ||
|
||
export { AddressBased, ProxyContract }; |
File renamed without changes.
File renamed without changes.
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 InputData from './input-data'; | ||
|
||
export { InputData }; |
File renamed without changes.
File renamed without changes.
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,16 @@ | ||
import PaymentNetworkFactory from './payment-network-factory'; | ||
import PaymentReferenceCalculator from './payment-reference-calculator'; | ||
|
||
import * as BtcPaymentNetwork from './btc'; | ||
import DeclarativePaymentNetwork from './declarative'; | ||
import * as Erc20PaymentNetwork from './erc20'; | ||
import * as EthPaymentNetwork from './eth'; | ||
|
||
export { | ||
PaymentNetworkFactory, | ||
PaymentReferenceCalculator, | ||
BtcPaymentNetwork, | ||
DeclarativePaymentNetwork, | ||
Erc20PaymentNetwork, | ||
EthPaymentNetwork, | ||
}; |
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
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...default-providers/blockchain-info.test.ts → ...default-providers/blockchain-info.test.ts
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...default-providers/blockcypher-com.test.ts → ...default-providers/blockcypher-com.test.ts
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
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
...efault-providers/blockstream-info.test.ts → ...efault-providers/blockstream-info.test.ts
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
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
...rk/btc/default-providers/chain-so.test.ts → ...st/btc/default-providers/chain-so.test.ts
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
2 changes: 1 addition & 1 deletion
2
...network/btc/mainnet-address-based.test.ts → ...on/test/btc/mainnet-address-based.test.ts
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
2 changes: 1 addition & 1 deletion
2
...network/btc/testnet-address-based.test.ts → ...on/test/btc/testnet-address-based.test.ts
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
2 changes: 1 addition & 1 deletion
2
...rc20/address-based-info-retriever.test.ts → ...rc20/address-based-info-retriever.test.ts
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
2 changes: 1 addition & 1 deletion
2
...ment-network/erc20/proxy-contract.test.ts → ...tection/test/erc20/proxy-contract.test.ts
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.