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

Bugfix/all 4863 doge getblock #1067

Merged
merged 7 commits into from
Feb 22, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [4.2.11] - 2024.2.22

### Fixed

- Fixed the `getBlock` method for Doge, addressing an issue with the second boolean parameter.

## [4.2.10] - 2024.2.22

### Fixed
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.10",
"version": "4.2.11",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
11 changes: 6 additions & 5 deletions src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ export const UTXO_BASED_NETWORKS = [
Network.LITECOIN,
Network.LITECOIN_TESTNET,
Network.ZCASH,
Network.ZCASH_TESTNET,
Network.DOGECOIN,
Network.DOGECOIN_TESTNET,
Network.ZCASH_TESTNET
]

export const UTXO_LOAD_BALANCER_ESTIMATE_FEE_NETWORKS = [Network.BITCOIN_CASH]
Expand Down Expand Up @@ -200,12 +198,12 @@ export const UTXO_LOAD_BALANCER_NETWORKS = [
Network.BITCOIN_TESTNET,
Network.LITECOIN,
Network.LITECOIN_TESTNET,
Network.DOGECOIN,
Network.DOGECOIN_TESTNET,
Network.ZCASH,
Network.BITCOIN_CASH,
]

export const DOGECOIN_LOAD_BALANCED_NETWORKS = [Network.DOGECOIN, Network.DOGECOIN_TESTNET]

