Skip to content

Commit

Permalink
ALL-5502 - Add Kadena L0 (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel authored Mar 27, 2024
1 parent 60294ff commit 4d730d2
Show file tree
Hide file tree
Showing 15 changed files with 704 additions and 5 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.19] - 2024.3.27

### Added

- Added support for Kadena RPC calls

## [4.2.18] - 2024.3.22

### 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.18",
"version": "4.2.19",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
9 changes: 9 additions & 0 deletions src/connector/tatum.connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export class TatumConnector {
}) as Promise<RESPONSE>
}

public async put<RESPONSE, BODY extends DefaultBodyType = DefaultBodyType>(
request: SdkRequest<DefaultParamsType, BODY>,
) {
return this.request<RESPONSE, DefaultParamsType, BODY>({
...request,
method: 'PUT',
}) as Promise<RESPONSE>
}

public async delete<RESPONSE>(request: GetUrl) {
return this.request<RESPONSE>({ ...request, method: 'DELETE' }) as Promise<RESPONSE>
}
Expand Down
1 change: 1 addition & 0 deletions src/dto/Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export enum Currency {
EGLD = 'EGLD',
DOT = 'DOT',
BASE = 'BASE',
KADENA = 'KADENA',
}

export function networkToCurrency(network: Network): Currency {
Expand Down
17 changes: 17 additions & 0 deletions src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum Network {
GNOSIS = 'gno-mainnet',
HAQQ = 'haqq-mainnet',
HARMONY_ONE_SHARD_0 = 'one-mainnet-s0',
KADENA = 'kadena-mainnet',
KLAYTN = 'klaytn-mainnet',
KUCOIN = 'kcs-mainnet',
LITECOIN = 'litecoin-mainnet',
Expand Down Expand Up @@ -79,6 +80,7 @@ export enum Network {
HAQQ_TESTNET = 'haqq-testnet',
HARMONY_ONE_TESTNET_SHARD_0 = 'one-testnet-s0',
HORIZEN_EON_GOBI = 'horizen-eon-gobi',
KADENA_TESTNET = 'kadena-testnet',
KLAYTN_BAOBAB = 'klaytn-baobab',
KUCOIN_TESTNET = 'kcs-testnet',
LITECOIN_TESTNET = 'litecoin-testnet',
Expand Down Expand Up @@ -243,6 +245,7 @@ export const ALGORAND_ALGOD_NETWORKS = [Network.ALGORAND_ALGOD, Network.ALGORAND
export const ALGORAND_INDEXER_NETWORKS = [Network.ALGORAND_INDEXER, Network.ALGORAND_INDEXER_TESTNET]
export const CARDANO_NETWORKS = [Network.CARDANO_ROSETTA, Network.CARDANO_ROSETTA_PREPROD]
export const STELLAR_LOAD_BALANCER_NETWORKS = [Network.STELLAR]
export const KADENA_LOAD_BALANCER_NETWORKS = [Network.KADENA, Network.KADENA_TESTNET]

export const LOAD_BALANCER_NETWORKS = [
...UTXO_LOAD_BALANCER_NETWORKS,
Expand All @@ -259,6 +262,7 @@ export const LOAD_BALANCER_NETWORKS = [
...ALGORAND_INDEXER_NETWORKS,
...CARDANO_NETWORKS,
...STELLAR_LOAD_BALANCER_NETWORKS,
...KADENA_LOAD_BALANCER_NETWORKS,
]

export const EVM_ARCHIVE_NON_ARCHIVE_LOAD_BALANCER_NETWORKS = [
Expand Down Expand Up @@ -324,6 +328,9 @@ export const isEosLoadBalancerNetwork = (network: Network) => EOS_LOAD_BALANCER_

export const isXrpLoadBalancerNetwork = (network: Network) => XRP_LOAD_BALANCER_NETWORKS.includes(network)

export const isKadenaLoadBalancerNetwork = (network: Network) =>
KADENA_LOAD_BALANCER_NETWORKS.includes(network)

export const isNativeEvmLoadBalancerNetwork = (network: Network) =>
NATIVE_EVM_LOAD_BALANCER_NETWORKS.includes(network)

Expand Down Expand Up @@ -414,6 +421,16 @@ export const NETWORK_METADATA: Record<Network, NetworkMetadata> = {
defaultMainnet: true,
chainId: 137,
},
[Network.KADENA]: {
currency: Currency.KADENA,
testnet: false,
defaultMainnet: true,
},
[Network.KADENA_TESTNET]: {
currency: Currency.KADENA,
testnet: true,
defaultTestnet: true,
},
[Network.KLAYTN_BAOBAB]: {
currency: Currency.KLAY,
testnet: true,
Expand Down
205 changes: 205 additions & 0 deletions src/dto/rpc/KadenaRpcSuite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

export type ChainwebVersion = 'test-singleton' | 'development' | 'mainnet01' | 'testnet04'

export type SignedTransactionText = string

export interface SHA256Hash {
hash: string
}

export type Base64UrlBlockHeader = string

export interface Payload {
transactions: string[]
minerData: string
transactionsHash: SHA256Hash
outputsHash: SHA256Hash
payloadHash: SHA256Hash
}

export interface PayloadWithOutputs {
transactions: [
{
Base64Url: string
description: string
},
{
Base64Url: string
description: string
},
][]
minerData: string
transactionsHash: SHA256Hash
outputsHash: SHA256Hash
payloadHash: SHA256Hash
coinbase: string
}

export interface Peer {
id: string | null
address: {
hostname: string
port: number
}
network: NetworkParams
}

export interface Cut {
origin: Peer
height: number
weight: string
hashes: {
[key: string]: HashWithBlockHeight
}
instance?: string
id?: string
network: ApiParams
}

export interface HashWithBlockHeight {
hash: string
height: number
}

export interface ChainwebNodeInfo {
nodeNumberOfChains: number
nodeApiVersion: string
nodeChains: string[]
nodeVersion: ChainwebVersion
nodeLatestBehaviorHeight: number
nodeGraphHistory: [
number,
{
[chainId: number]: number[]
},
][]
}

export interface BlockHashesPage {
limit: number
next: string | null
items: any[]
}

export interface Base64HashesPage {
limit: number
next: string | null
items: Base64UrlBlockHeader[]
}

export type PayloadHashArray = Array<SHA256Hash>

export interface PayloadBatchQuery {
heights: number[]
hashes: SHA256Hash[]
}

export interface PayloadRequest {
body: PayloadBatchQuery | PayloadHashArray
network: NetworkParams
}

export interface GetBlockParams {
query?: {
limit?: number
next?: string
minheight?: number
maxheight?: number
}
network: NetworkParams
}

export interface NetworkParams {
chain: string
nodeVersion: ChainwebVersion
apiVersion: string
}

export interface ApiParams {
nodeVersion: ChainwebVersion
apiVersion: string
}

export interface PendingTransactionsResponse {
hashes: string[]
highwaterMark: [number, number]
}

export interface GetBlockParamsLowerUpper extends GetBlockParams {
lower: string[]
upper: string[]
}

export interface GetCurrentCutParams {
maxheight?: number
network: ApiParams
}

export interface GetCutNetworkPeerInfoParams {
limit?: string
next?: string
network: NetworkParams
}

export interface InsertTransactionIntoMempoolParams {
body: string[]
network: NetworkParams
}

export interface MempoolTransactionsParams {
headers: Base64UrlBlockHeader[]
network: NetworkParams
}

export interface GetBlockHeaderByHashParams {
blockHash: string
network: NetworkParams
}

export interface GetPayloadByHashParams {
payloadHash: string
height?: number
network: NetworkParams
}

export interface GetBlockPayloadWithOutputsParams {
payloadHash: string
height: number
network: NetworkParams
}

export interface GetPendingTransactionsParams {
nonce?: number
since?: number
network: NetworkParams
}

export interface KadenaRpcInterface {
getCurrentCut(params: GetCurrentCutParams): Promise<Cut>
publishCut(params: Cut): Promise<void>
getCutNetworkPeerInfo(params: GetCutNetworkPeerInfoParams): Promise<{
items: Peer[]
page: BlockHashesPage
}>
putCutNetworkPeerInfo(params: Peer & NetworkParams): Promise<void>
getBlockHashes(params: GetBlockParams): Promise<BlockHashesPage>
getBlockHashBranches(params: GetBlockParamsLowerUpper): Promise<BlockHashesPage>
getBlock(params: GetBlockParams): Promise<BlockHashesPage>
getBlockBranches(params: GetBlockParamsLowerUpper): Promise<BlockHashesPage>
getBlockHeaders(params: GetBlockParams): Promise<Base64HashesPage>
getBlockHeaderByHash(params: GetBlockHeaderByHashParams): Promise<Base64UrlBlockHeader>
getBlockHeaderBranches(params: GetBlockParamsLowerUpper): Promise<BlockHashesPage>
getPayloadByHash(params: GetPayloadByHashParams): Promise<Payload>
getBatchOfBlockPayload(params: PayloadRequest): Promise<Payload[]>
getBlockPayloadWithOutputs(params: GetBlockPayloadWithOutputsParams): Promise<PayloadWithOutputs>
getBatchBlockPayloadWithOutputs(params: PayloadRequest): Promise<Array<PayloadWithOutputs>>
getPendingTransactions(params: GetPendingTransactionsParams): Promise<PendingTransactionsResponse>
checkPendingTransactionsInMempool(params: MempoolTransactionsParams): Promise<boolean[]>
lookupMempoolTransactions(
params: MempoolTransactionsParams,
): Promise<Array<{ tag: 'Missing' | 'Pending'; contents?: SignedTransactionText }>>
insertTransactionsIntoMempool(params: InsertTransactionIntoMempoolParams): Promise<void>
checkNodeHealth(): Promise<string>
getNodeInfo(): Promise<ChainwebNodeInfo>
}
2 changes: 1 addition & 1 deletion src/dto/shared.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ export interface TokenDetails {
}

export type QueryValue = string | number | boolean | string[] | number[] | boolean[]
export type QueryParams = Record<string, QueryValue>
export type QueryParams = Partial<Record<string, QueryValue>>
2 changes: 1 addition & 1 deletion src/e2e/rpc/evm/evm.rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const testNetworks = [
{
network: Network.XINFIN,
},
{ network: Network.CRONOS },
// { network: Network.CRONOS },
{ network: Network.CRONOS_TESTNET, apiKey: process.env.V3_API_KEY_TESTNET },
{ network: Network.BASE },
]
Expand Down
Loading

0 comments on commit 4d730d2

Please sign in to comment.