Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to YAML config #82

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
config.toml
config.yml
main
.idea
.DS_Store
aliases.toml
aliases.yml
cosmos-transactions-bot
dist/
cover.out
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ User=<username>
TimeoutStartSec=0
CPUWeight=95
IOWeight=95
ExecStart=cosmos-transactions-bot --config /path/to/config.toml
ExecStart=cosmos-transactions-bot --config /path/to/config.yml
Restart=always
RestartSec=2
LimitNOFILE=800000
Expand Down Expand Up @@ -81,8 +81,8 @@ and validator rewards are claimed from). Lastly, each of these transactions are

## How can I configure it?

All configuration is done with a `.toml` file, which is passed to an app through a `--config` flag.
See `config.example.toml` for reference.
All configuration is done with a `.yml` file, which is passed to an app through a `--config` flag.
See `config.example.yml` for reference.

### Chains, subscriptions, chain subscriptions and reporters

Expand Down Expand Up @@ -135,17 +135,17 @@ That's also manageable. You can do the following:
- subscription 3, let's call it "whale-votes", with reporter "third" and the following chain subscription
- - chain subscription 1, chain C, 1 filter matching any delegations with amount more than 10M $TOKEN on chain C

See config.example.toml for real-life examples.
See config.example.yml for real-life examples.

### Queries and filters

This is another quite complex topic and deserves a special explanation.

When a node starts, it connects to a Websocket of the fullnode and subscribes to queries (`queries` in `.toml` config).
When a node starts, it connects to a Websocket of the fullnode and subscribes to queries (`queries` in `.yml` config).
If there's a transaction that does not match these filters, a fullnode won't emit the event for it
and this transaction won't reach the app.

If using filters (`filters` in `.toml` config), when a transaction is received, all messages in the transaction
If using filters (`filters` in `.yml` config), when a transaction is received, all messages in the transaction
are checked whether they match these filters, and can be filtered out (and the transaction itself would be filtered out
if there are 0 non-filtered messages left).

