/* this class is for shared methods between avm/pvm api's */ import { SignedTx } from '../../serializable/avax'; import { hexToBuffer } from '../../utils'; import type { GetAddressTxsParams, GetAddressTxsResponse } from '../avm/models'; import type { GetBalanceParams, GetBalanceResponse } from '../pvm'; import type { GetTxServerResponse } from '../pvm/privateModels'; import type { GetAssetDescriptionResponse, GetTxParams, GetTxStatusParams, GetTxStatusResponse, } from './apiModels'; import { ChainApi } from './chainAPI'; export class AvaxApi extends ChainApi { getAssetDescription(assetID: string): Promise { return this.callRpc('getAssetDescription', { assetID, }); } getTx = async (getTxParams: GetTxParams) => { const resp = await this.callRpc('getTx', { ...getTxParams, encoding: 'hex', }); return this.manager.unpack(hexToBuffer(resp.tx), SignedTx); }; getTxJson = (getTxParams: GetTxParams) => { return this.callRpc('getTx', { ...getTxParams, encoding: 'json', }); }; getTxStatus(getTxStatus: GetTxStatusParams): Promise { return this.callRpc('getTxStatus', { includeReason: true, ...getTxStatus, }); } getBalance(getBalanceParams: GetBalanceParams): Promise { return this.callRpc('getBalance', getBalanceParams); } getAddressTxs( GetAddressTxsParams: GetAddressTxsParams, ): Promise { return this.callRpc( 'GetAddressTxs', GetAddressTxsParams, ); } }