From 90fda81b2d01c2bff4fc0af6ac671fda2c8dde25 Mon Sep 17 00:00:00 2001 From: FengFeng <1290017556@qq.com> Date: Mon, 8 Jul 2024 15:34:20 +0800 Subject: [PATCH] Add DoraVota Chain Indexer Support --- .../.github/workflows/cli-deploy.yml | 33 ++++ .../doravota-starter/.github/workflows/pr.yml | 24 +++ .../workflows/scripts/publish-deploy.sh | 14 ++ DoraVota/doravota-starter/.gitignore | 59 +++++++ DoraVota/doravota-starter/LICENSE | 21 +++ DoraVota/doravota-starter/README.md | 86 +++++++++++ DoraVota/doravota-starter/docker-compose.yml | 66 ++++++++ .../docker/load-extensions.sh | 5 + .../doravota-starter/docker/pg-Dockerfile | 12 ++ DoraVota/doravota-starter/package.json | 37 +++++ DoraVota/doravota-starter/project.ts | 71 +++++++++ .../proto/cosmos/slashing/v1beta1/gogo.proto | 144 ++++++++++++++++++ .../proto/cosmos/slashing/v1beta1/msg.proto | 22 +++ .../proto/cosmos/slashing/v1beta1/query.proto | 64 ++++++++ .../cosmos/slashing/v1beta1/slashing.proto | 45 ++++++ .../proto/cosmos/slashing/v1beta1/tx.proto | 30 ++++ DoraVota/doravota-starter/schema.graphql | 29 ++++ DoraVota/doravota-starter/src/index.ts | 2 + .../src/mappings/mappingHandlers.ts | 48 ++++++ .../src/test/mappingHandlers.test.ts | 12 ++ DoraVota/doravota-starter/tsconfig.json | 20 +++ 21 files changed, 844 insertions(+) create mode 100644 DoraVota/doravota-starter/.github/workflows/cli-deploy.yml create mode 100644 DoraVota/doravota-starter/.github/workflows/pr.yml create mode 100644 DoraVota/doravota-starter/.github/workflows/scripts/publish-deploy.sh create mode 100644 DoraVota/doravota-starter/.gitignore create mode 100644 DoraVota/doravota-starter/LICENSE create mode 100644 DoraVota/doravota-starter/README.md create mode 100644 DoraVota/doravota-starter/docker-compose.yml create mode 100644 DoraVota/doravota-starter/docker/load-extensions.sh create mode 100644 DoraVota/doravota-starter/docker/pg-Dockerfile create mode 100644 DoraVota/doravota-starter/package.json create mode 100644 DoraVota/doravota-starter/project.ts create mode 100644 DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/gogo.proto create mode 100644 DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/msg.proto create mode 100644 DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/query.proto create mode 100644 DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/slashing.proto create mode 100644 DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/tx.proto create mode 100644 DoraVota/doravota-starter/schema.graphql create mode 100644 DoraVota/doravota-starter/src/index.ts create mode 100644 DoraVota/doravota-starter/src/mappings/mappingHandlers.ts create mode 100644 DoraVota/doravota-starter/src/test/mappingHandlers.test.ts create mode 100644 DoraVota/doravota-starter/tsconfig.json diff --git a/DoraVota/doravota-starter/.github/workflows/cli-deploy.yml b/DoraVota/doravota-starter/.github/workflows/cli-deploy.yml new file mode 100644 index 000000000..5edba7c00 --- /dev/null +++ b/DoraVota/doravota-starter/.github/workflows/cli-deploy.yml @@ -0,0 +1,33 @@ +name: "CLI deploy" + +on: + workflow_dispatch: + inputs: + projectName: + description: "Project name" + required: true + type: string +jobs: + deploy: + name: CLI Deploy + runs-on: ubuntu-latest + environment: + name: DEPLOYMENT + env: + SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }} + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 16 + - run: yarn + - name: Codegen + run: yarn codegen + - name: Version + run: npx subql --version + - name: repo + run: echo ${{github.repository}} + - name: Publish and Deploy + run: | + sh .github/workflows/scripts/publish-deploy.sh -o ${{github.repository}} -p ${{github.event.inputs.projectName}} diff --git a/DoraVota/doravota-starter/.github/workflows/pr.yml b/DoraVota/doravota-starter/.github/workflows/pr.yml new file mode 100644 index 000000000..93b6fc5b5 --- /dev/null +++ b/DoraVota/doravota-starter/.github/workflows/pr.yml @@ -0,0 +1,24 @@ +name: PR +on: + pull_request: + paths-ignore: + - ".github/workflows/**" +jobs: + pr: + name: pr + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 16 + - run: yarn + - name: Codegen + run: yarn codegen + - name: Build + run: yarn build + - name: Install subql-node-cosmos + run: yarn global add @subql/node-cosmos + - name: Run tests with Subquery Node + run: subql-node-cosmos test -f ${{ github.workspace }} diff --git a/DoraVota/doravota-starter/.github/workflows/scripts/publish-deploy.sh b/DoraVota/doravota-starter/.github/workflows/scripts/publish-deploy.sh new file mode 100644 index 000000000..adae267d9 --- /dev/null +++ b/DoraVota/doravota-starter/.github/workflows/scripts/publish-deploy.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +while getopts p:o: flag +do + case "${flag}" in + p) PROJECTNAME=${OPTARG};; + o) ORG=${OPTARG};; + *) echo "Usage: $0 [-p projectname] [-o org]" && exit 1;; + esac +done + +IPFSCID=$(npx subql publish -o -f .) + +npx subql deployment:deploy -d --ipfsCID="$IPFSCID" --projectName="${PROJECTNAME}" --org="${ORG%/*}" \ No newline at end of file diff --git a/DoraVota/doravota-starter/.gitignore b/DoraVota/doravota-starter/.gitignore new file mode 100644 index 000000000..af37ddbf4 --- /dev/null +++ b/DoraVota/doravota-starter/.gitignore @@ -0,0 +1,59 @@ + +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# lock files +yarn.lock +package-lock.json + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Generated files +target/ +dist/ +src/types +project.yaml + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + +.data +dist diff --git a/DoraVota/doravota-starter/LICENSE b/DoraVota/doravota-starter/LICENSE new file mode 100644 index 000000000..f168fbe14 --- /dev/null +++ b/DoraVota/doravota-starter/LICENSE @@ -0,0 +1,21 @@ +MIT LICENSE + +Copyright 2020-2024 SubQuery Pte Ltd authors & contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/DoraVota/doravota-starter/README.md b/DoraVota/doravota-starter/README.md new file mode 100644 index 000000000..f43e53157 --- /dev/null +++ b/DoraVota/doravota-starter/README.md @@ -0,0 +1,86 @@ +# SubQuery - Example Project for DoraVota + +[SubQuery](https://subquery.network) is a fast, flexible, and reliable open-source data indexer that provides you with custom APIs for your web3 project across all of our supported networks. To learn about how to get started with SubQuery, [visit our docs](https://academy.subquery.network). + +**This SubQuery project indexes all events and messages from DoraVota** + +## Start + +First, install SubQuery CLI globally on your terminal by using NPM `npm install -g @subql/cli` + +You can either clone this GitHub repo, or use the `subql` CLI to bootstrap a clean project in the network of your choosing by running `subql init` and following the prompts. + +Don't forget to install dependencies with `npm install` or `yarn install`! + +## Editing your SubQuery project + +Although this is a working example SubQuery project, you can edit the SubQuery project by changing the following files: + +- The project manifest in `project.ts` defines the key project configuration and mapping handler filters +- The GraphQL Schema (`schema.graphql`) defines the shape of the resulting data that you are using SubQuery to index +- The Mapping functions in `src/mappings/` directory are typescript functions that handle transformation logic + +SubQuery supports various layer-1 blockchain networks and provides [dedicated quick start guides](https://academy.subquery.network/quickstart/quickstart.html) as well as [detailed technical documentation](https://academy.subquery.network/build/introduction.html) for each of them. + +## Run your project + +_If you get stuck, find out how to get help below._ + +The simplest way to run your project is by running `yarn dev` or `npm run-script dev`. This does all of the following: + +1. `yarn codegen` - Generates types from the GraphQL schema definition and contract ABIs and saves them in the `/src/types` directory. This must be done after each change to the `schema.graphql` file or the contract ABIs +2. `yarn build` - Builds and packages the SubQuery project into the `/dist` directory +3. `docker-compose pull && docker-compose up` - Runs a Docker container with an indexer, PostgeSQL DB, and a query service. This requires [Docker to be installed](https://docs.docker.com/engine/install) and running locally. The configuration for this container is set from your `docker-compose.yml` + +You can observe the three services start, and once all are running (it may take a few minutes on your first start), please open your browser and head to [http://localhost:3000](http://localhost:3000) - you should see a GraphQL playground showing with the schemas ready to query. [Read the docs for more information](https://academy.subquery.network/run_publish/run.html) or [explore the possible service configuration for running SubQuery](https://academy.subquery.network/run_publish/references.html). + +## Query your project + +For this project, you can try to query with the following GraphQL code to get a taste of how it works. + +```graphql +{ + query { + executeEvents(first: 5) { + nodes { + id + blockHeight + txHash + contractAddress + } + } + messages(first: 5) { + nodes { + id + blockHeight + txHash + sender + contract + } + } + } +} +``` + +You can explore the different possible queries and entities to help you with GraphQL using the documentation draw on the right. + +## Publish your project + +SubQuery is open-source, meaning you have the freedom to run it in the following three ways: + +- Locally on your own computer (or a cloud provider of your choosing), [view the instructions on how to run SubQuery Locally](https://academy.subquery.network/run_publish/run.html) +- By publishing it to our enterprise-level [Managed Service](https://managedservice.subquery.network), where we'll host your SubQuery project in production ready services for mission critical data with zero-downtime blue/green deployments. We even have a generous free tier. [Find out how](https://academy.subquery.network/run_publish/publish.html) +- [Coming Soon] By publishing it to the decentralised [SubQuery Network](https://subquery.network/network), the most open, performant, reliable, and scalable data service for dApp developers. The SubQuery Network indexes and services data to the global community in an incentivised and verifiable way + +## What Next? + +Take a look at some of our advanced features to take your project to the next level! + +- [**Multi-chain indexing support**](https://academy.subquery.network/build/multi-chain.html) - SubQuery allows you to index data from across different layer-1 networks into the same database, this allows you to query a single endpoint to get data for all supported networks. +- [**Dynamic Data Sources**](https://academy.subquery.network/build/dynamicdatasources.html) - When you want to index factory contracts, for example on a DEX or generative NFT project. +- [**Project Optimisation Advice**](https://academy.subquery.network/build/optimisation.html) - Some common tips on how to tweak your project to maximise performance. +- [**GraphQL Subscriptions**](https://academy.subquery.network/run_publish/subscription.html) - Build more reactive front end applications that subscribe to changes in your SubQuery project. + +## Need Help? + +The fastest way to get support is by [searching our documentation](https://academy.subquery.network), or by [joining our discord](https://discord.com/invite/subquery) and messaging us in the `#technical-support` channel. diff --git a/DoraVota/doravota-starter/docker-compose.yml b/DoraVota/doravota-starter/docker-compose.yml new file mode 100644 index 000000000..c057f3eb0 --- /dev/null +++ b/DoraVota/doravota-starter/docker-compose.yml @@ -0,0 +1,66 @@ +version: "3" + +services: + postgres: + build: + context: . + dockerfile: ./docker/pg-Dockerfile + ports: + - 5432:5432 + volumes: + - .data/postgres:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + subquery-node: + image: subquerynetwork/subql-node-cosmos:latest + depends_on: + "postgres": + condition: service_healthy + restart: unless-stopped + environment: + DB_USER: postgres + DB_PASS: postgres + DB_DATABASE: postgres + DB_HOST: postgres + DB_PORT: 5432 + volumes: + - ./:/app + command: + - ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests + - -f=/app + - --db-schema=app + - --workers=4 + - --batch-size=30 + - --unfinalized-blocks=true + healthcheck: + test: ["CMD", "curl", "-f", "http://subquery-node:3000/ready"] + interval: 3s + timeout: 5s + retries: 10 + + graphql-engine: + image: subquerynetwork/subql-query:latest + ports: + - 3000:3000 + depends_on: + "postgres": + condition: service_healthy + "subquery-node": + condition: service_healthy + restart: always + environment: + DB_USER: postgres + DB_PASS: postgres + DB_DATABASE: postgres + DB_HOST: postgres + DB_PORT: 5432 + command: + - --name=app + - --playground + - --indexer=http://subquery-node:3000 diff --git a/DoraVota/doravota-starter/docker/load-extensions.sh b/DoraVota/doravota-starter/docker/load-extensions.sh new file mode 100644 index 000000000..6d33f8638 --- /dev/null +++ b/DoraVota/doravota-starter/docker/load-extensions.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <=3.0.0', + }, + query: { + name: '@subql/query', + version: '*', + }, + }, + schema: { + file: './schema.graphql', + }, + network: { + /* The unique chainID of the Cosmos Zone */ + chainId: 'vota-ash', + /** + * These endpoint(s) should be public non-pruned archive node + * We recommend providing more than one endpoint for improved reliability, performance, and uptime + * Public nodes may be rate limited, which can affect indexing speed + * When developing your project we suggest getting a private API key + * If you use a rate limited endpoint, adjust the --batch-size and --workers parameters + * These settings can be found in your docker-compose.yaml, they will slow indexing but prevent your project being rate limited + */ + endpoint: ['https://vota-rpc.dorafactory.org:443'], + }, + dataSources: [ + { + kind: CosmosDatasourceKind.Runtime, + startBlock: 4969400, + mapping: { + file: './dist/index.js', + handlers: [ + { + handler: 'handleEvent', + kind: CosmosHandlerKind.Event, + filter: { + type: 'execute', + messageFilter: { + type: '/cosmwasm.wasm.v1.MsgExecuteContract', + }, + }, + }, + { + handler: 'handleMessage', + kind: CosmosHandlerKind.Message, + filter: { + type: '/cosmwasm.wasm.v1.MsgExecuteContract', + }, + }, + ], + }, + }, + ], +}; + +// Must set default to the project instance +export default project; diff --git a/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/gogo.proto b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/gogo.proto new file mode 100644 index 000000000..8947d90aa --- /dev/null +++ b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/gogo.proto @@ -0,0 +1,144 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package gogoproto; + +import "google/protobuf/descriptor.proto"; + +option java_package = "com.google.protobuf"; +option java_outer_classname = "GoGoProtos"; +option go_package = "github.com/gogo/protobuf/gogoproto"; + +extend google.protobuf.EnumOptions { + optional bool goproto_enum_prefix = 62001; + optional bool goproto_enum_stringer = 62021; + optional bool enum_stringer = 62022; + optional string enum_customname = 62023; + optional bool enumdecl = 62024; +} + +extend google.protobuf.EnumValueOptions { + optional string enumvalue_customname = 66001; +} + +extend google.protobuf.FileOptions { + optional bool goproto_getters_all = 63001; + optional bool goproto_enum_prefix_all = 63002; + optional bool goproto_stringer_all = 63003; + optional bool verbose_equal_all = 63004; + optional bool face_all = 63005; + optional bool gostring_all = 63006; + optional bool populate_all = 63007; + optional bool stringer_all = 63008; + optional bool onlyone_all = 63009; + + optional bool equal_all = 63013; + optional bool description_all = 63014; + optional bool testgen_all = 63015; + optional bool benchgen_all = 63016; + optional bool marshaler_all = 63017; + optional bool unmarshaler_all = 63018; + optional bool stable_marshaler_all = 63019; + + optional bool sizer_all = 63020; + + optional bool goproto_enum_stringer_all = 63021; + optional bool enum_stringer_all = 63022; + + optional bool unsafe_marshaler_all = 63023; + optional bool unsafe_unmarshaler_all = 63024; + + optional bool goproto_extensions_map_all = 63025; + optional bool goproto_unrecognized_all = 63026; + optional bool gogoproto_import = 63027; + optional bool protosizer_all = 63028; + optional bool compare_all = 63029; + optional bool typedecl_all = 63030; + optional bool enumdecl_all = 63031; + + optional bool goproto_registration = 63032; + optional bool messagename_all = 63033; + + optional bool goproto_sizecache_all = 63034; + optional bool goproto_unkeyed_all = 63035; +} + +extend google.protobuf.MessageOptions { + optional bool goproto_getters = 64001; + optional bool goproto_stringer = 64003; + optional bool verbose_equal = 64004; + optional bool face = 64005; + optional bool gostring = 64006; + optional bool populate = 64007; + optional bool stringer = 67008; + optional bool onlyone = 64009; + + optional bool equal = 64013; + optional bool description = 64014; + optional bool testgen = 64015; + optional bool benchgen = 64016; + optional bool marshaler = 64017; + optional bool unmarshaler = 64018; + optional bool stable_marshaler = 64019; + + optional bool sizer = 64020; + + optional bool unsafe_marshaler = 64023; + optional bool unsafe_unmarshaler = 64024; + + optional bool goproto_extensions_map = 64025; + optional bool goproto_unrecognized = 64026; + + optional bool protosizer = 64028; + optional bool compare = 64029; + + optional bool typedecl = 64030; + + optional bool messagename = 64033; + + optional bool goproto_sizecache = 64034; + optional bool goproto_unkeyed = 64035; +} + +extend google.protobuf.FieldOptions { + optional bool nullable = 65001; + optional bool embed = 65002; + optional string customtype = 65003; + optional string customname = 65004; + optional string jsontag = 65005; + optional string moretags = 65006; + optional string casttype = 65007; + optional string castkey = 65008; + optional string castvalue = 65009; + + optional bool stdtime = 65010; + optional bool stdduration = 65011; + optional bool wktpointer = 65012; + +} \ No newline at end of file diff --git a/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/msg.proto b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/msg.proto new file mode 100644 index 000000000..89bdf3129 --- /dev/null +++ b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/msg.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +package cosmos.msg.v1; + +import "google/protobuf/descriptor.proto"; + +// TODO(fdymylja): once we fully migrate to protov2 the go_package needs to be updated. +// We need this right now because gogoproto codegen needs to import the extension. +option go_package = "github.com/cosmos/cosmos-sdk/types/msgservice"; + +extend google.protobuf.MessageOptions { + // signer must be used in cosmos messages in order + // to signal to external clients which fields in a + // given cosmos message must be filled with signer + // information (address). + // The field must be the protobuf name of the message + // field extended with this MessageOption. + // The field must either be of string kind, or of message + // kind in case the signer information is contained within + // a message inside the cosmos message. + repeated string signer = 11110000; +} \ No newline at end of file diff --git a/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/query.proto b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/query.proto new file mode 100644 index 000000000..bd1ee0c30 --- /dev/null +++ b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/query.proto @@ -0,0 +1,64 @@ +syntax = "proto3"; +package cosmos.slashing.v1beta1; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/slashing/v1beta1/slashing.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; + +// Query provides defines the gRPC querier service +service Query { + // Params queries the parameters of slashing module + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cosmos/slashing/v1beta1/params"; + } + + // SigningInfo queries the signing info of given cons address + rpc SigningInfo(QuerySigningInfoRequest) returns (QuerySigningInfoResponse) { + option (google.api.http).get = "/cosmos/slashing/v1beta1/signing_infos/{cons_address}"; + } + + // SigningInfos queries signing info of all validators + rpc SigningInfos(QuerySigningInfosRequest) returns (QuerySigningInfosResponse) { + option (google.api.http).get = "/cosmos/slashing/v1beta1/signing_infos"; + } +} + +// QueryParamsRequest is the request type for the Query/Params RPC method +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method +message QueryParamsResponse { + Params params = 1 [(gogoproto.nullable) = false]; +} + +// QuerySigningInfoRequest is the request type for the Query/SigningInfo RPC +// method +message QuerySigningInfoRequest { + // cons_address is the address to query signing info of + string cons_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// QuerySigningInfoResponse is the response type for the Query/SigningInfo RPC +// method +message QuerySigningInfoResponse { + // val_signing_info is the signing info of requested val cons address + ValidatorSigningInfo val_signing_info = 1 [(gogoproto.nullable) = false]; +} + +// QuerySigningInfosRequest is the request type for the Query/SigningInfos RPC +// method +message QuerySigningInfosRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QuerySigningInfosResponse is the response type for the Query/SigningInfos RPC +// method +message QuerySigningInfosResponse { + // info is the signing info of all validators + repeated cosmos.slashing.v1beta1.ValidatorSigningInfo info = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} \ No newline at end of file diff --git a/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/slashing.proto b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/slashing.proto new file mode 100644 index 000000000..081dc5abe --- /dev/null +++ b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/slashing.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; +package cosmos.slashing.v1beta1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; +option (gogoproto.equal_all) = true; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "cosmos_proto/cosmos.proto"; + +// ValidatorSigningInfo defines a validator's signing info for monitoring their +// liveness activity. +message ValidatorSigningInfo { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // Height at which validator was first a candidate OR was unjailed + int64 start_height = 2; + // Index which is incremented each time the validator was a bonded + // in a block and may have signed a precommit or not. This in conjunction with the + // `SignedBlocksWindow` param determines the index in the `MissedBlocksBitArray`. + int64 index_offset = 3; + // Timestamp until which the validator is jailed due to liveness downtime. + google.protobuf.Timestamp jailed_until = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + // Whether or not a validator has been tombstoned (killed out of validator set). It is set + // once the validator commits an equivocation or for any other configured misbehiavor. + bool tombstoned = 5; + // A counter kept to avoid unnecessary array reads. + // Note that `Sum(MissedBlocksBitArray)` always equals `MissedBlocksCounter`. + int64 missed_blocks_counter = 6; +} + +// Params represents the parameters used for by the slashing module. +message Params { + int64 signed_blocks_window = 1; + bytes min_signed_per_window = 2 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + google.protobuf.Duration downtime_jail_duration = 3 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; + bytes slash_fraction_double_sign = 4 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + bytes slash_fraction_downtime = 5 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; +} \ No newline at end of file diff --git a/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/tx.proto b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/tx.proto new file mode 100644 index 000000000..12595a67a --- /dev/null +++ b/DoraVota/doravota-starter/proto/cosmos/slashing/v1beta1/tx.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package cosmos.slashing.v1beta1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; +option (gogoproto.equal_all) = true; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; + +// Msg defines the slashing Msg service. +service Msg { + // Unjail defines a method for unjailing a jailed validator, thus returning + // them into the bonded validator set, so they can begin receiving provisions + // and rewards again. + rpc Unjail(MsgUnjail) returns (MsgUnjailResponse); +} + +// MsgUnjail defines the Msg/Unjail request type +message MsgUnjail { + option (cosmos.msg.v1.signer) = "validator_addr"; + + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = true; + + string validator_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString", (gogoproto.jsontag) = "address"]; +} + +// MsgUnjailResponse defines the Msg/Unjail response type +message MsgUnjailResponse {} \ No newline at end of file diff --git a/DoraVota/doravota-starter/schema.graphql b/DoraVota/doravota-starter/schema.graphql new file mode 100644 index 000000000..b381564a6 --- /dev/null +++ b/DoraVota/doravota-starter/schema.graphql @@ -0,0 +1,29 @@ +# To improve query performance, we strongly suggest adding indexes to any field that you plan to filter or sort by +# Add the `@index` or `@index(unique: true)` annotation after any non-key field +# https://academy.subquery.network/build/graphql.html#indexing-by-non-primary-key-field + +# type Block @entity { +# id: ID! # The block hash +# height: BigInt! +# } + +# type Transaction @entity { +# id: ID! +# blockHeight: BigInt! +# timestamp: String! +# } + +type ExecuteEvent @entity { + id: ID! + blockHeight: BigInt! + txHash: String! + contractAddress: String! +} + +type Message @entity { + id: ID! + blockHeight: BigInt! + txHash: String! + sender: String! + contract: String! +} diff --git a/DoraVota/doravota-starter/src/index.ts b/DoraVota/doravota-starter/src/index.ts new file mode 100644 index 000000000..fb59776f0 --- /dev/null +++ b/DoraVota/doravota-starter/src/index.ts @@ -0,0 +1,2 @@ +//Exports all handler functions +export * from "./mappings/mappingHandlers"; diff --git a/DoraVota/doravota-starter/src/mappings/mappingHandlers.ts b/DoraVota/doravota-starter/src/mappings/mappingHandlers.ts new file mode 100644 index 000000000..01886246b --- /dev/null +++ b/DoraVota/doravota-starter/src/mappings/mappingHandlers.ts @@ -0,0 +1,48 @@ +import { ExecuteEvent, Message } from '../types'; +import { + CosmosEvent, + CosmosBlock, + CosmosMessage, + CosmosTransaction, +} from '@subql/types-cosmos'; + +/* +export async function handleBlock(block: CosmosBlock): Promise { + // If you want to index each block in Cosmos (DoraVota), you could do that here +} + +export async function handleTransaction(tx: CosmosTransaction): Promise { + // If you want to index each transaction in Cosmos (DoraVota), you could do that here + const transactionRecord = Transaction.create({ + id: tx.hash, + blockHeight: BigInt(tx.block.block.header.height), + timestamp: tx.block.block.header.time, + }); + await transactionRecord.save(); +} +*/ + +export async function handleMessage(msg: CosmosMessage): Promise { + const messageRecord = Message.create({ + id: `${msg.tx.hash}-${msg.idx}`, + blockHeight: BigInt(msg.block.block.header.height), + txHash: msg.tx.hash, + sender: msg.msg.decodedMsg.sender, + contract: msg.msg.decodedMsg.contract, + }); + await messageRecord.save(); +} + +export async function handleEvent(event: CosmosEvent): Promise { + const eventRecord = ExecuteEvent.create({ + id: `${event.tx.hash}-${event.msg.idx}-${event.idx}`, + blockHeight: BigInt(event.block.block.header.height), + txHash: event.tx.hash, + contractAddress: + event.event.attributes.find( + attr => attr.key === '_contract_address' + )?.value ?? '', + }); + + await eventRecord.save(); +} diff --git a/DoraVota/doravota-starter/src/test/mappingHandlers.test.ts b/DoraVota/doravota-starter/src/test/mappingHandlers.test.ts new file mode 100644 index 000000000..42f41c3fb --- /dev/null +++ b/DoraVota/doravota-starter/src/test/mappingHandlers.test.ts @@ -0,0 +1,12 @@ +import { subqlTest } from "@subql/testing"; + +/* +// https://academy.subquery.network/build/testing.html +subqlTest( + "testName", // test name + 1000003, // block height to process + [], // dependent entities + [], // expected entities + "handleEvent" //handler name +); +*/ diff --git a/DoraVota/doravota-starter/tsconfig.json b/DoraVota/doravota-starter/tsconfig.json new file mode 100644 index 000000000..f3019d720 --- /dev/null +++ b/DoraVota/doravota-starter/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "declaration": true, + "importHelpers": true, + "resolveJsonModule": true, + "module": "commonjs", + "outDir": "dist", + "rootDir": "src", + "target": "es2017", + "strict": true + }, + "include": [ + "src/**/*", + "node_modules/@subql/types-core/dist/global.d.ts", + "node_modules/@subql/types-cosmos/dist/global.d.ts" + ] +}