export const EVM_LOAD_BALANCER_NETWORKS = [
Network.FLARE,
Network.FLARE_COSTON,
Expand Down Expand Up @@ -246,6 +244,7 @@ export const STELLAR_LOAD_BALANCER_NETWORKS = [Network.STELLAR]

export const LOAD_BALANCER_NETWORKS = [
...UTXO_LOAD_BALANCER_NETWORKS,
...DOGECOIN_LOAD_BALANCED_NETWORKS,
...EVM_LOAD_BALANCER_NETWORKS,
...TRON_LOAD_BALANCER_NETWORKS,
...EOS_LOAD_BALANCER_NETWORKS,
Expand Down Expand Up @@ -286,6 +285,8 @@ export const isUtxoBasedNetwork = (network: Network) => UTXO_BASED_NETWORKS.incl
export const isUtxoLoadBalancerEstimateFeeNetwork = (network: Network) =>
UTXO_LOAD_BALANCER_ESTIMATE_FEE_NETWORKS.includes(network)

export const isDogecoinLoadBalancedNetwork = (network: Network) => DOGECOIN_LOAD_BALANCED_NETWORKS.includes(network)

export const isUtxoEstimateFeeNetwork = (network: Network) => UTXO_ESTIMATE_FEE_NETWORKS.includes(network)

export const isUtxoLoadBalancerNetwork = (network: Network) => UTXO_LOAD_BALANCER_NETWORKS.includes(network)
Expand Down
11 changes: 11 additions & 0 deletions src/dto/rpc/DogeRpcSuite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { JsonRpcResponse } from '../JsonRpcResponse.dto'
import { AbstractRpcInterface } from './AbstractJsonRpcInterface'
import { UtxoBasedCommonRpcInterface } from './UtxoBasedRpcSuite'

export interface DogeRpcSuite extends DogeRpcInterface, AbstractRpcInterface {}

export interface DogeRpcInterface extends UtxoBasedCommonRpcInterface{
getBlock(hashOrHeight: string, verbose?: boolean): Promise<JsonRpcResponse<any>>
}
7 changes: 5 additions & 2 deletions src/dto/rpc/UtxoBasedRpcSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { AbstractRpcInterface } from './AbstractJsonRpcInterface'

export interface UtxoBasedRpcSuite extends UtxoBasedRpcInterface, AbstractRpcInterface {}

export interface UtxoBasedRpcInterface {
export interface UtxoBasedCommonRpcInterface {
// blockchain methods
getBestBlockHash(): Promise<JsonRpcResponse<string>>
getBlock(hashOrHeight: string, verbose?: 0 | 1 | 2): Promise<JsonRpcResponse<any>>
getBlockChainInfo(): Promise<JsonRpcResponse<any>>
getBlockCount(): Promise<JsonRpcResponse<number>>
getBlockHash(height: number): Promise<JsonRpcResponse<string>>
Expand Down Expand Up @@ -46,6 +45,10 @@ export interface UtxoBasedRpcInterface {
verifyMessage(address: string, signature: string, message: string): Promise<JsonRpcResponse<boolean>>
}

export interface UtxoBasedRpcInterface extends UtxoBasedCommonRpcInterface{
getBlock(hashOrHeight: string, verbose?: 0 | 1 | 2): Promise<JsonRpcResponse<any>>
}

export interface UtxoBasedRpcInterfaceEstimateFee extends UtxoBasedRpcInterface {
estimateFee(): Promise<JsonRpcResponse<any>>
}
Expand Down
1 change: 1 addition & 0 deletions src/dto/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './TezosRpcSuite'
export * from './TronRpcSuite'
export * from './UtxoBasedRpcSuite'
export * from './XrpRpcSuite'
export * from './DogeRpcSuite'
31 changes: 29 additions & 2 deletions src/e2e/rpc/utxo/tatum.rpc.doge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Network } from '../../../service'
import { Dogecoin, Network } from '../../../service'
import { UtxoE2eUtils, UtxoNetworkType } from './utxo.e2e.utils'

describe('Doge', () => {
describe('mainnet', () => {
it('createrawtransaction', async () => {
const tatum = await UtxoE2eUtils.initTatum({ network: Network.DOGECOIN, type: UtxoNetworkType.MAIN })
const tatum = await UtxoE2eUtils.initTatum<Dogecoin>({ network: Network.DOGECOIN, type: UtxoNetworkType.MAIN })
const result = await tatum.rpc.createRawTransaction(
[
{
Expand All @@ -20,5 +20,32 @@ describe('Doge', () => {
expect(result.result).not.toBeNull()
await tatum.destroy()
})

it('getblock', async () => {
const tatum = await UtxoE2eUtils.initTatum<Dogecoin>({
network: Network.DOGECOIN,
type: UtxoNetworkType.MAIN,
})
const hash: string = '4cddee0cb7cc1e7a5d6a099285461e0470b2af8078dae35d5ac77e7c57bbc997'
const response1 = await tatum.rpc.getBlock(hash, true)

expect(response1).toBeDefined()
expect(response1.result).toStrictEqual(
expect.objectContaining({
hash,
version: 6422788,
height: 5092153,
size: 998443,
merkleroot: '8918a6f70a0ca3c9b4f745c86a7aa3a3d67d18b9c658eacb571c13d7fed0c7a7',
chainwork: '000000000000000000000000000000000000000000000f2239716b279a602583',
}),
)

const response2 = await tatum.rpc.getBlock(hash, false)
expect(response2).toBeDefined()
expect(typeof response2.result).toBe('string')

await tatum.destroy()
})
})
})
4 changes: 2 additions & 2 deletions src/e2e/rpc/utxo/utxo.e2e.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Network } from '../../../dto'
import { BaseUtxo, TatumSDK } from '../../../service'
import { BaseUtxo, TatumSDK, Dogecoin } from '../../../service'
import { e2eUtil } from '../../e2e.util'

export enum UtxoNetworkType {
Expand All @@ -15,7 +15,7 @@ interface TatumBtcUtils {
}

export const UtxoE2eUtils = {
initTatum: async <T extends BaseUtxo>(params: TatumBtcUtils) =>
initTatum: async <T extends BaseUtxo | Dogecoin>(params: TatumBtcUtils) =>
TatumSDK.init<T>(e2eUtil.initConfig(params.network, params.apiKey)),
e2e: (params: TatumBtcUtils) => {
const { type } = params
Expand Down
126 changes: 126 additions & 0 deletions src/service/rpc/utxo/AbstractCommonUtxoRpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { JsonRpcResponse, UtxoBasedCommonRpcInterface } from '../../../dto'

export abstract class AbstractCommonUtxoRpc implements UtxoBasedCommonRpcInterface {
protected abstract rpcCall<T>(method: string, params?: unknown[]): Promise<T>

async createRawTransaction(
inputs: any[],
outputs: any,
locktime: number,
replaceable: boolean,
): Promise<JsonRpcResponse<string>> {
const params: unknown[] = [inputs, outputs]
if (locktime) {
params.push(locktime)
}
if (replaceable) {
params.push(replaceable)
}
return this.rpcCall<JsonRpcResponse<string>>('createrawtransaction', params)
}

async decodeRawTransaction(hexstring: string): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('decoderawtransaction', [hexstring])
}

async decodeScript(hexstring: string): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('decodescript', [hexstring])
}

async estimateSmartFee(blocks: number, estimateMode?: string): Promise<JsonRpcResponse<any>> {
const params: unknown[] = [blocks]
if (estimateMode) {
params.push(estimateMode)
}
return this.rpcCall<JsonRpcResponse<any>>('estimatesmartfee', params)
}

async getBestBlockHash(): Promise<JsonRpcResponse<string>> {
return this.rpcCall<JsonRpcResponse<string>>('getbestblockhash')
}

async getBlockChainInfo(): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getblockchaininfo')
}

async getBlockCount(): Promise<JsonRpcResponse<number>> {
return this.rpcCall<JsonRpcResponse<number>>('getblockcount')
}

async getBlockHash(height: number): Promise<JsonRpcResponse<string>> {
return this.rpcCall<JsonRpcResponse<string>>('getblockhash', [height])
}

async getBlockHeader(hash: string, verbose = true): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getblockheader', [hash, verbose])
}

async getBlockStats(hash: string): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getblockstats', [hash])
}

async getChainTips(): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getchaintips')
}

async getDifficulty(): Promise<JsonRpcResponse<number>> {
return this.rpcCall<JsonRpcResponse<number>>('getdifficulty')
}

async getMempoolAncestors(txId: string, verbose = false): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getmempoolancestors', [txId, verbose])
}

async getMempoolDescendants(txId: string, verbose = false): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getmempooldescendants', [txId, verbose])
}

async getMempoolEntry(txId: string): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getmempoolentry', [txId])
}

async getMempoolInfo(): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getmempoolinfo')
}

async getRawMemPool(verbose = false): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getrawmempool', [verbose])
}

