-
Notifications
You must be signed in to change notification settings - Fork 92
feat: balance event timestamps #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3235586
1be9b9a
6a64948
105c2e8
3df7176
d987dfe
dff55fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ export default class BlockcypherCom implements Types.IBitcoinDetectionProvider { | |
| bitcoinNetworkId: number, | ||
| address: string, | ||
| eventName: Types.EVENTS_NAMES, | ||
| ): Promise<Types.IBalanceWithEvents> { | ||
| ): Promise<Types.BTCBalanceWithEvents> { | ||
| const baseUrl = this.getBaseUrl(bitcoinNetworkId); | ||
| const queryUrl = `${baseUrl}/addrs/${address}`; | ||
| try { | ||
|
|
@@ -57,28 +57,28 @@ export default class BlockcypherCom implements Types.IBitcoinDetectionProvider { | |
| * @param eventName Indicates if it is an address for payment or refund | ||
| * @returns Balance with events | ||
| */ | ||
| public parse(addressInfo: any, eventName: Types.EVENTS_NAMES): Types.IBalanceWithEvents { | ||
| public parse(addressInfo: any, eventName: Types.EVENTS_NAMES): Types.BTCBalanceWithEvents { | ||
| const balance = new bigNumber(addressInfo.total_received).toString(); | ||
|
|
||
| // Retrieves all the transaction hash of the transactions having as input the current address | ||
| const inputTxHashes = addressInfo.txrefs | ||
| .filter((tx: any) => tx.tx_output_n === -1) | ||
| .map((tx: any) => tx.tx_hash); | ||
|
|
||
| const events: Types.IPaymentNetworkEvent[] = addressInfo.txrefs | ||
| const events: Types.BTCPaymentNetworkEvent[] = addressInfo.txrefs | ||
| // keep only the transaction with this address as output | ||
| .filter((tx: any) => tx.tx_input_n === -1) | ||
| // exclude the transactions coming from the same address | ||
| .filter((tx: any) => !inputTxHashes.includes(tx.tx_hash)) | ||
| .map( | ||
| (tx: any): Types.IPaymentNetworkEvent => ({ | ||
| (tx: any): Types.BTCPaymentNetworkEvent => ({ | ||
| amount: tx.value.toString(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may need to be discussed with the team
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discussed with Vince, we agreed that it's OK to have an amount of 0 for specific events.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to be included in this discussion. I'm not sure this makes a lot of sense to me. |
||
| name: eventName, | ||
| parameters: { | ||
| amount: tx.value.toString(), | ||
| block: tx.block_height, | ||
| // timestamp - not given by this API | ||
| txHash: tx.tx_hash, | ||
| }, | ||
| // timestamp - not given by this API | ||
| }), | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ export default class BlockstreamInfo implements Types.IBitcoinDetectionProvider | |
| bitcoinNetworkId: number, | ||
| address: string, | ||
| eventName: Types.EVENTS_NAMES, | ||
| ): Promise<Types.IBalanceWithEvents> { | ||
| ): Promise<Types.BTCBalanceWithEvents> { | ||
| const baseUrl = this.getBaseUrl(bitcoinNetworkId); | ||
| const queryUrl = `${baseUrl}/address/${address}/txs`; | ||
| try { | ||
|
|
@@ -87,8 +87,8 @@ export default class BlockstreamInfo implements Types.IBitcoinDetectionProvider | |
| * @param eventName Indicates if it is an address for payment or refund | ||
| * @returns Balance with events | ||
| */ | ||
| public parse(addressInfo: any, eventName: Types.EVENTS_NAMES): Types.IBalanceWithEvents { | ||
| const events: Types.IPaymentNetworkEvent[] = addressInfo.txs | ||
| public parse(addressInfo: any, eventName: Types.EVENTS_NAMES): Types.BTCBalanceWithEvents { | ||
| const events: Types.BTCPaymentNetworkEvent[] = addressInfo.txs | ||
| // exclude the transactions coming from the same address | ||
| .filter((tx: any) => { | ||
| const autoVin = tx.vin.filter( | ||
|
|
@@ -109,20 +109,20 @@ export default class BlockstreamInfo implements Types.IBitcoinDetectionProvider | |
| }, []) | ||
| .filter((output: any) => output.output.scriptpubkey_address === addressInfo.address) | ||
| .map( | ||
| (output: any): Types.IPaymentNetworkEvent => ({ | ||
| (output: any): Types.BTCPaymentNetworkEvent => ({ | ||
| amount: output.output.value.toString(), | ||
| name: eventName, | ||
| parameters: { | ||
| amount: output.output.value.toString(), | ||
| block: output.blockHeight, | ||
| timestamp: output.timestamp, | ||
| txHash: output.txHash, | ||
| }, | ||
| timestamp: output.timestamp, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }), | ||
| ); | ||
|
|
||
| const balance: string = events | ||
| .reduce((balanceAccumulator: any, event: Types.IPaymentNetworkEvent) => { | ||
| return balanceAccumulator.add(new bigNumber(event.parameters.amount)); | ||
| .reduce((balanceAccumulator: any, event: Types.BTCPaymentNetworkEvent) => { | ||
| return balanceAccumulator.add(new bigNumber(event.amount)); | ||
| }, new bigNumber('0')) | ||
| .toString(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
less typing but more clarity... @romaric-juniet's brain may explode! 😄