@@ -230,8 +230,6 @@ export interface IProtocolAdapter {
230230 getVersion ( ) : ProtocolVersion ;
231231 getSupportedMethods ( ) : Set < RpcMethod > ;
232232 getCapabilities ( ) : ProtocolCapabilities ;
233- encodeParams ( method : RpcMethod , params : any ) : any ;
234- decodeResponse ( method : RpcMethod , response : any ) : any ;
235233 encodeBytes ( data : string ) : Uint8Array ;
236234 decodeBytes ( data : Uint8Array ) : string ;
237235}
@@ -357,179 +355,6 @@ export abstract class BaseAdapter implements RequestEncoder, ResponseDecoder, IC
357355 return this . version ;
358356 }
359357
360- encodeParams ( method : RpcMethod , params : any ) : any {
361- // Convert camelCase to snake_case for Tendermint/CometBFT
362- if ( ! params ) return { } ;
363-
364- // Special handling for ABCI query using codec
365- if ( method === RpcMethod . ABCI_QUERY ) {
366- const encoded = this . encodeAbciQuery ( params as AbciQueryParams ) ;
367- // Convert to snake_case for RPC
368- return {
369- path : encoded . path ,
370- data : encoded . data ,
371- height : encoded . height ,
372- prove : encoded . prove
373- } ;
374- }
375-
376- // Special handling for commit using codec
377- if ( method === RpcMethod . COMMIT ) {
378- const encoded = this . encodeCommit ( params as CommitParams ) ;
379- return encoded ;
380- }
381-
382- // Special handling for block_results using codec
383- if ( method === RpcMethod . BLOCK_RESULTS ) {
384- const encoded = this . encodeBlockResults ( params as BlockResultsParams ) ;
385- return encoded ;
386- }
387-
388-
389-
390- // Convert height to string for block-related methods
391- if ( ( method === RpcMethod . BLOCK ) &&
392- params . height !== undefined && typeof params . height === "number" ) {
393- params = { ...params , height : params . height . toString ( ) } ;
394- }
395-
396- // Convert height to string for validator and consensus methods
397- if ( ( method === RpcMethod . VALIDATORS || method === RpcMethod . CONSENSUS_PARAMS ) &&
398- params . height !== undefined && typeof params . height === "number" ) {
399- params = { ...params , height : params . height . toString ( ) } ;
400- }
401-
402-
403-
404- // Special handling for genesis (no parameters)
405- if ( method === RpcMethod . GENESIS ) {
406- return undefined ;
407- }
408-
409-
410-
411-
412-
413- // Special handling for unconfirmed_txs using codec
414- if ( method === RpcMethod . UNCONFIRMED_TXS ) {
415- const encoded = this . encodeUnconfirmedTxs ( params as UnconfirmedTxsParams ) ;
416- return encoded ;
417- }
418-
419- // Special handling for validators using codec
420- if ( method === RpcMethod . VALIDATORS ) {
421- const encoded = this . encodeValidators ( params as ValidatorsParams ) ;
422- return encoded ;
423- }
424-
425- // Special handling for tx using codec
426- if ( method === RpcMethod . TX ) {
427- const encoded = this . encodeTx ( params as TxParams ) ;
428- return encoded ;
429- }
430-
431- // Special handling for tx_search using codec
432- if ( method === RpcMethod . TX_SEARCH ) {
433- const encoded = this . encodeTxSearch ( params as TxSearchParams ) ;
434- return encoded ;
435- }
436-
437-
438-
439- // Special handling for broadcast_tx_sync using codec
440- if ( method === RpcMethod . BROADCAST_TX_SYNC ) {
441- const encoded = this . encodeBroadcastTxSync ( params as BroadcastTxParams ) ;
442- return encoded ;
443- }
444-
445- // Special handling for broadcast_tx_async using codec
446- if ( method === RpcMethod . BROADCAST_TX_ASYNC ) {
447- const encoded = this . encodeBroadcastTxAsync ( params as BroadcastTxParams ) ;
448- return encoded ;
449- }
450-
451- // Special handling for broadcast_tx_commit using codec
452- if ( method === RpcMethod . BROADCAST_TX_COMMIT ) {
453- const encoded = this . encodeBroadcastTxCommit ( params as BroadcastTxParams ) ;
454- return encoded ;
455- }
456-
457- // Special handling for check_tx using codec
458- if ( method === RpcMethod . CHECK_TX ) {
459- const encoded = this . encodeCheckTx ( params as CheckTxParams ) ;
460- return encoded ;
461- }
462-
463- const encoded : any = { } ;
464- for ( const [ key , value ] of Object . entries ( params ) ) {
465- const snakeKey = this . camelToSnake ( key ) ;
466-
467- // Handle hash parameters with 0x prefix
468- if ( key === 'hash' && typeof value === 'string' && value . startsWith ( '0x' ) ) {
469- // Convert hex to base64 for RPC
470- const hexString = value . slice ( 2 ) ; // Remove 0x prefix
471- const bytes = Buffer . from ( hexString , 'hex' ) ;
472- encoded [ snakeKey ] = bytes . toString ( 'base64' ) ;
473- }
474- // Handle Uint8Array data (especially for ABCI queries and broadcast)
475- else if ( value instanceof Uint8Array ) {
476- // For tx field in broadcast methods, encode as base64
477- if ( key === 'tx' ) {
478- encoded [ snakeKey ] = Buffer . from ( value ) . toString ( 'base64' ) ;
479- } else {
480- // Convert Uint8Array to hex string for RPC
481- encoded [ snakeKey ] = this . decodeBytes ( value ) ;
482- }
483- }
484- else {
485- encoded [ snakeKey ] = value ;
486- }
487- }
488- return encoded ;
489- }
490-
491- decodeResponse ( method : RpcMethod , response : any ) : any {
492- // Use the version-specific decoder
493- switch ( method ) {
494- case RpcMethod . ABCI_INFO :
495- return this . decodeAbciInfo ( response ) ;
496- case RpcMethod . ABCI_QUERY :
497- return this . decodeAbciQuery ( response ) ;
498- case RpcMethod . BLOCK_RESULTS :
499- return this . decodeBlockResults ( response ) ;
500-
501- case RpcMethod . CONSENSUS_PARAMS :
502- return this . decodeConsensusParams ( response ) ;
503-
504-
505-
506- case RpcMethod . STATUS :
507- return this . decodeStatus ( response ) ;
508- case RpcMethod . NET_INFO :
509- return this . decodeNetInfo ( response ) ;
510- case RpcMethod . GENESIS :
511- return this . decodeGenesis ( response ) ;
512- case RpcMethod . GENESIS_CHUNKED :
513- return this . decodeGenesisChunked ( response ) ;
514- case RpcMethod . HEALTH :
515- return this . decodeHealth ( response ) ;
516-
517- case RpcMethod . NUM_UNCONFIRMED_TXS :
518- return this . decodeNumUnconfirmedTxs ( response ) ;
519- case RpcMethod . COMMIT :
520- return this . decodeCommit ( response ) ;
521- case RpcMethod . BROADCAST_TX_SYNC :
522- return this . decodeBroadcastTxSync ( response ) ;
523- case RpcMethod . BROADCAST_TX_ASYNC :
524- return this . decodeBroadcastTxAsync ( response ) ;
525- case RpcMethod . BROADCAST_TX_COMMIT :
526- return this . decodeBroadcastTxCommit ( response ) ;
527- default :
528- // For unsupported methods, return raw response
529- return response ;
530- }
531- }
532-
533358 encodeBytes ( data : string ) : Uint8Array {
534359 // Handle hex strings and base64
535360 if ( data . startsWith ( '0x' ) ) {
0 commit comments