Expand Down Expand Up @@ -212,7 +212,7 @@ See [the documentation](https://docs.tendermint.com/master/rpc/#/Websocket/subsc
One important thing to keep in mind: by default, Tendermint RPC now only allows 5 connections per client,
so if you have more than 5 filters specified, this will fail when subscribing to 6th one.
If you own the node you are subscribing to, o fix this, change this parameter to something that suits your needs
in `<fullnode folder>/config/config.toml`:
in `<fullnode folder>/config/config.yml`:

```
max_subscriptions_per_client = 5
Expand Down Expand Up @@ -284,7 +284,7 @@ unless you contact it first, so write a message to a bot before proceeding.
- you want to send messages to a channel. Write something to a channel, then forward it to [@getmyid_bot](https://t.me/getmyid_bot)
and copy the `Forwarded from chat` number. Then add the bot as an admin.

Then run a program with Telegram config (see `config.example.toml` as example).
Then run a program with Telegram config (see `config.example.yml` as example).

You would likely want to also put only the IDs of trusted people to admins list in Telegram config, so the bot
won't react to anyone writing messages to it except these users.
Expand Down
3 changes: 0 additions & 3 deletions assets/aliases.toml

This file was deleted.

3 changes: 3 additions & 0 deletions assets/aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
subscription:
chain:
wallet: test
20 changes: 0 additions & 20 deletions assets/invalid-timezone.toml

This file was deleted.

23 changes: 23 additions & 0 deletions assets/invalid-timezone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
timezone: invalid
reporters:
- name: reporter
type: telegram
telegram-config:
token: xxx:yyy
chat: 12345
admins:
- 67890
subscriptions:
- reporter: telegram
name: subscription
chains:
- name: cosmos
filters:
- message.action = '/cosmos.gov.v1beta1.MsgVote'
chains:
- name: cosmos
chain-id: cosmoshub-4
tendermint-nodes:
- https://rpc.cosmos.quokkastake.io:443
api-nodes:
- https://api.cosmos.quokkastake.io
1 change: 0 additions & 1 deletion assets/invalid-toml.toml

This file was deleted.

1 change: 1 addition & 0 deletions assets/invalid-yaml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not-valid-yaml
3 changes: 0 additions & 3 deletions assets/valid-aliases.toml

This file was deleted.

3 changes: 3 additions & 0 deletions assets/valid-aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
subscription:
chain:
wallet: alias
33 changes: 0 additions & 33 deletions assets/valid-unused-chain.toml

This file was deleted.

39 changes: 39 additions & 0 deletions assets/valid-unused-chain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
timezone: Etc/UTC
reporters:
- name: reporter
type: telegram
telegram-config:
token: xxx:yyy
chat: 12345
admins:
- 67890
subscriptions:
- reporter: reporter
name: subscription
chains:
- name: cosmos
filters:
- message.action = '/cosmos.gov.v1beta1.MsgVote'
chains:
- name: cosmos
chain-id: cosmoshub-4
tendermint-nodes:
- https://rpc.cosmos.quokkastake.io:443
api-nodes:
- https://api.cosmos.quokkastake.io
mintscan-prefix: cosmos
denoms:
- denom: uatom
display-denom: atom
coingecko-currency: cosmos
- name: sentinel
chain-id: sentinelhub-2
tendermint-nodes:
- https://rpc.sentine;.quokkastake.io:443
api-nodes:
- https://api.sentine;.quokkastake.io
mintscan-prefix: sent
denoms:
- denom: udvpn
display-denom: dvpn
coingecko-currency: sentinel
28 changes: 0 additions & 28 deletions assets/valid-unused-reporter.toml

This file was deleted.

35 changes: 35 additions & 0 deletions assets/valid-unused-reporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
timezone: Etc/UTC
reporters:
- name: reporter
type: telegram
telegram-config:
token: xxx:yyy
chat: 12345
admins:
- 67890
- name: reporter-2
type: telegram
telegram-config:
token: xxx:yyy
chat: 12345
admins:
- 67890
subscriptions:
- reporter: reporter
name: subscription
chains:
- name: cosmos
filters:
- message.action = '/cosmos.gov.v1beta1.MsgVote'
chains:
- name: cosmos
chain-id: cosmoshub-4
tendermint-nodes:
- https://rpc.cosmos.quokkastake.io:443
api-nodes:
- https://api.cosmos.quokkastake.io
mintscan-prefix: cosmos
denoms:
- denom: uatom
display-denom: atom
coingecko-currency: cosmos
23 changes: 0 additions & 23 deletions assets/valid.toml

This file was deleted.

28 changes: 28 additions & 0 deletions assets/valid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
timezone: Etc/UTC
reporters:
- name: reporter
type: telegram
telegram-config:
token: xxx:yyy
chat: 12345
admins:
- 67890
subscriptions:
- reporter: reporter
name: subscription
chains:
- name: cosmos
filters:
- message.action = '/cosmos.gov.v1beta1.MsgVote'
chains:
- name: cosmos
chain-id: cosmoshub-4
tendermint-nodes:
- https://rpc.cosmos.quokkastake.io:443
api-nodes:
- https://api.cosmos.quokkastake.io
mintscan-prefix: cosmos
denoms:
- denom: uatom
display-denom: atom
coingecko-currency: cosmos
10 changes: 5 additions & 5 deletions cmd/cosmos-transactions-bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestValidateConfigFailedToLoad(t *testing.T) {
}
}()

os.Args = []string{"cmd", "validate-config", "--config", "../assets/config-not-found.toml"}
os.Args = []string{"cmd", "validate-config", "--config", "../assets/config-not-found.yml"}
main()
}

Expand All @@ -39,19 +39,19 @@ func TestValidateConfigInvalid(t *testing.T) {
}
}()

os.Args = []string{"cmd", "validate-config", "--config", "../assets/invalid-timezone.toml"}
os.Args = []string{"cmd", "validate-config", "--config", "../assets/invalid-timezone.yml"}
main()
}

//nolint:paralleltest // disabled
func TestValidateConfigWithWarnings(_ *testing.T) {
os.Args = []string{"cmd", "validate-config", "--config", "../assets/valid-unused-chain.toml"}
os.Args = []string{"cmd", "validate-config", "--config", "../assets/valid-unused-chain.yml"}
main()
}

//nolint:paralleltest // disabled
func TestValidateConfigValid(_ *testing.T) {
os.Args = []string{"cmd", "validate-config", "--config", "../assets/valid.toml"}
os.Args = []string{"cmd", "validate-config", "--config", "../assets/valid.yml"}
main()
}

Expand All @@ -75,6 +75,6 @@ func TestStartConfigProvided(t *testing.T) {
}
}()

os.Args = []string{"cmd", "--config", "../assets/invalid-timezone.toml"}
os.Args = []string{"cmd", "--config", "../assets/invalid-timezone.yml"}
main()
}
Loading
Loading