@@ -61,7 +61,8 @@ export class EthImpl implements Eth {
6161 static feeHistoryEmptyResponse = { baseFeePerGas : [ ] , gasUsedRatio : [ ] , reward : [ ] , oldestBlock : EthImpl . zeroHex } ;
6262 static redirectBytecodePrefix = '6080604052348015600f57600080fd5b506000610167905077618dc65e' ;
6363 static redirectBytecodePostfix = '600052366000602037600080366018016008845af43d806000803e8160008114605857816000f35b816000fdfea2646970667358221220d8378feed472ba49a0005514ef7087017f707b45fb9bf56bb81bb93ff19a238b64736f6c634300080b0033' ;
64-
64+ static iHTSAddress = '0x0000000000000000000000000000000000000167' ;
65+ static invalidEVMInstruction = '0xfe' ;
6566
6667 // endpoint metric callerNames
6768 static ethCall = 'eth_call' ;
@@ -573,7 +574,14 @@ export class EthImpl implements Eth {
573574 */
574575 async getCode ( address : string , blockNumber : string | null , requestId ?: string ) {
575576 const requestIdPrefix = formatRequestIdMessage ( requestId ) ;
576- // FIXME: This has to be reimplemented to get the data from the mirror node.
577+
578+ // check for static precompile cases first before consulting nodes
579+ // this also account for environments where system entitites were not yet exposed to the mirror node
580+ if ( address === EthImpl . iHTSAddress ) {
581+ this . logger . trace ( `${ requestIdPrefix } HTS precompile case, return ${ EthImpl . invalidEVMInstruction } for byte code` ) ;
582+ return EthImpl . invalidEVMInstruction ;
583+ }
584+
577585 this . logger . trace ( `${ requestIdPrefix } getCode(address=${ address } , blockNumber=${ blockNumber } )` ) ;
578586
579587 const cachedLabel = `getCode.${ address } .${ blockNumber } ` ;
@@ -584,17 +592,20 @@ export class EthImpl implements Eth {
584592
585593 try {
586594 const result = await this . mirrorNodeClient . resolveEntityType ( address , requestId ) ;
587-
588- if ( result && result ?. type === constants . TYPE_TOKEN ) {
595+ if ( result ) {
596+ if ( result ?. type === constants . TYPE_TOKEN ) {
597+ this . logger . trace ( `${ requestIdPrefix } Token redirect case, return redirectBytecode` ) ;
589598 return EthImpl . redirectBytecodeAddressReplace ( address ) ;
599+ }
600+ else if ( result ?. type === constants . TYPE_CONTRACT ) {
601+ if ( result ?. entity . runtime_bytecode !== EthImpl . emptyHex ) {
602+ return result ?. entity . runtime_bytecode ;
603+ }
604+ }
590605 }
591- else if ( result && result ?. type === constants . TYPE_CONTRACT && result ?. entity . runtime_bytecode !== EthImpl . emptyHex ) {
592- return result ?. entity . runtime_bytecode ;
593- }
594- else {
595- const bytecode = await this . sdkClient . getContractByteCode ( 0 , 0 , address , EthImpl . ethGetCode , requestId ) ;
596- return EthImpl . prepend0x ( Buffer . from ( bytecode ) . toString ( 'hex' ) ) ;
597- }
606+
607+ const bytecode = await this . sdkClient . getContractByteCode ( 0 , 0 , address , EthImpl . ethGetCode , requestId ) ;
608+ return EthImpl . prepend0x ( Buffer . from ( bytecode ) . toString ( 'hex' ) ) ;
598609 } catch ( e : any ) {
599610 if ( e instanceof SDKClientError ) {
600611 // handle INVALID_CONTRACT_ID
0 commit comments