async getRawTransaction(txId: string, verbose = false): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getrawtransaction', [txId, verbose])
}

async getTxOut(txId: string, index: number, includeMempool = true): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('gettxout', [txId, index, includeMempool])
}

async getTxOutProof(txIds: string[], blockhash?: string): Promise<JsonRpcResponse<any>> {
const params: unknown[] = [txIds]
if (blockhash) {
params.push(blockhash)
}
return this.rpcCall<JsonRpcResponse<any>>('gettxoutproof', params)
}

async sendRawTransaction(hexstring: string): Promise<JsonRpcResponse<string>> {
return this.rpcCall<JsonRpcResponse<string>>('sendrawtransaction', [hexstring])
}

async validateAddress(address: string): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('validateaddress', [address])
}

async verifyMessage(
address: string,
signature: string,
message: string,
): Promise<JsonRpcResponse<boolean>> {
return this.rpcCall<JsonRpcResponse<boolean>>('verifymessage', [address, signature, message])
}

async verifyTxOutProof(proof: string): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('verifytxoutproof', [proof])
}
}
11 changes: 11 additions & 0 deletions src/service/rpc/utxo/AbstractDogeRpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DogeRpcInterface, JsonRpcResponse } from '../../../dto'
import { AbstractCommonUtxoRpc } from './AbstractCommonUtxoRpc'

export abstract class AbstractDogeRpc extends AbstractCommonUtxoRpc implements DogeRpcInterface {
protected abstract rpcCall<T>(method: string, params?: unknown[]): Promise<T>

async getBlock(hashOrHeight: string, verbose = true): Promise<JsonRpcResponse<any>> {
return this.rpcCall<JsonRpcResponse<any>>('getblock', [hashOrHeight, verbose])
}
}
Loading
Loading