From f3adc829114684925611e9a4f29294cdea5f8541 Mon Sep 17 00:00:00 2001 From: Garet Halliday <ghalliday@gfxlabs.io> Date: Mon, 19 Sep 2022 14:18:55 -0500 Subject: [PATCH] fix weird formatting --- openrpc/generate/generate.go | 26 ++----------- openrpc/out/server.go | 25 +----------- openrpc/out/types.go | 75 ++++++++++++++++++------------------ 3 files changed, 43 insertions(+), 83 deletions(-) diff --git a/openrpc/generate/generate.go b/openrpc/generate/generate.go index b494b13..7bd90cd 100644 --- a/openrpc/generate/generate.go +++ b/openrpc/generate/generate.go @@ -4,11 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "go/ast" - "go/parser" - "go/printer" - "go/token" - "log" + "go/format" "os" "path" "path/filepath" @@ -238,26 +234,10 @@ func WriteFile(box *packr.Box, name, pkg string, openrpc *types.OpenRPCSpec1) er return err } - log.Println(tmpl.String()) - fset := new(token.FileSet) - root, err := parser.ParseFile(fset, "", tmpl.Bytes(), parser.ParseComments) + fmtd, err := format.Source(tmpl.Bytes()) if err != nil { return err } - ast.SortImports(fset, root) - cfg := printer.Config{Mode: printer.UseSpaces | printer.TabIndent, Tabwidth: 8} - root.Name.Name = path.Base(pkg) - - err = os.MkdirAll(pkg, os.ModePerm) - if err != nil { - return err - } - file, err := os.OpenFile(path.Join(pkg, fmt.Sprintf("%s.%s", name, goExt)), os.O_RDWR|os.O_CREATE, 0644) - if err != nil { - return err - } - defer file.Close() - - return cfg.Fprint(file, fset, root) + return os.WriteFile(path.Join(pkg, fmt.Sprintf("%s.%s", name, goExt)), fmtd, 0644) } diff --git a/openrpc/out/server.go b/openrpc/out/server.go index fb2fe69..abb0ac1 100644 --- a/openrpc/out/server.go +++ b/openrpc/out/server.go @@ -1,5 +1,6 @@ // Code generated by go-openrpc. DO NOT EDIT. -package out + +package main import ( "encoding/json" @@ -495,25 +496,3 @@ 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 index d81ae89..a3941cb 100644 --- a/openrpc/out/types.go +++ b/openrpc/out/types.go @@ -1,5 +1,6 @@ // Code generated by go-openrpc. DO NOT EDIT. -package out + +package main type GoOpenRPCService interface { // Returns an RLP-encoded header. @@ -148,18 +149,18 @@ type EthGetBlockByHashParams struct { FieldHydrated bool `json:"hydrated"` } type BlockObject struct { - FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + Field32ByteHexValue string `json:"32ByteHexValue"` - FieldHexEncodedBytes string `json:"hexEncodedBytes"` + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` Field256HexEncodedBytes string `json:"256HexEncodedBytes"` - Field32ByteHexValue string `json:"32ByteHexValue"` - FieldHexEncodedAddress string `json:"hexEncodedAddress"` Field8HexEncodedBytes string `json:"8HexEncodedBytes"` + FieldHexEncodedBytes string `json:"hexEncodedBytes"` + FieldUncles []string `json:"uncles"` } type Uncles struct { @@ -230,14 +231,14 @@ 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"` + // EIP-2930 access list + AccessListEntry + // EIP-2930 access list + FieldAccessList []AccessListEntry `json:"accessList"` } type AccessListEntry struct { FieldHexEncodedAddress string `json:"hexEncodedAddress"` @@ -305,29 +306,29 @@ 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. +type BaseFeePerGas struct { 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. + // 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 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"` // 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 { +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 EthFeeHistoryResult struct { // Fee history results. FeeHistoryResults @@ -539,41 +540,38 @@ type EthGetTransactionByBlockNumberAndIndexResult struct { 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 actual value per gas deducted from the senders account. Before EIP-1559, this is equal to the transaction's gas price. After, it is equal to baseFeePerGas + min(maxFeePerGas - baseFeePerGas, maxPriorityFeePerGas). + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` // 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"` + Field32ByteHexValue string `json:"32ByteHexValue"` + // The contract address created, if the transaction was a contract creation, otherwise null. + FieldContractAddress string `json:"contractAddress"` + // Address of the receiver or null in a contract creation transaction. + FieldHexEncodedAddress string `json:"hexEncodedAddress"` + Field256HexEncodedBytes string `json:"256HexEncodedBytes"` } type Log struct { - FieldHexEncodedBytes string `json:"hexEncodedBytes"` - - FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` + FieldRemoved bool `json:"removed"` Field32ByteHexValue string `json:"32ByteHexValue"` - FieldHexEncodedAddress string `json:"hexEncodedAddress"` + FieldHexEncodedUnsignedInteger string `json:"hexEncodedUnsignedInteger"` - FieldRemoved bool `json:"removed"` + FieldHexEncodedBytes string `json:"hexEncodedBytes"` Field32HexEncodedBytes string `json:"32HexEncodedBytes"` FieldTopics []string `json:"topics"` + + FieldHexEncodedAddress string `json:"hexEncodedAddress"` } type Topics struct { Field32HexEncodedBytes string `json:"32HexEncodedBytes"` @@ -581,6 +579,9 @@ type Topics struct { type Logs struct { Log } +type ContractAddress struct { + FieldHexEncodedAddress string `json:"hexEncodedAddress"` +} type EthGetTransactionReceiptResult struct { ReceiptInfo } -- GitLab