diff --git a/go.mod b/go.mod index 3a2695cb410099fa0a550eea796a72bc62750fcc..66405e839290cb4ebb15663c7dd39f1925ffc0e4 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( gfx.cafe/util/go/bufpool v0.0.0-20220917152604-80373e5a2c51 git.tuxpa.in/a/zlog v1.32.0 + github.com/alecthomas/kong v0.6.1 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/ethereum/go-ethereum v1.10.22 @@ -21,7 +22,6 @@ require ( require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect - github.com/alecthomas/kong v0.6.1 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect diff --git a/go.sum b/go.sum index 5359d0a43de72680f3371a9fb5b04faffd0fae56..523fc55d93f3d2202cb1563e2c02bc08bdfe006f 100644 --- a/go.sum +++ b/go.sum @@ -47,6 +47,7 @@ github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIO github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/alecthomas/kong v0.6.1 h1:1kNhcFepkR+HmasQpbiKDLylIL8yh5B5y1zPp5bJimA= github.com/alecthomas/kong v0.6.1/go.mod h1:JfHWDzLmbh/puW6I3V7uWenoh56YNVONW+w8eKeUr9I= +github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48= github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= diff --git a/openrpc/generate/generate.go b/openrpc/generate/generate.go index ddcfadbc3cfb09d51c4674aa7a6826caa42a469b..b494b1316b2819ace8fe84bb9ace1ef09fb9d1c9 100644 --- a/openrpc/generate/generate.go +++ b/openrpc/generate/generate.go @@ -184,9 +184,6 @@ type object struct { func funcMap(openrpc *types.OpenRPCSpec1) template.FuncMap { return template.FuncMap{ - "fixName": func(s string) string { - return "Type" + strings.ReplaceAll(s, " ", "") - }, "programName": getProgramName, "derefSchema": derefSchemaRecurse, "schemaHasRef": schemaHazRef, diff --git a/openrpc/out/server.go b/openrpc/out/server.go index 65e36d95e2b7c06e7b215bd900ce8b462b19a63b..fb2fe69082899ea25eef87b471d836d5fe6ed4d8 100644 --- a/openrpc/out/server.go +++ b/openrpc/out/server.go @@ -495,3 +495,25 @@ func WriteData(w http.ResponseWriter, id interface{}, result interface{}) { w.WriteHeader(http.StatusOK) w.Write(data) } +nil { + panic(err) + } + w.Header().Set("Content-Type", "application/json") + w.Write(data) +} + +func WriteData(w http.ResponseWriter, id interface{}, result interface{}) { + resp := &RPCResultResponse{ + JSONRPC: JSONRPC, + ID: id, + Result: StructToResult(result), + } + data, err := json.Marshal(resp) + if err != nil { + WriteError(w, id, ErrInternal.RPCError()) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write(data) +} diff --git a/openrpc/out/types.go b/openrpc/out/types.go new file mode 100644 index 0000000000000000000000000000000000000000..d81ae89dfdfeb46ad9c41c68f941a56d99ed4f77 --- /dev/null +++ b/openrpc/out/types.go @@ -0,0 +1,586 @@ +// Code generated by go-openrpc. DO NOT EDIT. +package out + +type GoOpenRPCService interface { + // Returns an RLP-encoded header. + DebugGetRawHeader(*DebugGetRawHeaderParams) (*DebugGetRawHeaderResult, error) + // Returns an RLP-encoded block. + DebugGetRawBlock(*DebugGetRawBlockParams) (*DebugGetRawBlockResult, error) + // Returns an array of EIP-2718 binary-encoded transactions. + DebugGetRawTransaction(*DebugGetRawTransactionParams) (*DebugGetRawTransactionResult, error) + // Returns an array of EIP-2718 binary-encoded receipts. + DebugGetRawReceipts(*DebugGetRawReceiptsParams) (*DebugGetRawReceiptsResult, error) + // Returns an array of recent bad blocks that the client has seen on the network. + DebugGetBadBlocks() (*DebugGetBadBlocksResult, error) + // Returns information about a block by hash. + EthGetBlockByHash(*EthGetBlockByHashParams) (*EthGetBlockByHashResult, error) + // Returns information about a block by number. + EthGetBlockByNumber(*EthGetBlockByNumberParams) (*EthGetBlockByNumberResult, error) + // Returns the number of transactions in a block from a block matching the given block hash. + EthGetBlockTransactionCountByHash(*EthGetBlockTransactionCountByHashParams) (*EthGetBlockTransactionCountByHashResult, error) + // Returns the number of transactions in a block matching the given block number. + EthGetBlockTransactionCountByNumber(*EthGetBlockTransactionCountByNumberParams) (*EthGetBlockTransactionCountByNumberResult, error) + // Returns the number of uncles in a block from a block matching the given block hash. + EthGetUncleCountByBlockHash(*EthGetUncleCountByBlockHashParams) (*EthGetUncleCountByBlockHashResult, error) + // Returns the number of transactions in a block matching the given block number. + EthGetUncleCountByBlockNumber(*EthGetUncleCountByBlockNumberParams) (*EthGetUncleCountByBlockNumberResult, error) + // Returns the chain ID of the current network. + EthChainId() (*EthChainIdResult, error) + // Returns an object with data about the sync status or false. + EthSyncing() (*EthSyncingResult, error) + // Returns the client coinbase address. + EthCoinbase() (*EthCoinbaseResult, error) + // Returns a list of addresses owned by client. + EthAccounts() (*EthAccountsResult, error) + // Returns the number of most recent block. + EthBlockNumber() (*EthBlockNumberResult, error) + // Executes a new message call immediately without creating a transaction on the block chain. + EthCall(*EthCallParams) (*EthCallResult, error) + // Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. + EthEstimateGas(*EthEstimateGasParams) (*EthEstimateGasResult, error) + // Generates an access list for a transaction. + EthCreateAccessList(*EthCreateAccessListParams) (*EthCreateAccessListResult, error) + // Returns the current price per gas in wei. + EthGasPrice() (*EthGasPriceResult, error) + // Returns the current maxPriorityFeePerGas per gas in wei. + EthMaxPriorityFeePerGas() (*EthMaxPriorityFeePerGasResult, error) + // Returns transaction base fee per gas and effective priority fee per gas for the requested/supported block range. + EthFeeHistory(*EthFeeHistoryParams) (*EthFeeHistoryResult, error) + // Creates a filter object, based on filter options, to notify when the state changes (logs). + EthNewFilter(*EthNewFilterParams) (*EthNewFilterResult, error) + // Creates a filter in the node, to notify when a new block arrives. + EthNewBlockFilter() (*EthNewBlockFilterResult, error) + // Creates a filter in the node, to notify when new pending transactions arrive. + EthNewPendingTransactionFilter() (*EthNewPendingTransactionFilterResult, error) + // Uninstalls a filter with given id. + EthUninstallFilter(*EthUninstallFilterParams) (*EthUninstallFilterResult, error) + // Polling method for a filter, which returns an array of logs which occurred since last poll. + EthGetFilterChanges(*EthGetFilterChangesParams) (*EthGetFilterChangesResult, error) + // Returns an array of all logs matching filter with given id. + EthGetFilterLogs(*EthGetFilterLogsParams) (*EthGetFilterLogsResult, error) + // Returns an array of all logs matching filter with given id. + EthGetLogs(*EthGetLogsParams) (*EthGetLogsResult, error) + // Returns whether the client is actively mining new blocks. + EthMining() (*EthMiningResult, error) + // Returns the number of hashes per second that the node is mining with. + EthHashrate() (*EthHashrateResult, error) + // Returns the hash of the current block, the seedHash, and the boundary condition to be met (“targetâ€). + EthGetWork() (*EthGetWorkResult, error) + // Used for submitting a proof-of-work solution. + EthSubmitWork(*EthSubmitWorkParams) (*EthSubmitWorkResult, error) + // Used for submitting mining hashrate. + EthSubmitHashrate(*EthSubmitHashrateParams) (*EthSubmitHashrateResult, error) + // Returns an EIP-191 signature over the provided data. + EthSign(*EthSignParams) (*EthSignResult, error) + // Returns an RLP encoded transaction signed by the specified account. + EthSignTransaction(*EthSignTransactionParams) (*EthSignTransactionResult, error) + // Returns the balance of the account of given address. + EthGetBalance(*EthGetBalanceParams) (*EthGetBalanceResult, error) + // Returns the value from a storage position at a given address. + EthGetStorageAt(*EthGetStorageAtParams) (*EthGetStorageAtResult, error) + // Returns the number of transactions sent from an address. + EthGetTransactionCount(*EthGetTransactionCountParams) (*EthGetTransactionCountResult, error) + // Returns code at a given address. + EthGetCode(*EthGetCodeParams) (*EthGetCodeResult, error) + // Returns the merkle proof for a given account and optionally some storage keys. + EthGetProof(*EthGetProofParams) (*EthGetProofResult, error) + // Signs and submits a transaction. + EthSendTransaction(*EthSendTransactionParams) (*EthSendTransactionResult, error) + // Submits a raw transaction. + EthSendRawTransaction(*EthSendRawTransactionParams) (*EthSendRawTransactionResult, error) + // Returns the information about a transaction requested by transaction hash. + EthGetTransactionByHash(*EthGetTransactionByHashParams) (*EthGetTransactionByHashResult, error) + // Returns information about a transaction by block hash and transaction index position. + EthGetTransactionByBlockHashAndIndex(*EthGetTransactionByBlockHashAndIndexParams) (*EthGetTransactionByBlockHashAndIndexResult, error) + // Returns information about a transaction by block number and transaction index position. + EthGetTransactionByBlockNumberAndIndex(*EthGetTransactionByBlockNumberAndIndexParams) (*EthGetTransactionByBlockNumberAndIndexResult, error) + // Returns the receipt of a transaction by transaction hash. + EthGetTransactionReceipt(*EthGetTransactionReceiptParams) (*EthGetTransactionReceiptResult, error) +} +type BlockNumberOrTag struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type DebugGetRawHeaderParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type DebugGetRawHeaderResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type DebugGetRawBlockParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type DebugGetRawBlockResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type DebugGetRawTransactionParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type DebugGetRawTransactionResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type DebugGetRawReceiptsParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type ReceiptArray struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type DebugGetRawReceiptsResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + FieldReceiptArray []string `json:"receiptArray"` +} +type BadBlock struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type BadBlockArray struct { + BadBlock +} +type DebugGetBadBlocksResult struct { + BadBlock + + FieldBadBlockArray []BadBlock `json:"badBlockArray"` +} +type EthGetBlockByHashParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldHydrated bool `json:"hydrated"` +} +type BlockObject struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + Field256HexEncodedBytes string `json:"256HexEncodedBytes"` + + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + Field8HexEncodedBytes string `json:"8HexEncodedBytes"` + + FieldUncles []string `json:"uncles"` +} +type Uncles struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type EthGetBlockByHashResult struct { + BlockObject +} +type EthGetBlockByNumberParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` + + FieldHydrated bool `json:"hydrated"` +} +type EthGetBlockByNumberResult struct { + BlockObject +} +type EthGetBlockTransactionCountByHashParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type EthGetBlockTransactionCountByHashResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetBlockTransactionCountByNumberParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthGetBlockTransactionCountByNumberResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetUncleCountByBlockHashParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type EthGetUncleCountByBlockHashResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetUncleCountByBlockNumberParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthGetUncleCountByBlockNumberResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthChainIdResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type SyncingProgress struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type SyncingStatus struct { + SyncingProgress +} +type EthSyncingResult struct { + FieldSyncingStatus SyncingProgress `json:"syncingStatus"` +} +type EthCoinbaseResult struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` +} +type Accounts struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` +} +type EthAccountsResult struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldAccounts []string `json:"accounts"` +} +type EthBlockNumberResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type TransactionObjectGenericToAllTypes struct { + FieldHexEncodedByte string `json:"hexEncodedByte"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + // EIP-2930 access list + AccessListEntry + // EIP-2930 access list + FieldAccessList []AccessListEntry `json:"accessList"` + + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + FieldHexEncodedAddress string `json:"hexEncodedAddress"` +} +type AccessListEntry struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldStorageKeys []string `json:"storageKeys"` +} +type StorageKeys struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type AccessList struct { + AccessListEntry +} +type EthCallParams struct { + TransactionObjectGenericToAllTypes + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthCallResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthEstimateGasParams struct { + TransactionObjectGenericToAllTypes + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthEstimateGasResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthCreateAccessListParams struct { + TransactionObjectGenericToAllTypes + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type AccessListResult struct { + AccessListEntry + + FieldAccessList []AccessListEntry `json:"accessList"` + + FieldError string `json:"error"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthCreateAccessListResult struct { + AccessListResult +} +type EthGasPriceResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthMaxPriorityFeePerGasResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthFeeHistoryParams struct { + // Requested range of blocks. Clients will return less than the requested range if not all blocks are available. + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + // Highest block of the requested range. + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` + // Floating point value between 0 and 100. + FieldRewardPercentile number `json:"rewardPercentile"` + // A monotonically increasing list of percentile values. For each block in the requested range, the transactions will be sorted in ascending order by effective tip per gas and the coresponding effective tip for the percentile will be determined, accounting for gas consumed. + FieldRewardPercentiles []number `json:"rewardPercentiles"` +} +type RewardPercentiles struct { + // Floating point value between 0 and 100. + FieldRewardPercentile number `json:"rewardPercentile"` +} +type RewardPercentile struct { + // A given percentile sample of effective priority fees per gas from a single block in ascending order, weighted by gas used. Zeroes are returned if the block is empty. + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type Reward struct { + // A given percentile sample of effective priority fees per gas from a single block in ascending order, weighted by gas used. Zeroes are returned if the block is empty. + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + // An array of effective priority fee per gas data points from a single block. All zeroes are returned if the block is empty. + FieldRewardPercentile []string `json:"rewardPercentile"` +} +type FeeHistoryResults struct { + // Lowest number block of returned range. + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + // An array of effective priority fee per gas data points from a single block. All zeroes are returned if the block is empty. + FieldRewardPercentile []string `json:"rewardPercentile"` + // A two-dimensional array of effective priority fees per gas at the requested block percentiles. + FieldReward []array `json:"reward"` + // An array of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks. + FieldBaseFeePerGas []string `json:"baseFeePerGas"` +} +type BaseFeePerGas struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthFeeHistoryResult struct { + // Fee history results. + FeeHistoryResults +} +type Address struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` +} +type Filter struct { + FieldAddress string `json:"address"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + + FieldFilterTopicListEntry null `json:"filterTopicListEntry"` + + FieldFilterTopics []FilterTopicListEntry `json:"filterTopics"` +} +type FilterTopicListEntry struct { + FieldAnyTopicMatch null `json:"anyTopicMatch"` +} +type FilterTopics struct { + FieldFilterTopicListEntry null `json:"filterTopicListEntry"` +} +type EthNewFilterParams struct { + Filter +} +type EthNewFilterResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthNewBlockFilterResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthNewPendingTransactionFilterResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthUninstallFilterParams struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthUninstallFilterResult struct { + FieldSuccess bool `json:"success"` +} +type EthGetFilterChangesParams struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type NewBlockHashes struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type FilterResults struct { + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldNewBlockHashes []string `json:"newBlockHashes"` +} +type EthGetFilterChangesResult struct { + FieldFilterResults array `json:"filterResults"` +} +type EthGetFilterLogsParams struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetFilterLogsResult struct { + FieldFilterResults array `json:"filterResults"` +} +type EthGetLogsParams struct { + Filter +} +type EthGetLogsResult struct { + FieldFilterResults array `json:"filterResults"` +} +type EthMiningResult struct { + FieldMiningStatus bool `json:"miningStatus"` +} +type EthHashrateResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetWorkResult struct { + FieldCurrentWork []string `json:"currentWork"` +} +type EthSubmitWorkParams struct { + Field8HexEncodedBytes string `json:"8HexEncodedBytes"` + + Field32HexEncodedBytes string `json:"32HexEncodedBytes"` +} +type EthSubmitWorkResult struct { + FieldSuccess bool `json:"success"` +} +type EthSubmitHashrateParams struct { + Field32HexEncodedBytes string `json:"32HexEncodedBytes"` +} +type EthSubmitHashrateResult struct { + FieldSuccess bool `json:"success"` +} +type EthSignParams struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthSignResult struct { + Field65HexEncodedBytes string `json:"65HexEncodedBytes"` +} +type EthSignTransactionParams struct { + TransactionObjectGenericToAllTypes +} +type EthSignTransactionResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthGetBalanceParams struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthGetBalanceResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetStorageAtParams struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthGetStorageAtResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthGetTransactionCountParams struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthGetTransactionCountResult struct { + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetCodeParams struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type EthGetCodeResult struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthGetProofParams struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldStorageKeys []string `json:"storageKeys"` + + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` +} +type AccountProof struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + FieldAccountProof []string `json:"accountProof"` + + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldStorageProof []StorageProof `json:"storageProof"` +} +type StorageProof struct { + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + FieldProof []string `json:"proof"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type Proof struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthGetProofResult struct { + AccountProof +} +type EthSendTransactionParams struct { + TransactionObjectGenericToAllTypes +} +type EthSendTransactionResult struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type EthSendRawTransactionParams struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` +} +type EthSendRawTransactionResult struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type EthGetTransactionByHashParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type EthGetTransactionByHashResult struct { + FieldTransactionInformation object `json:"transactionInformation"` +} +type EthGetTransactionByBlockHashAndIndexParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetTransactionByBlockHashAndIndexResult struct { + FieldTransactionInformation object `json:"transactionInformation"` +} +type EthGetTransactionByBlockNumberAndIndexParams struct { + FieldBlockNumberOrTag string `json:"blockNumberOrTag"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` +} +type EthGetTransactionByBlockNumberAndIndexResult struct { + FieldTransactionInformation object `json:"transactionInformation"` +} +type EthGetTransactionReceiptParams struct { + Field32ByteHexValue string `json:"32ByteHexValue"` +} +type ContractAddress struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` +} +type ReceiptInfo struct { + // The contract address created, if the transaction was a contract creation, otherwise null. + FieldContractAddress string `json:"contractAddress"` + // The post-transaction state root. Only specified for transactions included before the Byzantium upgrade. + Field32HexEncodedBytes string `json:"32HexEncodedBytes"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + // Address of the receiver or null in a contract creation transaction. + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + Field32ByteHexValue string `json:"32ByteHexValue"` + + Log + + FieldLogs []Log `json:"logs"` + + Field256HexEncodedBytes string `json:"256HexEncodedBytes"` +} +type Log struct { + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + + Field32ByteHexValue string `json:"32ByteHexValue"` + + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + + FieldRemoved bool `json:"removed"` + + Field32HexEncodedBytes string `json:"32HexEncodedBytes"` + + FieldTopics []string `json:"topics"` +} +type Topics struct { + Field32HexEncodedBytes string `json:"32HexEncodedBytes"` +} +type Logs struct { + Log +} +type EthGetTransactionReceiptResult struct { + ReceiptInfo +} diff --git a/openrpc/templates/types.gotmpl b/openrpc/templates/types.gotmpl index 5d3b3dd4a5c95f1939d40cae82139332a2d43a37..3c005028470073e844b928c3045717f341dd22e8 100644 --- a/openrpc/templates/types.gotmpl +++ b/openrpc/templates/types.gotmpl @@ -24,13 +24,13 @@ type GoOpenRPCService interface { } {{- range (getObjects .Objects) }} -{{ printf "type %s struct {" (fixName .Name) }} +{{ printf "type %s struct {" .Name }} {{- range (getFields .Fields) }} {{ maybeFieldComment .Desc }} {{- if (eq .Name .Type) }} -{{ printf "%s" (fixName .Name) }} +{{ printf "%s" .Name }} {{- else }} -{{ printf "%s %s `json:\"%s\"`" (fixName .Name) .Type (fixName (lowerFirst .Name)) }} +{{ printf "Field%s %s `json:\"%s\"`" .Name .Type (lowerFirst .Name) }} {{- end }} {{- end }} {{ printf "}" }} diff --git a/openrpc/util/common.go b/openrpc/util/common.go index d01c8d4a3ea688fe25a9e9391ad3b8360d298b47..afb4f6b033ad0f2cfa6129c433f5233f269a424a 100644 --- a/openrpc/util/common.go +++ b/openrpc/util/common.go @@ -26,7 +26,12 @@ func Inpect(val interface{}) string { } func CamelCase(name string) string { - in := strings.Split(name, "_") + var in []string + if strings.Contains(name, " ") { + in = strings.Split(name, " ") + } else { + in = strings.Split(name, "_") + } if len(in) == 0 { return strings.Title(name) }