Skip to content

Commit eb79ee3

Browse files
authored
ALL-3150 - add bch estimatefee method (#1001)
1 parent c5590f5 commit eb79ee3

File tree

11 files changed

+166
-7
lines changed

11 files changed

+166
-7
lines changed

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [4.1.15] - 2023.10.24
2+
### Added
3+
- Added estimatefee rpc method to the Bitcoin Cash network
4+
15
## [4.1.14] - 2023.10.23
26
### Added
37
- Added IPFS get file data method

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tatumio/tatum",
3-
"version": "4.1.14",
3+
"version": "4.1.15",
44
"description": "Tatum JS SDK",
55
"author": "Tatum",
66
"repository": "https://github.com/tatumio/tatum-js",

β€Žsrc/dto/Network.tsβ€Ž

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ export const UTXO_BASED_NETWORKS = [
160160
Network.DOGECOIN_TESTNET,
161161
]
162162

163+
export const UTXO_LOAD_BALANCER_ESTIMATE_FEE_NETWORKS = [
164+
Network.BITCOIN_CASH,
165+
]
166+
167+
export const UTXO_ESTIMATE_FEE_NETWORKS = [
168+
Network.BITCOIN_CASH_TESTNET,
169+
]
170+
163171
export const DATA_API_UTXO_NETWORKS = [
164172
Network.BITCOIN,
165173
Network.BITCOIN_TESTNET,
@@ -255,6 +263,12 @@ export const isEvmBasedNetwork = (network: Network) => EVM_BASED_NETWORKS.includ
255263

256264
export const isUtxoBasedNetwork = (network: Network) => UTXO_BASED_NETWORKS.includes(network)
257265

266+
export const isUtxoLoadBalancerEstimateFeeNetwork = (network: Network) => UTXO_LOAD_BALANCER_ESTIMATE_FEE_NETWORKS.includes(network)
267+
268+
export const isUtxoEstimateFeeNetwork = (network: Network) => UTXO_ESTIMATE_FEE_NETWORKS.includes(network)
269+
270+
export const isUtxoLoadBalancerNetwork = (network: Network) => UTXO_LOAD_BALANCER_NETWORKS.includes(network)
271+
258272
export const isXrpNetwork = (network: Network) => [Network.XRP, Network.XRP_TESTNET].includes(network)
259273

260274
export const isDataApiEvmEnabledNetwork = (network: Network) => DATA_API_EVM_NETWORKS.includes(network)
@@ -271,7 +285,6 @@ export const isEosNetwork = (network: Network) => EOS_NETWORKS.includes(network)
271285

272286
export const isLoadBalancerNetwork = (network: Network) => LOAD_BALANCER_NETWORKS.includes(network)
273287

274-
export const isUtxoLoadBalancerNetwork = (network: Network) => UTXO_LOAD_BALANCER_NETWORKS.includes(network)
275288

276289
export const isEvmLoadBalancerNetwork = (network: Network) => EVM_LOAD_BALANCER_NETWORKS.includes(network)
277290

β€Žsrc/dto/rpc/UtxoBasedRpcSuite.tsβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ export interface UtxoBasedRpcInterface {
4545
validateAddress(address: string): Promise<JsonRpcResponse<any>>
4646
verifyMessage(address: string, signature: string, message: string): Promise<JsonRpcResponse<boolean>>
4747
}
48+
49+
export interface UtxoBasedRpcInterfaceEstimateFee extends UtxoBasedRpcInterface {
50+
estimateFee(): Promise<JsonRpcResponse<any>>
51+
}
52+
53+
export interface UtxoBasedRpcSuiteEstimateFee extends UtxoBasedRpcSuite, UtxoBasedRpcInterfaceEstimateFee {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { BitcoinCash, Network } from '../../../service'
2+
import { UtxoE2eUtils, UtxoNetworkType } from './utxo.e2e.utils'
3+
4+
describe('Bitcoin Cash', () => {
5+
describe('mainnet', () => {
6+
it('estimatefee', async () => {
7+
const tatum = await UtxoE2eUtils.initTatum<BitcoinCash>({ network: Network.BITCOIN_CASH, type: UtxoNetworkType.MAIN })
8+
const result = await tatum.rpc.estimateFee()
9+
await tatum.destroy()
10+
expect(result.result).not.toBeNull()
11+
})
12+
})
13+
14+
describe('testnet', () => {
15+
it('estimatefee', async () => {
16+
const tatum = await UtxoE2eUtils.initTatum<BitcoinCash>({ network: Network.BITCOIN_CASH, type: UtxoNetworkType.TEST })
17+
const result = await tatum.rpc.estimateFee()
18+
await tatum.destroy()
19+
expect(result.result).not.toBeNull()
20+
})
21+
})
22+
})

β€Žsrc/e2e/rpc/utxo/utxo.e2e.utils.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ interface TatumBtcUtils {
1515
}
1616

1717
export const UtxoE2eUtils = {
18-
initTatum: async (params: TatumBtcUtils) =>
19-
TatumSDK.init<BaseUtxo>(RpcE2eUtils.initConfig(params.network, params.apiKey)),
18+
initTatum: async <T extends BaseUtxo>(params: TatumBtcUtils) =>
19+
TatumSDK.init<T>(RpcE2eUtils.initConfig(params.network, params.apiKey)),
2020
e2e: (params: TatumBtcUtils) => {
2121
const { type } = params
2222
it('chain info', async () => {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { JsonRpcResponse, UtxoBasedRpcInterfaceEstimateFee } from '../../../dto'
3+
import { AbstractUtxoRpc } from './AbstractUtxoRpc'
4+
5+
export abstract class AbstractUtxoRpcEstimateFee extends AbstractUtxoRpc implements UtxoBasedRpcInterfaceEstimateFee {
6+
estimateFee(): Promise<JsonRpcResponse<any>> {
7+
return this.rpcCall<JsonRpcResponse<any>>('estimatefee')
8+
}
9+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { Container, Service } from 'typedi'
3+
import {
4+
JsonRpcCall,
5+
JsonRpcResponse,
6+
UtxoBasedRpcSuiteEstimateFee,
7+
} from '../../../dto'
8+
import { Utils } from '../../../util'
9+
import { LoadBalancer } from '../generic'
10+
import { AbstractUtxoRpcEstimateFee } from './AbstractUtxoRpcEstimateFee'
11+
12+
@Service({
13+
factory: (data: { id: string }) => {
14+
return new UtxoLoadBalancerRpcEstimateFee(data.id)
15+
},
16+
transient: true,
17+
})
18+
export class UtxoLoadBalancerRpcEstimateFee extends AbstractUtxoRpcEstimateFee implements UtxoBasedRpcSuiteEstimateFee {
19+
protected readonly loadBalancerRpc: LoadBalancer
20+
21+
constructor(id: string) {
22+
super()
23+
this.loadBalancerRpc = Container.of(id).get(LoadBalancer)
24+
}
25+
26+
protected async rpcCall<T>(method: string, params?: unknown[]): Promise<T> {
27+
const preparedCall = Utils.prepareRpcCall(method, params)
28+
return (await this.loadBalancerRpc.rawRpcCall(preparedCall)) as T
29+
}
30+
31+
async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>> {
32+
return this.loadBalancerRpc.rawRpcCall(body)
33+
}
34+
35+
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[] | JsonRpcResponse<any>> {
36+
return this.loadBalancerRpc.rawBatchRpcCall(body)
37+
}
38+
39+
public destroy() {
40+
this.loadBalancerRpc.destroy()
41+
}
42+
43+
getRpcNodeUrl(): string {
44+
return this.loadBalancerRpc.getActiveNormalUrlWithFallback().url
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { Container, Service } from 'typedi'
3+
import { JsonRpcCall, JsonRpcResponse, UtxoBasedRpcSuiteEstimateFee } from '../../../dto'
4+
import { Utils } from '../../../util'
5+
import { GenericRpc } from '../generic'
6+
import { AbstractUtxoRpcEstimateFee } from './AbstractUtxoRpcEstimateFee'
7+
8+
@Service({
9+
factory: (data: { id: string }) => {
10+
return new UtxoRpcEstimateFee(data.id)
11+
},
12+
transient: true,
13+
})
14+
export class UtxoRpcEstimateFee extends AbstractUtxoRpcEstimateFee implements UtxoBasedRpcSuiteEstimateFee {
15+
public readonly genericRpc: GenericRpc
16+
17+
constructor(id: string) {
18+
super()
19+
this.genericRpc = Container.of(id).get(GenericRpc)
20+
}
21+
22+
protected async rpcCall<T>(method: string, params?: unknown[]): Promise<T> {
23+
const preparedCall = Utils.prepareRpcCall(method, params)
24+
return (await this.genericRpc.rawRpcCall(preparedCall)) as T
25+
}
26+
27+
async rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[] | JsonRpcResponse<any>> {
28+
return this.genericRpc.rawBatchRpcCall(body)
29+
}
30+
31+
async rawRpcCall<T>(body: JsonRpcCall): Promise<T> {
32+
return (await this.genericRpc.rawRpcCall(body)) as T
33+
}
34+
35+
destroy(): void {
36+
// do nothing
37+
}
38+
39+
getRpcNodeUrl(): string {
40+
return this.genericRpc.getRpcNodeUrl()
41+
}
42+
}

β€Žsrc/service/tatum/tatum.utxo.tsβ€Ž

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Container } from 'typedi'
2-
import { UtxoBasedRpcSuite } from '../../dto'
2+
import { UtxoBasedRpcSuite, UtxoBasedRpcSuiteEstimateFee } from '../../dto'
33
import { CONFIG, Utils } from '../../util'
44
import { Address } from '../address'
55
import { FeeUtxo } from '../fee'
@@ -49,5 +49,12 @@ export abstract class FullUtxo extends NotificationUtxo {
4949
export class Bitcoin extends FullUtxo {}
5050
export class Litecoin extends FullUtxo {}
5151
export class Dogecoin extends FullUtxo {}
52-
export class BitcoinCash extends NotificationUtxo {}
52+
export class BitcoinCash extends NotificationUtxo {
53+
rpc: UtxoBasedRpcSuiteEstimateFee
54+
55+
constructor(id: string) {
56+
super(id)
57+
this.rpc = Utils.getRpc<UtxoBasedRpcSuiteEstimateFee>(id, Container.of(id).get(CONFIG))
58+
}
59+
}
5360
export class ZCash extends BaseUtxo {}

0 commit comments

Comments
Β (0)