-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 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
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 GitHub Actions / test
|
||
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 { | ||
// 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 GitHub Actions / test
|
||
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 GitHub Actions / build (18)
|
||
|
||
/** | ||
* 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 GitHub Actions / build (18)
|
||
|
||
getProducers(body: GetProducersI): Promise<any> | ||
} |
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,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 { | ||
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 }, | ||
}) | ||
} | ||
} |