Skip to content

Commit

Permalink
ALL-2694 Add Eos
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Sep 26, 2023
1 parent 8356c5c commit 39d67e9
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/dto/rpc/EosRpcSuite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { BigNumber } from 'bignumber.js'

Check warning on line 2 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / test

'BigNumber' is defined but never used

Check failure on line 2 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / build (18)

'BigNumber' is declared but its value is never read.
import { AbstractRpcInterface } from './AbstractJsonRpcInterface'

interface GetProducersI {
json?: boolean
lowerBound?: string
limit?: number
}

// Definition for Action
interface Action {
account: 'NamePrivileged' | 'NameBasic' | 'NameBid' | 'NameCatchAll'
name: 'NamePrivileged' | 'NameBasic' | 'NameBid' | 'NameCatchAll'
authorization: Authority[]
data: object
hexData: string
}

// Definition for Authority
interface Authority {

Check failure on line 21 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / test

An empty interface is equivalent to `{}`
// Fill in the fields for Authority based on your needs
}

// Definition for Extension
type Extension = Array<number | string>

// Main Transaction interface
interface TransactionI {
expiration: string // DateTime in string format
refBlockNum: number
refBlockPrefix: number
maxNetUsageWords: string | number // WholeNumber
maxCpuUsageMs: string | number // WholeNumber
delaySec: number
contextFreeActions: Action[]
actions: Action[]
transactionExtensions: Extension[]
}

interface GetRequiredKeysI {

Check warning on line 41 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / test

'GetRequiredKeysI' is defined but never used

Check failure on line 41 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / build (18)

'GetRequiredKeysI' is declared but never used.
transaction: TransactionI
availableKeys: string[]
}

export interface EosRpcSuite extends AbstractRpcInterface {
/**
* Validates a Tron address.
*
* @param {string} address - The Tron address to be validated.
* @param {VisibleOption} [options] - The options for validation.
* @returns {Promise<any>} - Returns a Promise that resolves with validation result.
* https://docs.tatum.com/docs/rpc-api-reference/tron-rpc-documentation/api-calls-for-address-utility-methods/validateaddress
*/
validateAddress(address: string, options?: VisibleOption): Promise<any>

Check failure on line 55 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / build (18)

Cannot find name 'VisibleOption'.

Check failure on line 55 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / build (18)

Parameter 'options' of method from exported interface has or is using private name 'VisibleOption'.

/**
* Broadcasts a raw Tron transaction.
*
* @param {TronTxRawBody} rawBody - The raw body of the transaction to be broadcasted.
* @returns {Promise<any>} - Returns a Promise that resolves with the broadcast result.
* https://docs.tatum.com/docs/rpc-api-reference/tron-rpc-documentation/api-calls-for-transaction-methods/broadcasttransaction
*/
broadcastTransaction(rawBody: TronTxRawBody): Promise<any>

Check failure on line 64 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / build (18)

Cannot find name 'TronTxRawBody'.

Check failure on line 64 in src/dto/rpc/EosRpcSuite.ts

View workflow job for this annotation

GitHub Actions / build (18)

Parameter 'rawBody' of method from exported interface has or is using private name 'TronTxRawBody'.

getProducers(body: GetProducersI): Promise<any>
}
66 changes: 66 additions & 0 deletions src/service/rpc/AbstractEosRpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Service } from 'typedi'
import {
AccountPermissionUpdateOptions,
JsonRpcCall,
JsonRpcResponse,
TronPermission,
TronRpcSuite,
} from '../../dto'
import { Utils } from '../../util'
import { AbstractEvmRpc } from './evm/AbstractEvmRpc'

export interface PostI {
path: string
body?: any
}

@Service()
export abstract class AbstractEosRpc extends AbstractEvmRpc implements TronRpcSuite {

Check failure on line 19 in src/service/rpc/AbstractEosRpc.ts

View workflow job for this annotation

GitHub Actions / build (18)

Class 'AbstractEosRpc' incorrectly implements interface 'TronRpcSuite'.
protected abstract post<T>(post: PostI): Promise<T>
abstract destroy(): void
abstract getRpcNodeUrl(): string

abstract rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[] | JsonRpcResponse<any>>

abstract rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>>

private sendPost<T>({
path,
body,
notConvertCamelToSnake,
}: {
path: string
body?: any
notConvertCamelToSnake?: boolean
}): Promise<T> {
const post: PostI = {
path,
}

if (body) {
post.body = notConvertCamelToSnake ? body : Utils.convertObjCamelToSnake(body)
}

return this.post(post)
}

accountPermissionUpdate(
ownerAddress: string,
actives: TronPermission[],
owner: TronPermission,
options?: AccountPermissionUpdateOptions,
): Promise<any> {
return this.sendPost({
path: '/wallet/accountpermissionupdate',
body: { ownerAddress, actives, owner, ...options },
})
}

broadcastHex(transaction: string): Promise<any> {
return this.sendPost({
path: '/wallet/broadcasthex',
body: { transaction },
})
}
}

0 comments on commit 39d67e9

Please sign in to comment.