forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(misc/autocounterd): init autocounterd
- Loading branch information
Showing
9 changed files
with
594 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: autocounterd | ||
|
||
on: | ||
push: | ||
paths: | ||
- misc/autocounterd | ||
- .github/workflows/autocounterd.yml | ||
branches: | ||
- "master" | ||
- "misc/autocounterd" | ||
tags: | ||
- "v*" | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
autocounterd: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker metadata autcounterd | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }}/autcounterd | ||
tags: | | ||
type=raw,value=latest | ||
type=semver,pattern=v{{version}} | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./misc/autocounterd | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM golang:alpine AS builder | ||
|
||
COPY . /go/src/github.com/gnolang/gno/misc/loop | ||
|
||
WORKDIR /go/src/github.com/gnolang/gno/misc/loop | ||
|
||
RUN go build -o /build/autocounterd ./cmd | ||
|
||
# Final image for autocounterd | ||
FROM alpine AS autocounterd | ||
|
||
COPY --from=builder /build/autocounterd /usr/bin/autocounterd | ||
|
||
ENTRYPOINT [ "/usr/bin/autocounterd" ] | ||
CMD [ "start" ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Autocounterd | ||
|
||
## What is it? | ||
|
||
`autcounterd` is a simple binary that increment a simple counter every x seconds to analyse and test a network. | ||
|
||
## How to use | ||
|
||
Start the loop with: | ||
|
||
``` sh | ||
$ docker compose up -d | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
ff "github.com/peterbourgon/ff/v4" | ||
|
||
"github.com/gnolang/gno/gno.land/pkg/gnoclient" | ||
rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" | ||
) | ||
|
||
func (s *service) NewStartCmd() *ff.Command { | ||
rootFlags := ff.NewFlagSet("autocounterd") | ||
s.rpcURL = rootFlags.StringLong("rpc", "127.0.0.1:26657", "rpc url endpoint") | ||
s.chainID = rootFlags.StringLong("chain-id", "dev", "chain-id") | ||
s.mnemonic = rootFlags.StringLong("mnemonic", "", "mnemonic") | ||
s.realmPath = rootFlags.StringLong("realm", "gno.land/r/portal/counter", "realm path") | ||
s.incrementInterval = rootFlags.DurationLong("interval", 15*time.Second, "Increment counter interval") | ||
|
||
cmd := &ff.Command{ | ||
Name: "start", | ||
Flags: rootFlags, | ||
Exec: s.execStart, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (s *service) execStart(ctx context.Context, args []string) error { | ||
if err := s.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
signer, err := gnoclient.SignerFromBip39(s.MustGetMnemonic(), s.MustGetChainID(), "", uint32(0), uint32(0)) | ||
if err != nil { | ||
return err | ||
} | ||
if err := signer.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
rpcClient := rpcclient.NewHTTP(s.MustGetRPC(), "/websocket") | ||
|
||
client := gnoclient.Client{ | ||
Signer: signer, | ||
RPCClient: rpcClient, | ||
} | ||
|
||
for { | ||
res, err := client.Call(gnoclient.CallCfg{ | ||
PkgPath: s.MustGetRealmPath(), | ||
FuncName: "Incr", | ||
GasFee: "10000000ugnot", | ||
GasWanted: 800000, | ||
Args: nil, | ||
}) | ||
_ = res | ||
|
||
if err != nil { | ||
fmt.Printf("[ERROR] Failed to call Incr on %s, %+v\n", s.MustGetRealmPath(), err.Error()) | ||
} else { | ||
fmt.Println("[INFO] Counter incremented with success") | ||
} | ||
time.Sleep(s.MustGetIncrementInterval()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
ff "github.com/peterbourgon/ff/v4" | ||
"github.com/peterbourgon/ff/v4/ffhelp" | ||
) | ||
|
||
type service struct { | ||
rpcURL *string | ||
chainID *string | ||
mnemonic *string | ||
realmPath *string | ||
incrementInterval *time.Duration | ||
} | ||
|
||
func (s service) Validate() error { | ||
fmt.Println("mnemonic: ", *s.mnemonic) | ||
fmt.Println("rpc: ", *s.rpcURL) | ||
if s.mnemonic != nil && *s.mnemonic == "" { | ||
return fmt.Errorf("mnemonic is missing") | ||
} else if s.rpcURL != nil && *s.rpcURL == "" { | ||
return fmt.Errorf("rpc url is missing") | ||
} else if s.chainID != nil && *s.chainID == "" { | ||
return fmt.Errorf("chain_id is missing") | ||
} else if s.incrementInterval == nil { | ||
return fmt.Errorf("interval is missing") | ||
} else if s.realmPath != nil && *s.realmPath == "" { | ||
return fmt.Errorf("realm path is missing") | ||
} | ||
return nil | ||
} | ||
|
||
func (s service) MustGetRPC() string { return *s.rpcURL } | ||
func (s service) MustGetChainID() string { return *s.chainID } | ||
func (s service) MustGetMnemonic() string { return *s.mnemonic } | ||
func (s service) MustGetRealmPath() string { return *s.realmPath } | ||
func (s service) MustGetIncrementInterval() time.Duration { return *s.incrementInterval } | ||
|
||
func main() { | ||
s := &service{} | ||
|
||
rootCmd := &ff.Command{ | ||
Name: "autocounterd", | ||
Subcommands: []*ff.Command{ | ||
s.NewStartCmd(), | ||
}, | ||
} | ||
|
||
err := rootCmd.ParseAndRun( | ||
context.Background(), | ||
os.Args[1:], | ||
ff.WithEnvVarPrefix("COUNTER")) | ||
|
||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Command(rootCmd)) | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: "3" | ||
services: | ||
autocounterd: | ||
image: ghcr.io/gnolang/gno/autocounterd | ||
build: | ||
context: . | ||
restart: unless-stopped | ||
environment: | ||
COUNTER_MNEMONIC: "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast" | ||
# COUNTER_RPC: "http://127.0.0.1:26657" | ||
COUNTER_RPC: "https://rpc.portal.gnoteam.com:443" | ||
COUNTER_CHAIN_ID: "portal-loop" | ||
# COUNTER_CHAIN_ID: "dev" | ||
COUNTER_INTERVAL: "5s" | ||
COUNTER_REALM: "gno.land/r/portal/counter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module loop | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/gnolang/gno v0.0.0-20240125181217-b6193518e278 | ||
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4 | ||
) | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect | ||
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.1 // indirect | ||
github.com/cockroachdb/apd/v3 v3.2.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect | ||
github.com/dgraph-io/badger/v3 v3.2103.5 // indirect | ||
github.com/dgraph-io/ristretto v0.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.0 // indirect | ||
github.com/gnolang/goleveldb v0.0.9 // indirect | ||
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect | ||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/flatbuffers v1.12.1 // indirect | ||
github.com/gorilla/websocket v1.5.1 // indirect | ||
github.com/jaekwon/testify v1.6.1 // indirect | ||
github.com/jmhodges/levigo v1.0.0 // indirect | ||
github.com/klauspost/compress v1.12.3 // indirect | ||
github.com/libp2p/go-buffer-pool v0.1.0 // indirect | ||
github.com/linxGnu/grocksdb v1.8.11 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rs/cors v1.10.1 // indirect | ||
github.com/stretchr/testify v1.8.4 // indirect | ||
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect | ||
go.etcd.io/bbolt v1.3.8 // indirect | ||
go.opencensus.io v0.22.5 // indirect | ||
go.uber.org/multierr v1.10.0 // indirect | ||
golang.org/x/crypto v0.18.0 // indirect | ||
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect | ||
golang.org/x/mod v0.14.0 // indirect | ||
golang.org/x/net v0.20.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/tools v0.17.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.