-module(gleeth@rpc@types). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gleeth/rpc/types.gleam"). -export([method_to_string/1, error_to_string/1]). -export_type([json_rpc_request/0, json_rpc_response/0, json_rpc_error/0, eth_method/0, gleeth_error/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Core types for gleeth's JSON-RPC layer - request/response structures,\n" " Ethereum method definitions, and the unified application error type.\n" ). -type json_rpc_request() :: {json_rpc_request, binary(), binary(), list(gleam@json:json()), integer()}. -type json_rpc_response() :: {json_rpc_response, binary(), integer(), {ok, gleam@json:json()} | {error, json_rpc_error()}}. -type json_rpc_error() :: {json_rpc_error, integer(), binary(), gleam@json:json()}. -type eth_method() :: eth_block_number | eth_get_balance | eth_call | eth_get_transaction_by_hash | eth_get_transaction_receipt | eth_get_code | eth_estimate_gas | eth_get_storage_at | eth_get_logs | eth_get_block_by_number | eth_chain_id | eth_send_raw_transaction | eth_get_transaction_count | eth_gas_price | eth_max_priority_fee_per_gas | eth_fee_history. -type gleeth_error() :: {invalid_rpc_url, binary()} | {invalid_address, binary()} | {invalid_hash, binary()} | {rpc_error, binary()} | {network_error, binary()} | {parse_error, binary()} | {config_error, binary()} | {abi_err, gleeth@ethereum@abi@types:abi_error()} | {wallet_err, gleeth@crypto@wallet:wallet_error()} | {transaction_err, gleeth@crypto@transaction:transaction_error()}. -file("src/gleeth/rpc/types.gleam", 54). ?DOC(" Convert an EthMethod variant to its JSON-RPC method name string.\n"). -spec method_to_string(eth_method()) -> binary(). method_to_string(Method) -> case Method of eth_block_number -> <<"eth_blockNumber"/utf8>>; eth_get_balance -> <<"eth_getBalance"/utf8>>; eth_call -> <<"eth_call"/utf8>>; eth_get_transaction_by_hash -> <<"eth_getTransactionByHash"/utf8>>; eth_get_transaction_receipt -> <<"eth_getTransactionReceipt"/utf8>>; eth_get_code -> <<"eth_getCode"/utf8>>; eth_estimate_gas -> <<"eth_estimateGas"/utf8>>; eth_get_storage_at -> <<"eth_getStorageAt"/utf8>>; eth_get_logs -> <<"eth_getLogs"/utf8>>; eth_get_block_by_number -> <<"eth_getBlockByNumber"/utf8>>; eth_chain_id -> <<"eth_chainId"/utf8>>; eth_send_raw_transaction -> <<"eth_sendRawTransaction"/utf8>>; eth_get_transaction_count -> <<"eth_getTransactionCount"/utf8>>; eth_gas_price -> <<"eth_gasPrice"/utf8>>; eth_max_priority_fee_per_gas -> <<"eth_maxPriorityFeePerGas"/utf8>>; eth_fee_history -> <<"eth_feeHistory"/utf8>> end. -file("src/gleeth/rpc/types.gleam", 118). -spec abi_error_message(gleeth@ethereum@abi@types:abi_error()) -> binary(). abi_error_message(Err) -> case Err of {encode_error, Msg} -> Msg; {decode_error, Msg@1} -> Msg@1; {type_parse_error, Msg@2} -> Msg@2; {invalid_abi_json, Msg@3} -> Msg@3 end. -file("src/gleeth/rpc/types.gleam", 102). ?DOC(" Convert a `GleethError` to a human-readable message string.\n"). -spec error_to_string(gleeth_error()) -> binary(). error_to_string(Error) -> case Error of {invalid_rpc_url, Msg} -> <<"Invalid RPC URL: "/utf8, Msg/binary>>; {invalid_address, Msg@1} -> <<"Invalid address: "/utf8, Msg@1/binary>>; {invalid_hash, Msg@2} -> <<"Invalid hash: "/utf8, Msg@2/binary>>; {rpc_error, Msg@3} -> <<"RPC error: "/utf8, Msg@3/binary>>; {network_error, Msg@4} -> <<"Network error: "/utf8, Msg@4/binary>>; {parse_error, Msg@5} -> <<"Parse error: "/utf8, Msg@5/binary>>; {config_error, Msg@6} -> <<"Configuration error: "/utf8, Msg@6/binary>>; {abi_err, Err} -> <<"ABI error: "/utf8, (abi_error_message(Err))/binary>>; {wallet_err, Err@1} -> <<"Wallet error: "/utf8, (gleeth@crypto@wallet:error_to_string(Err@1))/binary>>; {transaction_err, Err@2} -> <<"Transaction error: "/utf8, (gleeth@crypto@transaction:error_to_string(Err@2))/binary>> end.