-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ALL-3150 - add bch estimatefee method (#1001)
- Loading branch information
Showing
11 changed files
with
166 additions
and
7 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,22 @@ | ||
import { BitcoinCash, Network } from '../../../service' | ||
import { UtxoE2eUtils, UtxoNetworkType } from './utxo.e2e.utils' | ||
|
||
describe('Bitcoin Cash', () => { | ||
describe('mainnet', () => { | ||
it('estimatefee', async () => { | ||
const tatum = await UtxoE2eUtils.initTatum<BitcoinCash>({ network: Network.BITCOIN_CASH, type: UtxoNetworkType.MAIN }) | ||
const result = await tatum.rpc.estimateFee() | ||
await tatum.destroy() | ||
expect(result.result).not.toBeNull() | ||
}) | ||
}) | ||
|
||
describe('testnet', () => { | ||
it('estimatefee', async () => { | ||
const tatum = await UtxoE2eUtils.initTatum<BitcoinCash>({ network: Network.BITCOIN_CASH, type: UtxoNetworkType.TEST }) | ||
const result = await tatum.rpc.estimateFee() | ||
await tatum.destroy() | ||
expect(result.result).not.toBeNull() | ||
}) | ||
}) | ||
}) |
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,9 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { JsonRpcResponse, UtxoBasedRpcInterfaceEstimateFee } from '../../../dto' | ||
import { AbstractUtxoRpc } from './AbstractUtxoRpc' | ||
|
||
export abstract class AbstractUtxoRpcEstimateFee extends AbstractUtxoRpc implements UtxoBasedRpcInterfaceEstimateFee { | ||
estimateFee(): Promise<JsonRpcResponse<any>> { | ||
return this.rpcCall<JsonRpcResponse<any>>('estimatefee') | ||
} | ||
} |
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,46 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Container, Service } from 'typedi' | ||
import { | ||
JsonRpcCall, | ||
JsonRpcResponse, | ||
UtxoBasedRpcSuiteEstimateFee, | ||
} from '../../../dto' | ||
import { Utils } from '../../../util' | ||
import { LoadBalancer } from '../generic' | ||
import { AbstractUtxoRpcEstimateFee } from './AbstractUtxoRpcEstimateFee' | ||
|
||
@Service({ | ||
factory: (data: { id: string }) => { | ||
return new UtxoLoadBalancerRpcEstimateFee(data.id) | ||
}, | ||
transient: true, | ||
}) | ||
export class UtxoLoadBalancerRpcEstimateFee extends AbstractUtxoRpcEstimateFee implements UtxoBasedRpcSuiteEstimateFee { | ||
protected readonly loadBalancerRpc: LoadBalancer | ||
|
||
constructor(id: string) { | ||
super() | ||
this.loadBalancerRpc = Container.of(id).get(LoadBalancer) | ||
} | ||
|
||
protected async rpcCall<T>(method: string, params?: unknown[]): Promise<T> { | ||
const preparedCall = Utils.prepareRpcCall(method, params) | ||
return (await this.loadBalancerRpc.rawRpcCall(preparedCall)) as T | ||
} | ||
|
||
async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>> { | ||
return this.loadBalancerRpc.rawRpcCall(body) | ||
} | ||
|
||
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[] | JsonRpcResponse<any>> { | ||
return this.loadBalancerRpc.rawBatchRpcCall(body) | ||
} | ||
|
||
public destroy() { | ||
this.loadBalancerRpc.destroy() | ||
} | ||
|
||
getRpcNodeUrl(): string { | ||
return this.loadBalancerRpc.getActiveNormalUrlWithFallback().url | ||
} | ||
} |
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,42 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Container, Service } from 'typedi' | ||
import { JsonRpcCall, JsonRpcResponse, UtxoBasedRpcSuiteEstimateFee } from '../../../dto' | ||
import { Utils } from '../../../util' | ||
import { GenericRpc } from '../generic' | ||
import { AbstractUtxoRpcEstimateFee } from './AbstractUtxoRpcEstimateFee' | ||
|
||
@Service({ | ||
factory: (data: { id: string }) => { | ||
return new UtxoRpcEstimateFee(data.id) | ||
}, | ||
transient: true, | ||
}) | ||
export class UtxoRpcEstimateFee extends AbstractUtxoRpcEstimateFee implements UtxoBasedRpcSuiteEstimateFee { | ||
public readonly genericRpc: GenericRpc | ||
|
||
constructor(id: string) { | ||
super() | ||
this.genericRpc = Container.of(id).get(GenericRpc) | ||
} | ||
|
||
protected async rpcCall<T>(method: string, params?: unknown[]): Promise<T> { | ||
const preparedCall = Utils.prepareRpcCall(method, params) | ||
return (await this.genericRpc.rawRpcCall(preparedCall)) as T | ||
} | ||
|
||
async rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[] | JsonRpcResponse<any>> { | ||
return this.genericRpc.rawBatchRpcCall(body) | ||
} | ||
|
||
async rawRpcCall<T>(body: JsonRpcCall): Promise<T> { | ||
return (await this.genericRpc.rawRpcCall(body)) as T | ||
} | ||
|
||
destroy(): void { | ||
// do nothing | ||
} | ||
|
||
getRpcNodeUrl(): string { | ||
return this.genericRpc.getRpcNodeUrl() | ||
} | ||
} |
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