Skip to content
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

ALL-5690 Fix AddressTransaction type in non-breaking way #1088

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [4.2.22] - 2024.4.10

### Fixed

- Fixed types for `getTransactions` method in `address` module.
- Updated undici dependency.

## [4.2.21] - 2024.4.4

### Added
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -50,6 +50,6 @@
"ts-node": "^10.7.0",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"undici": "^5.21.0"
"undici": "^5.28.3"
}
}
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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2855,10 +2855,10 @@ undici-types@~5.26.4:
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

undici@^5.21.0:
version "5.28.2"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.2.tgz#fea200eac65fc7ecaff80a023d1a0543423b4c91"
integrity sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==
undici@^5.28.3:
version "5.28.4"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068"
integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==
dependencies:
"@fastify/busboy" "^2.0.0"

Expand Down
Loading