diff --git a/CHANGELOG.md b/CHANGELOG.md index d7548bdc4..eba04bdca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [4.2.32] - 2024.6.5 + +### Added + +- Support for cosmos additional api + ## [4.2.31] - 2024.6.3 ### Fixed diff --git a/package.json b/package.json index f47881aaf..003bcc46b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.2.31", + "version": "4.2.32", "description": "Tatum JS SDK", "author": "Tatum", "repository": "https://github.com/tatumio/tatum-js", diff --git a/src/dto/Network.ts b/src/dto/Network.ts index e1d14948f..b7ba566e7 100644 --- a/src/dto/Network.ts +++ b/src/dto/Network.ts @@ -254,6 +254,9 @@ export const CARDANO_NETWORKS = [ Network.CARDANO_ROSETTA_PREPROD, Network.COSMONS_ROSETTA, ] +export const COSMOS_NETWORKS = [ + Network.COSMONS_ROSETTA, +] export const STELLAR_LOAD_BALANCER_NETWORKS = [Network.STELLAR] export const KADENA_LOAD_BALANCER_NETWORKS = [Network.KADENA, Network.KADENA_TESTNET] export const ROSTRUM_LOAD_BALANCER_NETWORKS = [Network.ROSTRUM, Network.BITCOIN_ELECTRS] @@ -364,6 +367,8 @@ export const isAlgorandIndexerNetwork = (network: Network) => ALGORAND_INDEXER_N export const isCardanoNetwork = (network: Network) => CARDANO_NETWORKS.includes(network) +export const isCosmosNetwork = (network: Network) => COSMOS_NETWORKS.includes(network) + export const isStellarLoadBalancerNetwork = (network: Network) => STELLAR_LOAD_BALANCER_NETWORKS.includes(network) diff --git a/src/dto/rpc/CosmosRpcSuite.ts b/src/dto/rpc/CosmosRpcSuite.ts new file mode 100644 index 000000000..22dbbd31f --- /dev/null +++ b/src/dto/rpc/CosmosRpcSuite.ts @@ -0,0 +1,1440 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { CardanoRpcSuite } from './CardanoRpcSuite' + +export enum ProposalStatus { + PROPOSAL_STATUS_UNSPECIFIED = 'PROPOSAL_STATUS_UNSPECIFIED', + PROPOSAL_STATUS_DEPOSIT_PERIOD = 'PROPOSAL_STATUS_DEPOSIT_PERIOD', + PROPOSAL_STATUS_VOTING_PERIOD = 'PROPOSAL_STATUS_VOTING_PERIOD', + PROPOSAL_STATUS_PASSED = 'PROPOSAL_STATUS_PASSED', + PROPOSAL_STATUS_REJECTED = 'PROPOSAL_STATUS_REJECTED', + PROPOSAL_STATUS_FAILED = 'PROPOSAL_STATUS_FAILED', +} + +export interface PaginationRequest { + 'pagination.key'?: string + 'pagination.offset'?: number + 'pagination.limit'?: number + 'pagination.countTotal'?: boolean + 'pagination.reverse'?: boolean +} + +interface Proposal { + proposal_id: string; + content: { + "@type": string; + title: string; + description: string; + }; + status: string; + final_tally_result: { + yes: string; + abstain: string; + no: string; + no_with_veto: string; + }; + submit_time: string; + deposit_end_time: string; + total_deposit: { + denom: string; + amount: string; + }[]; + voting_start_time: string; + voting_end_time: string; +} + +interface PubKey { + "@type": string; + key: string; +} + +interface Account { + "@type": string; + address: string; + pub_key: PubKey; + account_number: string; + sequence: string; +} + +interface PaginationResponse { + next_key: string; + total: string; +} + +export interface GetAllProposalsResponse { + proposals: Proposal[]; + pagination: PaginationResponse; +} + +export interface GetAccountsResponse { + accounts: Account[]; + pagination: PaginationResponse; +} + +export interface GetAccountDetailsRequest { + address: string; +} + +export interface GetAccountDetailsResponse { + account: Account; +} + +interface Params { + max_memo_characters: string; + tx_sig_limit: string; + tx_size_cost_per_byte: string; + sig_verify_cost_ed25519: string; + sig_verify_cost_secp256k1: string; +} + +export interface GetAllParamsResponse { + params: Params; +} + +export interface GetAllBalancesRequest extends PaginationRequest { + address: string; +} + +interface Balance { + denom: string; + amount: string; +} + +export interface GetAllBalancesResponse { + balances: Balance[]; + pagination: PaginationResponse; +} + +interface DenomUnit { + denom: string; + exponent: number; + aliases: string[]; +} + +interface Metadata { + description: string; + denom_units: DenomUnit[]; + base: string; + display: string; + name: string; + symbol: string; +} + +export interface GetDenomsMetadataResponse { + metadatas: Metadata[]; + pagination: PaginationResponse; +} + +export interface GetDenomMetadataRequest { + denom: string; +} + +interface DenomUnit { + denom: string; + exponent: number; + aliases: string[]; +} + +interface Metadata { + description: string; + denom_units: DenomUnit[]; + base: string; + display: string; + name: string; + symbol: string; +} + +export interface GetDenomMetadataResponse { + metadata: Metadata; +} + + +interface BankParams { + send_enabled: any[]; + default_send_enabled: boolean; +} + +export interface GetBankParamsResponse { + params: BankParams; +} + +interface CoinSupply { + denom: string; + amount: string; +} + +export interface GetTotalSupplyResponse { + supply: CoinSupply[]; + pagination: PaginationResponse; +} + +export interface GetSupplyOfCoinRequest { + denom: string; +} + +interface CoinSupplyAmount { + denom: string; + amount: string; +} + +export interface GetSupplyOfCoinResponse { + amount: CoinSupplyAmount; +} + +interface BlockData { + txs: string[]; +} + +interface Block { + header: BlockHeader; + data: BlockData; + evidence: Evidence; + last_commit: LastCommit; +} + +export interface GetLatestBlockResponse { + block_id: BlockID; + block: Block; +} + +export interface GetBlockByHeightRequest { + height: number; +} + +interface BlockID { + hash: string; + part_set_header: { + total: number; + hash: string; + }; +} + +interface BlockHeader { + version: { + block: string; + app: string; + }; + chain_id: string; + height: string; + time: string; + last_block_id: BlockID; + last_commit_hash: string; + data_hash: string; + validators_hash: string; + next_validators_hash: string; + consensus_hash: string; + app_hash: string; + last_results_hash: string; + evidence_hash: string; + proposer_address: string; +} + +interface Evidence { + evidence: any[]; +} + +interface CommitSignature { + block_id_flag: string; + validator_address: string; + timestamp: string; + signature: string; +} + +interface LastCommit { + height: string; + round: number; + block_id: BlockID; + signatures: CommitSignature[]; +} + +export interface GetBlockByHeightResponse { + block_id: BlockID; + block: Block; +} + +interface ProtocolVersion { + p2p: string; + block: string; + app: string; +} + +interface DefaultNodeInfo { + protocol_version: ProtocolVersion; + default_node_id: string; + listen_addr: string; + network: string; + version: string; + channels: string; + moniker: string; + other: { + tx_index: string; + rpc_address: string; + }; +} + +interface BuildDependency { + path: string; + version: string; + sum: string; +} + +interface ApplicationVersion { + name: string; + app_name: string; + version: string; + git_commit: string; + build_tags: string; + go_version: string; + build_deps: BuildDependency[]; + cosmos_sdk_version: string; +} + +export interface GetNodeInfoResponse { + default_node_info: DefaultNodeInfo; + application_version: ApplicationVersion; +} + +export interface GetSyncingResponse { + syncing: boolean; +} + +interface ValidatorPubKey { + "@type": string; + key: string; +} + +interface Validator { + address: string; + pub_key: ValidatorPubKey; + voting_power: string; + proposer_priority: string; +} + + +export interface GetLatestValidatorSetResponse { + block_height: string; + validators: Validator[]; + pagination: PaginationResponse; +} + +export interface GetValidatorSetByHeightRequest extends PaginationRequest { + height: number; +} + +export interface GetValidatorSetByHeightResponse { + block_height: string; + validators: Validator[]; + pagination: PaginationResponse; +} + +interface CommunityPoolCoin { + denom: string; + amount: string; +} + +export interface GetCommunityPoolResponse { + pool: CommunityPoolCoin[]; +} + +interface Reward { + denom: string; + amount: string; +} + +interface ValidatorReward { + validator_address: string; + reward: Reward[]; +} + +export interface GetDelegationTotalRewardsResponse { + rewards: ValidatorReward[]; + total: Reward[]; +} + +export interface GetDelegationTotalRewardsRequest { + delegator_address: string; +} + +interface Reward { + denom: string; + amount: string; +} + +export interface GetDelegationRewardsResponse { + rewards: Reward[]; +} + +export interface GetDelegationRewardsRequest { + delegator_address: string; + validator_address: string; +} + +export interface GetDelegatorValidatorsResponse { + validators: string[]; +} +export interface GetDelegatorValidatorsRequest { + delegator_address: string; +} + +export interface GetDelegatorWithdrawAddressResponse { + withdraw_address: string; +} + +export interface GetDelegatorWithdrawAddressRequest { + delegator_address: string; +} + +interface DistributionParams { + community_tax: string; + base_proposer_reward: string; + bonus_proposer_reward: string; + withdraw_addr_enabled: boolean; +} + +export interface GetDistributionParamsResponse { + params: DistributionParams; +} + +interface CommissionAmount { + denom: string; + amount: string; +} + +interface ValidatorCommission { + commission: CommissionAmount[]; +} + +export interface GetValidatorCommissionResponse { + commission: ValidatorCommission; +} + +export interface GetValidatorCommissionRequest { + validator_address: string; +} + +interface OutstandingRewardsAmount { + denom: string; + amount: string; +} + +interface ValidatorOutstandingRewards { + rewards: OutstandingRewardsAmount[]; +} + +export interface GetValidatorOutstandingRewardsResponse { + rewards: ValidatorOutstandingRewards; +} + +export interface GetValidatorOutstandingRewardsRequest { + validator_address: string; +} + +interface SlashEvent { + validator_period: string; + fraction: string; +} + +export interface GetValidatorSlashesResponse { + slashes: SlashEvent[]; + pagination: PaginationResponse; +} + +export interface GetValidatorSlashesRequest extends PaginationRequest { + validator_address: string; + starting_height?: number; + ending_height?: number; +} + +export interface GetAllEvidenceResponse { + evidence: Evidence[]; + pagination: PaginationResponse; +} + +export interface GetGovernanceParamsResponse { + voting_params: { + voting_period: string; + }; + deposit_params: { + min_deposit: any[]; + max_deposit_period: string; + }; + tally_params: { + quorum: string; + threshold: string; + veto_threshold: string; + }; +} +export interface GetGovernanceParamsRequest { + params_type: 'voting' | 'tallying' | 'deposit'; +} + +interface Proposal { + proposal_id: string; + content: { + "@type": string; + title: string; + description: string; + }; + status: string; + final_tally_result: { + yes: string; + abstain: string; + no: string; + no_with_veto: string; + }; + submit_time: string; + deposit_end_time: string; + total_deposit: { + denom: string; + amount: string; + }[]; + voting_start_time: string; + voting_end_time: string; +} + +export interface GetAllProposalsResponse { + proposals: Proposal[]; + pagination: PaginationResponse; +} + +export interface GetAllProposalsRequest extends PaginationRequest { + proposal_status?: ProposalStatus; + voter?: string; + depositor?: string; +} + +export interface GetProposalDetailsResponse { + proposal: Proposal; +} + +export interface GetProposalDetailsRequest { + proposal_id: number; +} + +export interface GetDepositsResponse { + deposits: { + depositor: string; + amount: Reward[]; + }[]; + pagination: PaginationResponse; +} + +export interface GetDepositsRequest { + proposal_id: number; +} + +export interface GetTallyResultResponse { + tally: { + yes: string; + abstain: string; + no: string; + no_with_veto: string; + }; +} + +export interface GetTallyResultRequest { + proposal_id: number; +} + +interface VoteOption { + option: string; + weight: string; +} + +interface Vote { + proposal_id: string; + voter: string; + option: string; + options: VoteOption[]; +} + +interface SlashEvent { + validator_period: string; + fraction: string; +} + +export interface GetVotesResponse { + votes: Vote[]; + pagination: PaginationResponse; +} + +export interface GetVotesRequest extends PaginationRequest { + proposal_id: number; +} + +interface Proposal { + proposal_id: string; + content: { + "@type": string; + title: string; + description: string; + }; + status: string; + final_tally_result: { + yes: string; + abstain: string; + no: string; + no_with_veto: string; + }; + submit_time: string; + deposit_end_time: string; + total_deposit: { + denom: string; + amount: string; + }[]; + voting_start_time: string; + voting_end_time: string; +} + +export interface GetTallyResultResponse { + tally: { + yes: string; + abstain: string; + no: string; + no_with_veto: string; + }; +} + +export interface GetTallyResultRequest { + proposal_id: number; +} + +export interface GetVotesResponse { + votes: Vote[]; + pagination: PaginationResponse; +} + +export interface GetVotesRequest extends PaginationRequest { + proposal_id: number; +} + +export interface GetVoteResponse { + vote: Vote; +} + +export interface GetVoteRequest { + proposal_id: number; + voter: string; +} + +export interface GetAnnualProvisionsResponse { + annual_provisions: string; +} + +export interface GetInflationResponse { + inflation: string; +} + +interface MintingParams { + mint_denom: string; + inflation_rate_change: string; + inflation_max: string; + inflation_min: string; + goal_bonded: string; + blocks_per_year: string; +} + +export interface GetMintingParamsResponse { + params: MintingParams; +} + +export interface GetSpecificParamResponse { + param: { + subspace: string; + key: string; + value: string; + }; +} + +export interface GetSpecificParamRequest { + subspace: string; + key: string; +} + +interface SlashingParams { + signed_blocks_window: string; + min_signed_per_window: string; + downtime_jail_duration: string; + slash_fraction_double_sign: string; + slash_fraction_downtime: string; +} + +export interface GetSlashingParamsResponse { + params: SlashingParams; +} + +interface SigningInfo { + address: string; + start_height: string; + index_offset: string; + jailed_until: string; + tombstoned: boolean; + missed_blocks_counter: string; +} + +export interface GetSigningInfosResponse { + info: SigningInfo[]; + pagination: PaginationResponse; +} + +interface SigningInfo { + address: string; + start_height: string; + index_offset: string; + jailed_until: string; + tombstoned: boolean; + missed_blocks_counter: string; +} + +export interface GetSigningInfoByConsAddressResponse { + val_signing_info: SigningInfo; +} + +export interface GetSigningInfoByConsAddressRequest { + cons_address: string; +} + +interface Coin { + denom: string; + amount: string; +} + +interface Delegation { + delegator_address: string; + validator_address: string; + shares: string; +} + +interface DelegationResponse { + delegation: Delegation; + balance: Coin; +} + +export interface GetDelegationsResponse { + delegation_responses: DelegationResponse[]; + pagination: PaginationResponse; +} + +export interface GetDelegationsRequest extends PaginationRequest { + delegator_address: string; +} + +interface RedelegationEntry { + creation_height: string; + completion_time: string; + initial_balance: string; + shares_dst: string; +} + +interface Redelegation { + delegator_address: string; + validator_src_address: string; + validator_dst_address: string; + entries: RedelegationEntry[]; +} + +interface RedelegationResponse { + redelegation: Redelegation; +} + +export interface GetRedelegationsResponse { + redelegation_responses: RedelegationResponse[]; + pagination: PaginationResponse; +} + +export interface GetRedelegationsRequest extends PaginationRequest { + delegator_addr: string; + src_validator_addr?: string; + dst_validator_addr?: string; +} + +interface UnbondingDelegationEntry { + creation_height: string; + completion_time: string; + initial_balance: string; + balance: string; +} + +interface UnbondingDelegation { + delegator_address: string; + validator_address: string; + entries: UnbondingDelegationEntry[]; +} + +export interface UnbondingDelegationResponse { + unbonding_responses: UnbondingDelegation[]; + pagination: PaginationResponse; +} + +export interface GetUnbondingDelegationsRequest extends PaginationRequest { + delegator_addr: string; +} + +interface ValidatorDescription { + moniker: string; + identity: string; + website: string; + security_contact: string; + details: string; +} + +interface CommissionRates { + rate: string; + max_rate: string; + max_change_rate: string; +} + +interface Commission { + commission_rates: CommissionRates; + update_time: string; +} + +interface ConsensusPubkey { + "@type": string; + key: string; +} + +interface Validator { + operator_address: string; + consensus_pubkey: ConsensusPubkey; + jailed: boolean; + status: string; + tokens: string; + delegator_shares: string; + description: ValidatorDescription; + unbonding_height: string; + unbonding_time: string; + commission: Commission; + min_self_delegation: string; +} + +export interface GetValidatorsResponse { + validators: Validator[]; + pagination: PaginationResponse; +} + +export interface GetValidatorsRequest extends PaginationRequest { + delegator_addr: string; +} + +interface ValidatorDescription { + moniker: string; + identity: string; + website: string; + security_contact: string; + details: string; +} + +interface CommissionRates { + rate: string; + max_rate: string; + max_change_rate: string; +} + +interface Commission { + commission_rates: CommissionRates; + update_time: string; +} + +interface ConsensusPubkey { + "@type": string; + key: string; +} + +interface Validator { + operator_address: string; + consensus_pubkey: ConsensusPubkey; + jailed: boolean; + status: string; + tokens: string; + delegator_shares: string; + description: ValidatorDescription; + unbonding_height: string; + unbonding_time: string; + commission: Commission; + min_self_delegation: string; +} + +export interface GetValidatorInfoResponse { + validator: Validator; +} + +export interface GetValidatorInfoRequest { + delegator_addr: string; + validator_addr: string; +} + +interface BlockVersion { + block: string; + app: string; +} + +interface PartSetHeader { + total: number; + hash: string; +} + +interface BlockID { + hash: string; + part_set_header: PartSetHeader; +} + +interface BlockHeader { + version: BlockVersion; + chain_id: string; + height: string; + time: string; + last_block_id: BlockID; + last_commit_hash: string; + data_hash: string; + validators_hash: string; + next_validators_hash: string; + consensus_hash: string; + app_hash: string; + last_results_hash: string; + evidence_hash: string; + proposer_address: string; +} + +interface ValidatorDescription { + moniker: string; + identity: string; + website: string; + security_contact: string; + details: string; +} + +interface CommissionRates { + rate: string; + max_rate: string; + max_change_rate: string; +} + +interface Commission { + commission_rates: CommissionRates; + update_time: string; +} + +interface ConsensusPubkey { + "@type": string; + key: string; +} + +interface Validator { + operator_address: string; + consensus_pubkey: ConsensusPubkey; + jailed: boolean; + status: string; + tokens: string; + delegator_shares: string; + description: ValidatorDescription; + unbonding_height: string; + unbonding_time: string; + commission: Commission; + min_self_delegation: string; +} + +interface HistoricalInfo { + header: BlockHeader; + valset: Validator[]; +} + +export interface GetHistoricalInfoResponse { + hist: HistoricalInfo; +} + +export interface GetHistoricalInfoRequest { + height: number; +} + +interface StakingParams { + unbonding_time: string; + max_validators: number; + max_entries: number; + historical_entries: number; + bond_denom: string; +} + +export interface GetStakingParamsResponse { + params: StakingParams; +} + +interface PoolInfo { + not_bonded_tokens: string; + bonded_tokens: string; +} + +export interface GetPoolInfoResponse { + pool: PoolInfo; +} + +interface ValidatorDescription { + moniker: string; + identity: string; + website: string; + security_contact: string; + details: string; +} + +interface CommissionRates { + rate: string; + max_rate: string; + max_change_rate: string; +} + +interface Commission { + commission_rates: CommissionRates; + update_time: string; +} + +interface ConsensusPubkey { + '@type': string; + key: string; +} + +interface Validator { + operator_address: string; + consensus_pubkey: ConsensusPubkey; + jailed: boolean; + status: string; + tokens: string; + delegator_shares: string; + description: ValidatorDescription; + unbonding_height: string; + unbonding_time: string; + commission: Commission; + min_self_delegation: string; +} + +export interface GetValidatorsResponse { + validators: Validator[]; + pagination: PaginationResponse; +} + +export interface GetValidatorsRequest extends PaginationRequest { + status?: string; +} + +interface ValidatorDescription { + moniker: string; + identity: string; + website: string; + security_contact: string; + details: string; +} + +interface CommissionRates { + rate: string; + max_rate: string; + max_change_rate: string; +} + +interface Commission { + commission_rates: CommissionRates; + update_time: string; +} + +interface ConsensusPubkey { + '@type': string; + key: string; +} + +interface Validator { + operator_address: string; + consensus_pubkey: ConsensusPubkey; + jailed: boolean; + status: string; + tokens: string; + delegator_shares: string; + description: ValidatorDescription; + unbonding_height: string; + unbonding_time: string; + commission: Commission; + min_self_delegation: string; +} + +export interface GetValidatorInfoResponse { + validator: Validator; +} + +export interface GetValidatorInfoRequest { + validator_addr: string; +} + +interface Balance { + denom: string; + amount: string; +} + +interface Delegation { + delegator_address: string; + validator_address: string; + shares: string; +} + +interface DelegationResponse { + delegation: Delegation; + balance: Balance; +} + +export interface GetDelegationsResponse { + delegation_responses: DelegationResponse[]; + pagination: PaginationResponse; +} + +export interface GetDelegationsRequest extends PaginationRequest { + validator_addr: string; +} + +interface UnbondingDelegationEntry { + creation_height: string; + completion_time: string; + initial_balance: string; + balance: string; +} + +interface UnbondingDelegation { + delegator_address: string; + validator_address: string; + entries: UnbondingDelegationEntry[]; +} + +export interface GetUnbondingDelegationResponse { + unbond: UnbondingDelegation; +} + +export interface GetUnbondingDelegationRequest { + validator_addr: string; + delegator_addr: string; +} + +export interface GetAppliedPlanResponse { + height: string; +} + +export interface GetAppliedPlanRequest { + name: string; +} + +export interface UpgradePlan { + name: string; + time: string; + height: string; + info: string; + upgraded_client_state: any | null; +} + +export interface GetCurrentPlanResponse { + plan: UpgradePlan; +} + +export interface ModuleVersion { + name: string; + version: string; +} + +export interface GetModuleVersionsResponse { + module_versions: ModuleVersion[]; +} + +export interface GetUpgradedConsensusStateResponse { + upgraded_consensus_state: any; +} + +export interface Authorization { + '@type': string; + msg: string; +} + +export interface Grant { + authorization: Authorization; + expiration: string; +} + +export interface GetGrantsResponse extends PaginationResponse { + grants: Grant[]; +} + +export interface GetGrantsRequest extends PaginationRequest { + granter: string; + grantee: string; + msg_type_url?: string; +} + +export interface SpendLimit { + denom: string; + amount: string; +} + +export interface BasicAllowance { + '@type': string; + spend_limit: SpendLimit[]; + expiration: string | null; +} + +export interface Allowance { + granter: string; + grantee: string; + allowance: BasicAllowance; +} + +export interface GetAllowanceResponse { + allowance: Allowance; +} + +export interface GetAllowanceRequest { + granter: string; + grantee: string; +} + +export interface GetGrantsForAddressRequest extends PaginationRequest { + grantee: string +} + +export interface GetGrantsForAddressResponse extends PaginationRequest { + allowances: Allowance[] +} + +export interface Message { + '@type': string; + [key: string]: any; +} + +export interface Amount { + denom: string; + amount: string; +} + +export interface Fee { + amount: Amount[]; + gas_limit: string; + payer: string; + granter: string; +} + +export interface PublicKey { + '@type': string; + key: string; +} + +export interface ModeInfo { + single: { + mode: string; + }; +} + +export interface SignerInfo { + public_key: PublicKey; + mode_info: ModeInfo; + sequence: string; +} + +export interface AuthInfo { + signer_infos: SignerInfo[]; + fee: Fee; +} + +export interface TxBody { + messages: Message[]; + memo: string; + timeout_height: string; + extension_options: any[]; + non_critical_extension_options: any[]; +} + +export interface Tx { + body: TxBody; + auth_info: AuthInfo; + signatures: string[]; +} + +export interface SimulateRequest { + tx: Tx; +} + +export interface GasInfo { + gas_wanted: string; + gas_used: string; +} + +export interface Attribute { + key: string; + value: string; + index: boolean; +} + +export interface Event { + type: string; + attributes: Attribute[]; +} + +export interface Result { + data: string; + log: string; + events: Event[]; +} + +export interface SimulateResponse { + gas_info: GasInfo; + result: Result; +} + +export interface TxsByEventRequest extends PaginationRequest { + events?: string[]; + order_by?: 'ORDER_BY_UNSPECIFIED' | 'ORDER_BY_ASC' | 'ORDER_BY_DESC'; +} + +export interface TxsByEventResponse extends PaginationResponse { + txs: Tx[]; + tx_responses: Tx[]; +} + +export interface BroadcastTxRequest { + tx_bytes: string; + mode: 'BROADCAST_MODE_UNSPECIFIED' | 'BROADCAST_MODE_BLOCK' | 'BROADCAST_MODE_SYNC' | 'BROADCAST_MODE_ASYNC'; +} + +export interface TxResponse { + height: string; + txhash: string; + codespace: string; + code: number; + data: string; + raw_log: string; + logs: any[]; + info: string; + gas_wanted: string; + gas_used: string; + tx: any; + timestamp: string; +} + +export interface BroadcastTxResponse { + tx_response: TxResponse; +} + +export interface CosmosRpcSuite extends CardanoRpcSuite { + getAccounts(params?: PaginationRequest): Promise + + getAccountDetails(params: GetAccountDetailsRequest): Promise + + getAllParams(): Promise + + getAllBalances(params: GetAllBalancesRequest): Promise + + getDenomsMetadata(params?: PaginationRequest): Promise + + getDenomMetadata(params: GetDenomMetadataRequest): Promise + + getBankParams(): Promise + + getTotalSupply(params?: PaginationRequest): Promise + + getSupplyOfCoin(params: GetSupplyOfCoinRequest): Promise + + getLatestBlock(): Promise + + getBlockByHeight(params: GetBlockByHeightRequest): Promise + + getNodeInfo(): Promise + + getSyncing(): Promise + + getLatestValidatorSet(params?: PaginationRequest): Promise + + getValidatorSetByHeight(params: GetValidatorSetByHeightRequest): Promise + + getCommunityPool(): Promise + + getDelegateTotalRewards(params: GetDelegationTotalRewardsRequest): Promise + + getDelegateRewards(params: GetDelegationRewardsRequest): Promise + + getDelegatorValidators(params: GetDelegatorValidatorsRequest): Promise + + getDelegatorWithdrawAddress(params: GetDelegatorWithdrawAddressRequest): Promise + + getDistributionParams(): Promise + + getValidatorCommission(params: GetValidatorCommissionRequest): Promise + + getValidatorOutstandingRewards(params: GetValidatorOutstandingRewardsRequest): Promise + + getValidatorSlashes(params: GetValidatorSlashesRequest): Promise + + getAllEvidence(params?: PaginationRequest): Promise + + getGovernanceParams(params: GetGovernanceParamsRequest): Promise + + getAllProposals(params: GetAllProposalsRequest): Promise + + getProposalDetails(params: GetProposalDetailsRequest): Promise + + getDeposits(params: GetDepositsRequest): Promise + + getTallyResult(params: GetTallyResultRequest): Promise + + getVotes(params: GetVotesRequest): Promise + + getVote(params: GetVoteRequest): Promise + + getAnnualProvisions(): Promise + + getInflation(): Promise + + getMintingParams(): Promise + + getSpecificParam(params: GetSpecificParamRequest): Promise + + getSlashingParams(): Promise + + getSigningInfos(params?: PaginationRequest): Promise + + getSingingInfoByConsAddress(params: GetSigningInfoByConsAddressRequest): Promise + + getDelegations(params: GetDelegationsRequest): Promise + + getRedelegations(params: GetRedelegationsRequest): Promise + + getUnbondingDelegations(params: GetUnbondingDelegationsRequest): Promise + + getValidators(params: GetValidatorsRequest): Promise + + getValidatorInfo(params: GetValidatorInfoRequest): Promise + + getHistoricalInfo(params: GetHistoricalInfoRequest): Promise + + getStakingParams(): Promise + + getPoolInfo(): Promise + + getValidatorsForGivenStatus(params: GetValidatorsRequest): Promise + + getValidatorInfoForAddress(params: GetValidatorInfoRequest): Promise + + getDelegationsForValidator(params: GetDelegationsRequest): Promise + + getUnbondingDelegation(params: GetUnbondingDelegationRequest): Promise + + getAppliedPlan(params: GetAppliedPlanRequest): Promise + + getCurrentPlan(): Promise + + getModuleVersions(): Promise + + getUpgradedConsensusState(lastHeight: number): Promise + + getGrants(params: GetGrantsRequest): Promise + + getAllowance(params: GetAllowanceRequest): Promise + + getAllowanceForAddress(params: GetGrantsForAddressRequest): Promise + + simulate(params: SimulateRequest): Promise + + getTxsByEvent(params: TxsByEventRequest): Promise + + broadcastTx(params: BroadcastTxRequest): Promise + + getTxByHash(hash: string): Promise +} diff --git a/src/e2e/rpc/other/tatum.rpc.cosmos.rosetta.spec.ts b/src/e2e/rpc/other/tatum.rpc.cosmos.rosetta.spec.ts index d6e39e55e..67396c67b 100644 --- a/src/e2e/rpc/other/tatum.rpc.cosmos.rosetta.spec.ts +++ b/src/e2e/rpc/other/tatum.rpc.cosmos.rosetta.spec.ts @@ -37,5 +37,22 @@ describe.skip.each(networks)('Cosmos Rosetta', ({ network, blockchain }) => { }) expect(response).toBeDefined() }) + + it.skip('should get all accounts', async () => { + const response = await tatum.rpc.getAccounts() + expect(response).toBeDefined() + }) + + it('should get all params', async () => { + const response = await tatum.rpc.getAllParams() + expect(response).toBeDefined() + }) + + it('should get all community pool', async () => { + const response = await tatum.rpc.getCommunityPool() + expect(response).toBeDefined() + }) }) }) + + diff --git a/src/e2e/rpc/other/tatum.rpc.kadena.spec.ts b/src/e2e/rpc/other/tatum.rpc.kadena.spec.ts index 9301be48f..b1aaec436 100644 --- a/src/e2e/rpc/other/tatum.rpc.kadena.spec.ts +++ b/src/e2e/rpc/other/tatum.rpc.kadena.spec.ts @@ -30,7 +30,7 @@ const networks = [ }, ] -describe('Kadena', () => { +describe.skip('Kadena', () => { networks.forEach(({ isTestnet, network, blockHash, lower, upper }) => { describe(`${isTestnet ? 'Testnet' : 'Mainnet'}`, () => { it('getInfo', async () => { diff --git a/src/service/rpc/other/AbstractCardanoRpc.ts b/src/service/rpc/other/AbstractCardanoRpc.ts index 0fa4cec86..8a59bb28c 100644 --- a/src/service/rpc/other/AbstractCardanoRpc.ts +++ b/src/service/rpc/other/AbstractCardanoRpc.ts @@ -45,7 +45,7 @@ import { Utils } from '../../../util' export abstract class AbstractCardanoRpc implements CardanoRpcSuite { protected abstract post(post: PostI): Promise - private sendPost({ path, body }: { path: string; body?: any }): Promise { + protected sendPost({ path, body }: { path: string; body?: any }): Promise { const post: PostI = { path, } diff --git a/src/service/rpc/other/AbstractCosmosRpc.ts b/src/service/rpc/other/AbstractCosmosRpc.ts new file mode 100644 index 000000000..f5f664d3c --- /dev/null +++ b/src/service/rpc/other/AbstractCosmosRpc.ts @@ -0,0 +1,541 @@ +import { AbstractCardanoRpc } from './AbstractCardanoRpc' +import { QueryParams } from '../../../dto' +import { Utils } from '../../../util' +import { PostI } from '../../../dto/PostI' +import { + BroadcastTxRequest, + BroadcastTxResponse, + CosmosRpcSuite, + GetAccountDetailsRequest, + GetAccountDetailsResponse, + GetAccountsResponse, + GetAllBalancesRequest, + GetAllBalancesResponse, + GetAllEvidenceResponse, + GetAllowanceRequest, + GetAllowanceResponse, + GetAllParamsResponse, + GetAllProposalsRequest, + GetAllProposalsResponse, + GetAnnualProvisionsResponse, + GetAppliedPlanRequest, + GetAppliedPlanResponse, + GetBankParamsResponse, + GetBlockByHeightRequest, + GetBlockByHeightResponse, + GetCommunityPoolResponse, + GetCurrentPlanResponse, + GetDelegationRewardsRequest, + GetDelegationRewardsResponse, + GetDelegationsRequest, + GetDelegationsResponse, + GetDelegationTotalRewardsRequest, + GetDelegationTotalRewardsResponse, + GetDelegatorValidatorsRequest, + GetDelegatorValidatorsResponse, + GetDelegatorWithdrawAddressRequest, + GetDelegatorWithdrawAddressResponse, + GetDenomMetadataRequest, + GetDenomMetadataResponse, + GetDenomsMetadataResponse, + GetDepositsRequest, GetDepositsResponse, + GetDistributionParamsResponse, + GetGovernanceParamsRequest, + GetGovernanceParamsResponse, + GetGrantsForAddressRequest, + GetGrantsForAddressResponse, + GetGrantsRequest, + GetGrantsResponse, + GetHistoricalInfoRequest, + GetHistoricalInfoResponse, + GetInflationResponse, + GetLatestBlockResponse, + GetLatestValidatorSetResponse, + GetMintingParamsResponse, + GetModuleVersionsResponse, + GetNodeInfoResponse, + GetPoolInfoResponse, + GetProposalDetailsRequest, + GetProposalDetailsResponse, + GetRedelegationsRequest, + GetRedelegationsResponse, + GetSigningInfoByConsAddressRequest, + GetSigningInfoByConsAddressResponse, + GetSigningInfosResponse, + GetSlashingParamsResponse, + GetSpecificParamRequest, + GetSpecificParamResponse, + GetStakingParamsResponse, + GetSupplyOfCoinRequest, + GetSupplyOfCoinResponse, + GetSyncingResponse, GetTallyResultRequest, GetTallyResultResponse, + GetTotalSupplyResponse, + GetUnbondingDelegationRequest, + GetUnbondingDelegationResponse, + GetUnbondingDelegationsRequest, + GetUpgradedConsensusStateResponse, + GetValidatorCommissionRequest, + GetValidatorCommissionResponse, + GetValidatorInfoRequest, + GetValidatorInfoResponse, + GetValidatorOutstandingRewardsRequest, + GetValidatorOutstandingRewardsResponse, + GetValidatorSetByHeightRequest, + GetValidatorSetByHeightResponse, + GetValidatorSlashesRequest, + GetValidatorSlashesResponse, + GetValidatorsRequest, + GetValidatorsResponse, GetVoteRequest, GetVoteResponse, GetVotesRequest, GetVotesResponse, + PaginationRequest, + SimulateRequest, + SimulateResponse, + TxResponse, + TxsByEventRequest, + TxsByEventResponse, + UnbondingDelegationResponse, +} from '../../../dto/rpc/CosmosRpcSuite' + + +export abstract class AbstractCosmosRpc extends AbstractCardanoRpc implements CosmosRpcSuite { + protected abstract get(post: PostI): Promise + private async sendGet({ + path, + queryParams, + }: { + path: string + queryParams?: QueryParams + }): Promise { + return this.get({ + path: Utils.addQueryParams({ + basePath: path, + queryParams: queryParams, + }) + }) + } + + getAccounts(params: PaginationRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/auth/v1beta1/accounts', + queryParams: params as QueryParams + }) + } + + getAccountDetails(params: GetAccountDetailsRequest): Promise { + const { address } = params; + return this.sendGet({ + path: `/api/cosmos/auth/v1beta1/accounts/${address}`, + }); + } + + getAllParams(): Promise { + return this.sendGet({ + path: '/api/cosmos/auth/v1beta1/params', + }); + } + + getAllBalances(params: GetAllBalancesRequest): Promise { + const { address, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/bank/v1beta1/balances/${address}`, + queryParams: paginationParams + }); + } + + getDenomsMetadata(params: PaginationRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/bank/v1beta1/denoms_metadata', + queryParams: params as QueryParams + }); + } + + getDenomMetadata(params: GetDenomMetadataRequest): Promise { + const { denom } = params; + return this.sendGet({ + path: `/api/cosmos/bank/v1beta1/denoms_metadata/${denom}`, + }); + } + + getBankParams(): Promise { + return this.sendGet({ + path: '/api/cosmos/bank/v1beta1/params', + }); + } + + getTotalSupply(params: PaginationRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/bank/v1beta1/supply', + queryParams: params as unknown as QueryParams + }); + } + + getSupplyOfCoin(params: GetSupplyOfCoinRequest): Promise { + const { denom } = params; + return this.sendGet({ + path: `/api/cosmos/bank/v1beta1/supply/${denom}`, + }); + } + + getLatestBlock(): Promise { + return this.sendGet({ + path: '/api/cosmos/base/tendermint/v1beta1/blocks/latest', + }); + } + + getBlockByHeight(params: GetBlockByHeightRequest): Promise { + const { height } = params; + return this.sendGet({ + path: `/api/cosmos/base/tendermint/v1beta1/blocks/${height}`, + }); + } + + getNodeInfo(): Promise { + return this.sendGet({ + path: '/api/cosmos/base/tendermint/v1beta1/node_info', + }); + } + + getSyncing(): Promise { + return this.sendGet({ + path: '/api/cosmos/base/tendermint/v1beta1/syncing', + }); + } + + getLatestValidatorSet(params: PaginationRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/base/tendermint/v1beta1/validatorsets/latest', + queryParams: params as unknown as QueryParams + }); + } + + getValidatorSetByHeight(params: GetValidatorSetByHeightRequest): Promise { + const { height, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/base/tendermint/v1beta1/validatorsets/${height}`, + queryParams: paginationParams + }); + } + + getCommunityPool(): Promise { + return this.sendGet({ + path: '/api/cosmos/distribution/v1beta1/community_pool', + }); + } + + getDelegateTotalRewards(params: GetDelegationTotalRewardsRequest): Promise { + const { delegator_address } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/delegators/${delegator_address}/rewards`, + }); + } + + getDelegateRewards(params: GetDelegationRewardsRequest): Promise { + const { delegator_address, validator_address } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/delegators/${delegator_address}/rewards/${validator_address}`, + }); + } + + getDelegatorValidators(params: GetDelegatorValidatorsRequest): Promise { + const { delegator_address } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/delegators/${delegator_address}/validators`, + }); + } + + getDelegatorWithdrawAddress(params: GetDelegatorWithdrawAddressRequest): Promise { + const { delegator_address } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/delegators/${delegator_address}/withdraw_address`, + }); + } + + getDistributionParams(): Promise { + return this.sendGet({ + path: '/api/cosmos/distribution/v1beta1/params', + }); + } + + getValidatorCommission(params: GetValidatorCommissionRequest): Promise { + const { validator_address } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/validators/${validator_address}/commission`, + }); + } + + getValidatorOutstandingRewards(params: GetValidatorOutstandingRewardsRequest): Promise { + const { validator_address } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/validators/${validator_address}/outstanding_rewards`, + }); + } + + getValidatorSlashes(params: GetValidatorSlashesRequest): Promise { + const { validator_address, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/distribution/v1beta1/validators/${validator_address}/slashes`, + queryParams: paginationParams + }); + } + + getAllEvidence(params: PaginationRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/evidence/v1beta1/evidence', + queryParams: params as unknown as QueryParams + }); + } + + getGovernanceParams(params: GetGovernanceParamsRequest): Promise { + const { params_type } = params; + return this.sendGet({ + path: `/api/cosmos/gov/v1beta1/params/${params_type}`, + }); + } + + getAllProposals(params: GetAllProposalsRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/gov/v1beta1/proposals', + queryParams: params as unknown as QueryParams + }); + } + + getProposalDetails(params: GetProposalDetailsRequest): Promise { + const { proposal_id } = params; + return this.sendGet({ + path: `/api/cosmos/gov/v1beta1/proposals/${proposal_id}`, + }); + } + + getDeposits(params: GetDepositsRequest): Promise { + const { proposal_id } = params; + return this.sendGet({ + path: `/api/cosmos/gov/v1beta1/proposals/${proposal_id}/deposits`, + }); + } + + getTallyResult(params: GetTallyResultRequest): Promise { + const { proposal_id } = params; + return this.sendGet({ + path: `/api/cosmos/gov/v1beta1/proposals/${proposal_id}/tally`, + }); + } + + getVotes(params: GetVotesRequest): Promise { + const { proposal_id, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/gov/v1beta1/proposals/${proposal_id}/votes`, + queryParams: paginationParams as QueryParams + }); + } + + getVote(params: GetVoteRequest): Promise { + const { proposal_id, voter } = params; + return this.sendGet({ + path: `/api/cosmos/gov/v1beta1/proposals/${proposal_id}/votes/${voter}`, + }); + } + + getAnnualProvisions(): Promise { + return this.sendGet({ + path: '/api/cosmos/mint/v1beta1/annual_provisions', + }); + } + + getInflation(): Promise { + return this.sendGet({ + path: '/api/cosmos/mint/v1beta1/inflation', + }); + } + + getMintingParams(): Promise { + return this.sendGet({ + path: '/api/cosmos/mint/v1beta1/params', + }); + } + + getSpecificParam(params: GetSpecificParamRequest): Promise { + const { subspace, key } = params; + return this.sendGet({ + path: '/api/cosmos/params/v1beta1/params', + queryParams: { subspace, key } + }); + } + + getSlashingParams(): Promise { + return this.sendGet({ + path: '/api/cosmos/slashing/v1beta1/params', + }); + } + + getSigningInfos(): Promise { + return this.sendGet({ + path: '/api/cosmos/slashing/v1beta1/signing_infos', + }); + } + + getSingingInfoByConsAddress(params: GetSigningInfoByConsAddressRequest): Promise { + const { cons_address } = params; + return this.sendGet({ + path: `/api/cosmos/slashing/v1beta1/signing_infos/${cons_address}`, + }); + } + + getDelegations(params: GetDelegationsRequest): Promise { + const { delegator_address, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/delegations/${delegator_address}`, + queryParams: paginationParams + }); + } + + getRedelegations(params: GetRedelegationsRequest): Promise { + const { delegator_addr, ...queryParams } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/delegators/${delegator_addr}/redelegations`, + queryParams: queryParams + }); + } + + getUnbondingDelegations(params: GetUnbondingDelegationsRequest): Promise { + const { delegator_addr, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/delegators/${delegator_addr}/unbonding_delegations`, + queryParams: paginationParams + }); + } + + getValidators(params: GetValidatorsRequest): Promise { + const { delegator_addr, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/delegators/${delegator_addr}/validators`, + queryParams: paginationParams + }); + } + + getValidatorInfo(params: GetValidatorInfoRequest): Promise { + const { delegator_addr, validator_addr } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/delegators/${delegator_addr}/validators/${validator_addr}`, + }); + } + + getHistoricalInfo(params: GetHistoricalInfoRequest): Promise { + const { height } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/historical_info/${height}`, + }); + } + + getStakingParams(): Promise { + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/params`, + }); + } + + getPoolInfo(): Promise { + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/pool`, + }); + } + + getValidatorsForGivenStatus(params: GetValidatorsRequest): Promise { + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/validators`, + queryParams: params as unknown as QueryParams + }); + } + + getValidatorInfoForAddress(params: GetValidatorInfoRequest): Promise { + const { validator_addr } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/validators/${validator_addr}`, + }); + } + + getDelegationsForValidator(params: GetDelegationsRequest): Promise { + const { validator_addr, ...paginationParams } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/validators/${validator_addr}/delegations`, + queryParams: paginationParams + }); + } + + getUnbondingDelegation(params: GetUnbondingDelegationRequest): Promise { + const { validator_addr, delegator_addr } = params; + return this.sendGet({ + path: `/api/cosmos/staking/v1beta1/validators/${validator_addr}/delegations/${delegator_addr}/unbonding_delegation`, + }); + } + + getAppliedPlan(params: GetAppliedPlanRequest): Promise { + const { name } = params; + return this.sendGet({ + path: `/api/cosmos/upgrade/v1beta1/applied_plan/${name}`, + }); + } + + getCurrentPlan(): Promise { + return this.sendGet({ + path: `/api/cosmos/upgrade/v1beta1/current_plan`, + }); + } + + getModuleVersions(): Promise { + return this.sendGet({ + path: `/api/cosmos/upgrade/v1beta1/module_versions`, + }); + } + + getUpgradedConsensusState(lastHeight: number): Promise { + return this.sendGet({ + path: `/api/cosmos/upgrade/v1beta1/upgraded_consensus_state/${lastHeight}`, + }); + } + + getGrants(params: GetGrantsRequest): Promise { + return this.sendGet({ + path: `/api/cosmos/authz/v1beta1/grants`, + queryParams: params as unknown as QueryParams, + }); + } + + getAllowance(params: GetAllowanceRequest): Promise { + const { granter, grantee } = params; + return this.sendGet({ + path: `/api/cosmos/feegrant/v1beta1/allowance/${granter}/${grantee}`, + }); + } + + getAllowanceForAddress(params: GetGrantsForAddressRequest): Promise { + const { grantee } = params; + return this.sendGet({ + path: `/api/cosmos/feegrant/v1beta1/allowances/${grantee}`, + }); + } + + simulate(params: SimulateRequest): Promise { + return this.sendPost({ + path: '/api/cosmos/tx/v1beta1/simulates', + body: params, + }) + } + + getTxsByEvent(params: TxsByEventRequest): Promise { + return this.sendGet({ + path: '/api/cosmos/tx/v1beta1/txs', + queryParams: params as unknown as QueryParams, + }) + } + + broadcastTx(params: BroadcastTxRequest): Promise { + return this.sendPost({ + path: '/api/cosmos/tx/v1beta1/txs', + body: params, + }) + } + + getTxByHash(hash: string): Promise { + return this.sendGet({ + path: `/api/cosmos/tx/v1beta1/txs/${hash}`, + }) + } +} diff --git a/src/service/rpc/other/CosmosLoadBalancerRpc.ts b/src/service/rpc/other/CosmosLoadBalancerRpc.ts new file mode 100644 index 000000000..21dd1927c --- /dev/null +++ b/src/service/rpc/other/CosmosLoadBalancerRpc.ts @@ -0,0 +1,39 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Container, Service } from 'typedi' +import { PostI } from '../../../dto/PostI' +// Need to import like this to keep browser working +import { LoadBalancer } from '../generic/LoadBalancer' +import { AbstractCosmosRpc } from './AbstractCosmosRpc' +import { CosmosRpcSuite } from '../../../dto/rpc/CosmosRpcSuite' +import { GetI } from '../../../dto/GetI' + +@Service({ + factory: (data: { id: string }) => { + return new CosmosLoadBalancerRpc(data.id) + }, + transient: true, +}) +export class CosmosLoadBalancerRpc extends AbstractCosmosRpc implements CosmosRpcSuite { + protected readonly loadBalancer: LoadBalancer + + constructor(id: string) { + super() + this.loadBalancer = Container.of(id).get(LoadBalancer) + } + + public destroy() { + this.loadBalancer.destroy() + } + + getRpcNodeUrl(): string { + return this.loadBalancer.getActiveNormalUrlWithFallback().url + } + + protected post(post: PostI): Promise { + return this.loadBalancer.post(post) + } + + protected get(get: GetI): Promise { + return this.loadBalancer.get(get) + } +} diff --git a/src/service/tatum/tatum.other.ts b/src/service/tatum/tatum.other.ts index a8fa7f031..d39aa1786 100644 --- a/src/service/tatum/tatum.other.ts +++ b/src/service/tatum/tatum.other.ts @@ -17,6 +17,7 @@ import { Notification } from '../notification' import { Rates } from '../rate' import { Token } from '../token' import { TatumSdkChain } from './tatum' +import { CosmosRpcSuite } from '../../dto/rpc/CosmosRpcSuite' export abstract class BaseOther extends TatumSdkChain { ipfs: Ipfs @@ -168,11 +169,11 @@ export class CardanoRosetta extends BaseOther { } export class CosmosRosetta extends BaseOther { - rpc: CardanoRpcSuite + rpc: CosmosRpcSuite constructor(id: string) { super(id) - this.rpc = Utils.getRpc(id, Container.of(id).get(CONFIG)) + this.rpc = Utils.getRpc(id, Container.of(id).get(CONFIG)) } } diff --git a/src/util/util.shared.ts b/src/util/util.shared.ts index c5dd33fe3..04983b920 100644 --- a/src/util/util.shared.ts +++ b/src/util/util.shared.ts @@ -7,7 +7,7 @@ import { isAlgorandAlgodNetwork, isAlgorandIndexerNetwork, isBnbLoadBalancerNetwork, - isCardanoNetwork, + isCardanoNetwork, isCosmosNetwork, isDogecoinLoadBalancedNetwork, isEosLoadBalancerNetwork, isEosNetwork, @@ -54,7 +54,7 @@ import { Bnb, CardanoRosetta, Celo, - Chiliz, + Chiliz, CosmosRosetta, Cronos, Dogecoin, Eos, @@ -117,10 +117,15 @@ import { UtxoRpcEstimateFee } from '../service/rpc/utxo/UtxoRpcEstimateFee' import { Constant } from './constant' import { CONFIG, LOGGER } from './di.tokens' import { IotaRpc } from '../service/rpc/other/IotaRpc' +import { CosmosLoadBalancerRpc } from '../service/rpc/other/CosmosLoadBalancerRpc' export const Utils = { getRpc: (id: string, config: TatumConfig): T => { const { network } = config + if (isCosmosNetwork(network)) { + return Container.of(id).get(CosmosLoadBalancerRpc) as T + } + if (isIotaLoadBalancerNetwork(network)) { return Container.of(id).get(IotaLoadBalancerRpc) as T } @@ -833,7 +838,7 @@ export const Utils = { case Network.CARDANO_ROSETTA_PREPROD: return new CardanoRosetta(id) as T case Network.COSMONS_ROSETTA: - return new CardanoRosetta(id) as T + return new CosmosRosetta(id) as T case Network.STELLAR: case Network.STELLAR_TESTNET: return new Stellar(id) as T