Skip to content

Commit 683252e

Browse files
zivkovicmilosaeddi
andauthored
feat: switch to using JSON-RPC 2.0 by default (#70)
* Switch to using JSON-RPC 2.0 by default * Bump go version * Add omit * Simplify default handler * Bump linter workflow version * Update README * Update README.md Co-authored-by: Antoine Eddi <5222525+aeddi@users.noreply.github.com> --------- Co-authored-by: Antoine Eddi <5222525+aeddi@users.noreply.github.com>
1 parent 8d1911a commit 683252e

File tree

12 files changed

+507
-372
lines changed

12 files changed

+507
-372
lines changed

.github/golangci.yaml

Lines changed: 120 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,132 @@
1+
version: "2"
12
run:
23
concurrency: 8
3-
timeout: 10m
4-
issue-exit-code: 1
5-
tests: true
6-
skip-dirs-use-default: true
4+
go: ""
75
modules-download-mode: readonly
6+
tests: true
87
allow-parallel-runners: false
9-
go: ""
10-
118
output:
12-
uniq-by-line: false
139
path-prefix: ""
14-
sort-results: true
15-
10+
linters:
11+
default: none
12+
enable:
13+
- asasalint
14+
- asciicheck
15+
- bidichk
16+
- decorder
17+
- dogsled
18+
- dupl
19+
- durationcheck
20+
- errcheck
21+
- errname
22+
- errorlint
23+
- gocheckcompilerdirectives
24+
- gochecknoinits
25+
- goconst
26+
- gocritic
27+
- godot
28+
- gomoddirectives
29+
- gosec
30+
- govet
31+
- importas
32+
- ineffassign
33+
- lll
34+
- loggercheck
35+
- makezero
36+
- misspell
37+
- nakedret
38+
- nestif
39+
- nilerr
40+
- nilnil
41+
- nlreturn
42+
- nolintlint
43+
- nonamedreturns
44+
- prealloc
45+
- predeclared
46+
- promlinter
47+
- reassign
48+
- revive
49+
- staticcheck
50+
- tagliatelle
51+
- testableexamples
52+
- thelper
53+
- tparallel
54+
- unconvert
55+
- unparam
56+
- unused
57+
- usestdlibvars
58+
- wastedassign
59+
- whitespace
60+
- wsl
61+
settings:
62+
errcheck:
63+
check-type-assertions: false
64+
check-blank: true
65+
exclude-functions:
66+
- io/ioutil.ReadFile
67+
- io.Copy(*bytes.Buffer)
68+
- io.Copy(os.Stdout)
69+
goconst:
70+
min-len: 3
71+
min-occurrences: 3
72+
gocritic:
73+
disabled-checks:
74+
- hugeParam
75+
- rangeExprCopy
76+
- rangeValCopy
77+
- importShadow
78+
- unnamedResult
79+
enabled-tags:
80+
- diagnostic
81+
- experimental
82+
- opinionated
83+
- performance
84+
- style
85+
godot:
86+
scope: all
87+
period: false
88+
govet:
89+
enable-all: true
90+
nakedret:
91+
max-func-lines: 1
92+
tagliatelle:
93+
case:
94+
rules:
95+
json: goCamel
96+
yaml: goCamel
97+
use-field-name: true
98+
exclusions:
99+
generated: lax
100+
presets:
101+
- comments
102+
- common-false-positives
103+
- legacy
104+
- std-error-handling
105+
rules:
106+
- linters:
107+
- gosec
108+
- nilnil
109+
path: (.+)_test.go
110+
paths:
111+
- third_party$
112+
- builtin$
113+
- examples$
16114
issues:
17115
max-issues-per-linter: 0
18116
max-same-issues: 0
19117
new: false
20118
fix: false
21-
exclude-rules:
22-
- path: (.+)_test.go
23-
linters:
24-
- nilnil
25-
- gosec
26-
27-
linters:
28-
fast: false
29-
disable-all: true
119+
formatters:
30120
enable:
31-
- asasalint # Check for pass []any as any in variadic func(...any)
32-
- asciicheck # Detects funky ASCII characters
33-
- bidichk # Checks for dangerous unicode character sequences
34-
- durationcheck # Check for two durations multiplied together
35-
- errcheck # Forces to not skip error check
36-
- exportloopref # Checks for pointers to enclosing loop variables
37-
- gocritic # Bundles different linting checks
38-
- godot # Checks for periods at the end of comments
39-
- gomoddirectives # Allow or ban replace directives in go.mod
40-
- gosimple # Code simplification
41-
- govet # Official Go tool
42-
- ineffassign # Detects when assignments to existing variables are not used
43-
- nakedret # Finds naked/bare returns and requires change them
44-
- nilerr # Requires explicit returns
45-
- nilnil # Requires explicit returns
46-
- promlinter # Lints Prometheus metrics names
47-
- reassign # Checks that package variables are not reassigned
48-
- revive # Drop-in replacement for golint
49-
- tagliatelle # Checks struct tags
50-
- tenv # Detects using os.Setenv instead of t.Setenv
51-
- testableexamples # Checks if examples are testable (have expected output)
52-
- unparam # Finds unused params
53-
- usestdlibvars # Detects the possibility to use variables/constants from stdlib
54-
- wastedassign # Finds wasted assignment statements
55-
- loggercheck # Checks the odd number of key and value pairs for common logger libraries
56-
- nestif # Finds deeply nested if statements
57-
- nonamedreturns # Reports all named returns
58-
- decorder # Check declaration order of types, consts, vars and funcs
59-
- gocheckcompilerdirectives # Checks that compiler directive comments (//go:) are valid
60-
- gochecknoinits # Checks for init methods
61-
- whitespace # Tool for detection of leading and trailing whitespace
62-
- wsl # Forces you to use empty lines
63-
- unconvert # Unnecessary type conversions
64-
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
65-
- thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers
66-
- stylecheck # Stylecheck is a replacement for golint
67-
- prealloc # Finds slice declarations that could potentially be pre-allocated
68-
- predeclared # Finds code that shadows one of Go's predeclared identifiers
69-
- nolintlint # Ill-formed or insufficient nolint directives
70-
- nlreturn # Checks for a new line before return and branch statements to increase code clarity
71-
- misspell # Misspelled English words in comments
72-
- makezero # Finds slice declarations with non-zero initial length
73-
- lll # Long lines
74-
- importas # Enforces consistent import aliases
75-
- gosec # Security problems
76-
- gofmt # Whether the code was gofmt-ed
77-
- gofumpt # Stricter gofmt
78-
- goimports # Unused imports
79-
- goconst # Repeated strings that could be replaced by a constant
80-
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
81-
- dupl # Code clone detection
82-
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
83-
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
84-
- unused # Checks Go code for unused constants, variables, functions and types
85-
86-
linters-settings:
87-
gocritic:
88-
enabled-tags:
89-
- diagnostic
90-
- experimental
91-
- opinionated
92-
- performance
93-
- style
94-
disabled-checks:
95-
- hugeParam
96-
- rangeExprCopy
97-
- rangeValCopy
98-
- importShadow
99-
- unnamedResult
100-
errcheck:
101-
check-type-assertions: false
102-
check-blank: true
103-
exclude-functions:
104-
- io/ioutil.ReadFile
105-
- io.Copy(*bytes.Buffer)
106-
- io.Copy(os.Stdout)
107-
nakedret:
108-
max-func-lines: 1
109-
govet:
110-
enable-all: true
111-
gofmt:
112-
simplify: true
113-
goconst:
114-
min-len: 3
115-
min-occurrences: 3
116-
godot:
117-
scope: all
118-
period: false
119-
tagliatelle:
120-
case:
121-
use-field-name: true
122-
rules:
123-
json: goCamel
124-
yaml: goCamel
121+
- gofmt
122+
- gofumpt
123+
- goimports
124+
settings:
125+
gofmt:
126+
simplify: true
127+
exclusions:
128+
generated: lax
129+
paths:
130+
- third_party$
131+
- builtin$
132+
- examples$

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
- name: Install Go
1010
uses: actions/setup-go@v5
1111
with:
12-
go-version: 1.22.x
12+
go-version: 1.23.x
1313

1414
- name: Checkout code
1515
uses: actions/checkout@v4
1616

1717
- name: Lint
18-
uses: golangci/golangci-lint-action@v6
18+
uses: golangci/golangci-lint-action@v8
1919
with:
2020
args:
2121
--config=./.github/golangci.yaml

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- uses: actions/setup-go@v5
2222
with:
23-
go-version: 1.22
23+
go-version: 1.23
2424
cache: true
2525

2626
- uses: sigstore/cosign-installer@v3.7.0

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Install Go
1010
uses: actions/setup-go@v5
1111
with:
12-
go-version: 1.22.x
12+
go-version: 1.23.x
1313

1414
- name: Checkout code
1515
uses: actions/checkout@v4
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install Go
2424
uses: actions/setup-go@v5
2525
with:
26-
go-version: 1.22.x
26+
go-version: 1.23.x
2727

2828
- name: Checkout code
2929
uses: actions/checkout@v4

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
`faucet` is a versatile command-line interface (CLI) tool and library designed to effortlessly deploy a faucet server
66
for Gno Tendermint 2 networks.
77

8+
### Default endpoint (root)
9+
10+
The `faucet` adopts the [JSON-RPC 2.0 standard](https://www.jsonrpc.org/specification) for requests / responses.
11+
12+
By default, the `/` endpoint is the home of the `drip` method, to handle faucet drips. The first parameter is the
13+
beneficiary address, and the second one is the string representation of the drip amount (`std.Coins`).
14+
15+
This can of course be overwritten with custom handling logic by the faucet creator (see below).
16+
17+
```json
18+
{
19+
"jsonrpc": "2.0",
20+
"id": 0,
21+
"method": "drip",
22+
"params": [
23+
"g1e6gxg5tvc55mwsn7t7dymmlasratv7mkv0rap2",
24+
"1000ugnot"
25+
]
26+
}
27+
```
28+
829
## Key Features
930

1031
### Customizability
@@ -46,6 +67,7 @@ make build
4667
3. Run the faucet
4768

4869
To run the faucet, start the built binary:
70+
4971
```bash
5072
./build/faucet --mnemonic "<faucet_account_mnemonic>"
5173
```
@@ -54,16 +76,19 @@ The provided mnemonic will be used to derive accounts which will be used to serv
5476
funds to users. Make sure that the accounts derived from it are well funded.
5577

5678
It should print something like the following. (Note the port number at the end.)
79+
5780
```
5881
2024-01-11T12:47:27.826+0100 INFO cmd/logger.go:17 faucet started at [::]:8545
5982
```
6083

6184
4. To send coins to a single account, in a new terminal enter the following (change to the correct recipient address):
85+
6286
```bash
63-
curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data '{"To": "g1juz2yxmdsa6audkp6ep9vfv80c8p5u76e03vvh"}'
87+
curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data '{ "jsonrpc": "2.0", "id": 0, "method": "drip", "params": [ "g1e6gxg5tvc55mwsn7t7dymmlasratv7mkv0rap2", "1000ugnot" ] }'
6488
```
6589

66-
5. To ensure the faucet is listening to requests, you can ping the health endpoint:
90+
5. To ensure the faucet is listening to requests, you can ping the health endpoint (returns a simple status 200):
91+
6792
```bash
6893
curl --location --request GET 'http://localhost:8545/health'
6994
```
@@ -94,7 +119,7 @@ func main() {
94119
f, err := NewFaucet(
95120
static.New(...), // gas estimator
96121
http.NewClient(...), // remote address
97-
)
122+
)
98123

99124
// The faucet is controlled through a top-level context
100125
ctx, cancelFn := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)