Skip to content

Commit

Permalink
ALL-5690 Fix AddressTransaction type in non-breaking way
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj.bacovcin committed Apr 9, 2024
1 parent 9190d43 commit d61bc98
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [4.2.22] - 2024.4.9

### Fixed

- Fixed types for `getTransactions` method in `address` module.

## [4.2.21] - 2024.4.4

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "4.2.21",
"version": "4.2.22",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
48 changes: 33 additions & 15 deletions src/service/address/address.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,50 +109,68 @@ export interface GetAddressTransactionsQueryTezos {
cursor?: string
}

export interface AddressTransaction {
export interface AddrTxCommon {
/**
* Blockchain network
*/
chain: string
/**
* Block number
*/
blockNumber: number
/**
* Transaction hash
*/
hash: string
/**
* Transaction type
* Address, on which transaction occurred. This is receiver address for incoming transactions and sender address for outgoing transactions.
*/
transactionType: 'incoming' | 'outgoing' | 'zero-transfer'
address: string
/**
* Block number
*/
blockNumber: number
/**
* Amount transferred. For outgoing transactions, it's a negative number. For zero-transfer transactions, it's always 0. For incoming transactions, it's a positive number.
*/
amount: string
/**
* Index of the transaction in the block
*/
transactionIndex?: number
/**
* Transaction subtype (only relevant for non-UTXO chains, for UTXO chains this exists as transactionType)
*/
transactionSubtype?: 'incoming' | 'outgoing' | 'zero-transfer'
/**
* Address of the token collection, if the transaction is related to a token (ERC-20, ERC-721, ERC-1155)
*/
tokenAddress?: string
/**
* Token ID, if the transaction is related to a NFT (ERC-721) or MutiToken (ERC-1155)
* Token ID, if the transaction is related to an NFT (ERC-721) or MutiToken (ERC-1155)
*/
tokenId?: string
/**
* Amount transferred. For outgoing transactions, it's a negative number. For zero-transfer transactions, it's always 0. For incoming transactions, it's a positive number.
* Counter address of the transaction. This is sender address for incoming transactions on `address` and receiver address for outgoing transactions on `address`.
* Not all blockchain networks can identify the counter address (e.g. UTXO chains like Bitcoin e.g., where there is multiple senders or recipients). In this case, the counter address is not returned.
*/
amount: string
counterAddress?: string
}

export interface AddressTransaction extends AddrTxCommon {
/**
* Transaction timestamp - UTC millis
*/
timestamp: number
/**
* Address, on which transaction occurred. This is receiver address for incoming transactions and sender address for outgoing transactions.
* Transaction type
*/
address: string
transactionType: 'fungible' | 'nft' | 'multitoken' | 'native' | 'internal'
}

export interface AddressTransactionUTXO extends AddrTxCommon {
/**
* Counter address of the transaction. This is sender address for incoming transactions on `address` and receiver address for outgoing transactions on `address`.
* Not all blockchain networks can identify the counter address (UTXO chains like Bitcoin e.g., where there is multiple senders or recipients). In this case, the counter address is not returned.
* Transaction timestamp - UTC seconds
*/
counterAddress?: string
timestamp: number
/**
* Transaction type
*/
transactionType: 'incoming' | 'outgoing' | 'zero-transfer'
}
7 changes: 4 additions & 3 deletions src/service/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
AddressBalance,
AddressBalanceDataApi,
AddressTransaction,
AddressTransactionUTXO,
GetAddressTransactionsQuery,
GetAddressTransactionsQueryTezos,
} from './address.dto'
Expand Down Expand Up @@ -286,7 +287,7 @@ export class Address {
pageSize = 10,
page = 0,
tokenAddress,
}: GetAddressTransactionsQuery): Promise<ResponseDto<AddressTransaction[]>> {
}: GetAddressTransactionsQuery): Promise<ResponseDto<(AddressTransaction | AddressTransactionUTXO)[]>> {
const chain = this.config.network
return ErrorUtils.tryFail(async () => {
if (isDataApiEnabledNetwork(chain)) {
Expand Down Expand Up @@ -402,9 +403,9 @@ export class Address {
},
})
.then((r) => {
const result: AddressTransaction[] = []
const result: AddressTransactionUTXO[] = []
for (const tx of r) {
const item: AddressTransaction = {
const item: AddressTransactionUTXO = {
chain,
blockNumber: tx.blockNumber,
timestamp: tx.time,
Expand Down

0 comments on commit d61bc98

Please sign in to comment.