From bbf81acdfe930cd0f0100e01e5081efd6b3294bb Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Mon, 7 Oct 2024 22:46:29 +0200 Subject: [PATCH] clean code --- gno_github_agent/.env | 3 +- gno_github_agent/clientql/client.go | 63 ++- gno_github_agent/db/db.go | 19 +- gno_github_agent/gnoindexerql/gnoindexerQL.go | 493 +----------------- .../gnoindexerql/indexer-operations.graphql | 41 +- gno_github_agent/main.go | 5 +- 6 files changed, 69 insertions(+), 555 deletions(-) diff --git a/gno_github_agent/.env b/gno_github_agent/.env index a9db2a93fb..4d48a6b1ce 100644 --- a/gno_github_agent/.env +++ b/gno_github_agent/.env @@ -1,4 +1,5 @@ GNO_MNEMONIC=scissors razor beauty delay derive chronic toss burger gravity shallow couch slogan change tray connect frame token slight zone usage sad monkey pyramid change GNO_CHAIN_ID=dev GNO_RPC_ADDR=http://127.0.0.1:26657 -GNO_REALM_PATH=gno.land/r/teritori/ghverify \ No newline at end of file +GNO_REALM_PATH=gno.land/r/teritori/ghverify +GNO_TX_INDEXER=http://localhost:8546/graphql/query \ No newline at end of file diff --git a/gno_github_agent/clientql/client.go b/gno_github_agent/clientql/client.go index 404d9779a3..de40e902bb 100644 --- a/gno_github_agent/clientql/client.go +++ b/gno_github_agent/clientql/client.go @@ -2,6 +2,7 @@ package clientql import ( "context" + "errors" "fmt" "io" "net/http" @@ -17,24 +18,25 @@ import ( ) type IndexerQL struct { - gqlClient graphql.Client - db *gorm.DB - logger *zap.SugaredLogger - signer *signer.Signer + gqlClient graphql.Client + db *gorm.DB + logger *zap.SugaredLogger + signer *signer.Signer + verifyRealmPath string } -func New(graphqlEndpoint string, db *gorm.DB, logger *zap.SugaredLogger, gnoSigner *signer.Signer) *IndexerQL { +func New(graphqlEndpoint string, db *gorm.DB, logger *zap.SugaredLogger, gnoSigner *signer.Signer, verifyRealmPath string) *IndexerQL { gqlClient := graphql.NewClient(graphqlEndpoint, nil) - return &IndexerQL{gqlClient: gqlClient, db: db, logger: logger, signer: gnoSigner} + return &IndexerQL{gqlClient: gqlClient, db: db, logger: logger, signer: gnoSigner, verifyRealmPath: verifyRealmPath} } func (client *IndexerQL) DealWithVerifications() error { - lastBlock, err := getLastTreatedBlock() + lastBlock, err := client.getLastTreatedBlock() if err != nil { return err } - validationRequests, err := gnoindexerql.GetValidationRequests(context.Background(), client.gqlClient, lastBlock) + validationRequests, err := gnoindexerql.GetValidationRequests(context.Background(), client.gqlClient, lastBlock, client.verifyRealmPath) if err != nil { return err } @@ -45,7 +47,8 @@ func (client *IndexerQL) DealWithVerifications() error { switch event := responseEvent.(type) { case *gnoindexerql.GetValidationRequestsTransactionsTransactionResponseEventsGnoEvent: client.logger.Infof("args %v\n", event.Attrs) - err := client.dealWithVerification(event) + + err := client.dealWithVerification(event, validationRequest.Block_height) if err != nil { client.logger.Errorf("failed to deal with verification: %s", err.Error()) continue @@ -60,11 +63,21 @@ func (client *IndexerQL) DealWithVerifications() error { return nil } -func getLastTreatedBlock() (int, error) { - return 0, nil +func (client *IndexerQL) getLastTreatedBlock() (int, error) { + var verification db.Verification + err := client.db.Model(&db.Verification{}).Where("status = ?", string(db.VerificationStatusVerified)).Order("id desc").First(&verification).Error + + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return 0, nil + } + + return 0, nil + } + return verification.BlockHeight, err } -func (client *IndexerQL) dealWithVerification(event *gnoindexerql.GetValidationRequestsTransactionsTransactionResponseEventsGnoEvent) error { +func (client *IndexerQL) dealWithVerification(event *gnoindexerql.GetValidationRequestsTransactionsTransactionResponseEventsGnoEvent, blockHeight int) error { var handle string var callerAddress string for _, attr := range event.Attrs { @@ -75,6 +88,7 @@ func (client *IndexerQL) dealWithVerification(event *gnoindexerql.GetValidationR callerAddress = attr.Value } } + var verification db.Verification err := client.db.Model(&db.Verification{}).Where("handle = ? AND address = ?", handle, callerAddress).Find(&verification).Error if err != nil { @@ -92,17 +106,17 @@ func (client *IndexerQL) dealWithVerification(event *gnoindexerql.GetValidationR return err } - client.logger.Infof("Get\n") defer res.Body.Close() if res.StatusCode != 200 { - return client.updateVerification(handle, callerAddress, "config_not_found") + return client.updateVerification(handle, callerAddress, db.VerificationStatusConfigNotFound, blockHeight) } + data, err := io.ReadAll(res.Body) if err != nil { - client.updateVerification(handle, callerAddress, "invalid_data") + client.updateVerification(handle, callerAddress, db.VerificationStatusInvalidData, blockHeight) return err } - client.logger.Infof("config.yml: %s\n", string(data)) + githubConfiguredAddress := strings.TrimSpace(string(data)) if githubConfiguredAddress == callerAddress { err = client.signer.CallVerify(githubConfiguredAddress) @@ -110,18 +124,19 @@ func (client *IndexerQL) dealWithVerification(event *gnoindexerql.GetValidationR return err } - return client.updateVerification(handle, callerAddress, "verified") + return client.updateVerification(handle, callerAddress, db.VerificationStatusVerified, blockHeight) } - return client.updateVerification(handle, callerAddress, "caller_address_mismatch") + return client.updateVerification(handle, callerAddress, db.VerificationStatusCallerAddressMismatch, blockHeight) } -func (client *IndexerQL) updateVerification(handle, address, status string) error { +func (client *IndexerQL) updateVerification(handle, address string, status db.VerificationStatus, blockHeight int) error { verification := db.Verification{ - Handle: handle, - Address: address, - Status: status, - CreatedAt: time.Now().Format("2006-01-02 15:04:05"), + Handle: handle, + Address: address, + Status: string(status), + CreatedAt: time.Now().Format("2006-01-02 15:04:05"), + BlockHeight: blockHeight, } - return client.db.Model(&verification).Where("handle = ? AND address = ?", handle, address).Assign(db.Verification{Status: status}).FirstOrCreate(&verification).Error + return client.db.Model(&verification).Where("handle = ? AND address = ?", handle, address).Assign(db.Verification{Status: string(status)}).FirstOrCreate(&verification).Error } diff --git a/gno_github_agent/db/db.go b/gno_github_agent/db/db.go index 1a766e1ce8..6e2a9a51fd 100644 --- a/gno_github_agent/db/db.go +++ b/gno_github_agent/db/db.go @@ -29,8 +29,19 @@ type Verification struct { gorm.Model Id uint `json:"id" gorm:"unique;primaryKey;autoIncrement"` - Handle string - Address string - Status string - CreatedAt string + Handle string + Address string + Status string + CreatedAt string + BlockHeight int } + +type VerificationStatus string + +const ( + VerificationStatusUnverified VerificationStatus = "unverified" + VerificationStatusVerified VerificationStatus = "verified" + VerificationStatusConfigNotFound VerificationStatus = "config_not_found" + VerificationStatusInvalidData VerificationStatus = "invalid_data" + VerificationStatusCallerAddressMismatch VerificationStatus = "caller_address_mismatch" +) diff --git a/gno_github_agent/gnoindexerql/gnoindexerQL.go b/gno_github_agent/gnoindexerql/gnoindexerQL.go index 707252df71..0663e998ef 100644 --- a/gno_github_agent/gnoindexerql/gnoindexerQL.go +++ b/gno_github_agent/gnoindexerql/gnoindexerQL.go @@ -10,418 +10,6 @@ import ( "github.com/Khan/genqlient/graphql" ) -// GetPostTransactionsResponse is returned by GetPostTransactions on success. -type GetPostTransactionsResponse struct { - // Retrieves a list of Transactions that match the given filter criteria. If the result is incomplete due to errors, both partial results and errors are returned. - Transactions []GetPostTransactionsTransactionsTransaction `json:"transactions"` -} - -// GetTransactions returns GetPostTransactionsResponse.Transactions, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsResponse) GetTransactions() []GetPostTransactionsTransactionsTransaction { - return v.Transactions -} - -// GetPostTransactionsTransactionsTransaction includes the requested fields of the GraphQL type Transaction. -// The GraphQL type's documentation follows. -// -// Defines a transaction within a block, detailing its execution specifics and content. -type GetPostTransactionsTransactionsTransaction struct { - // A sequential index representing the order of this Transaction within its Block. Unique within the context of its Block. - Index int `json:"index"` - // Hash from Transaction content in base64 encoding. - Hash string `json:"hash"` - // The success can determine whether the transaction succeeded or failed. - Success bool `json:"success"` - // The height of the Block in which this Transaction is included. Links the Transaction to its containing Block. - Block_height int `json:"block_height"` - // The declared amount of computational effort the sender is willing to pay for executing this Transaction. - Gas_wanted int `json:"gas_wanted"` - // The actual amount of computational effort consumed to execute this Transaction. It could be less or equal to `gas_wanted`. - Gas_used int `json:"gas_used"` - // `memo` are string information stored within a transaction. - // `memo` can be utilized to find or distinguish transactions. - // For example, when trading a specific exchange, you would utilize the memo field of the transaction. - Memo string `json:"memo"` - // The payload of a message shows the contents of the messages in a transaction. - // A message consists of `router`, `type`, and `value` (whose form depends on the `router` and `type`). - Messages []GetPostTransactionsTransactionsTransactionMessagesTransactionMessage `json:"messages"` - // `response` is the processing result of the transaction. - // It has `log`, `info`, `error`, and `data`. - Response GetPostTransactionsTransactionsTransactionResponse `json:"response"` -} - -// GetIndex returns GetPostTransactionsTransactionsTransaction.Index, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetIndex() int { return v.Index } - -// GetHash returns GetPostTransactionsTransactionsTransaction.Hash, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetHash() string { return v.Hash } - -// GetSuccess returns GetPostTransactionsTransactionsTransaction.Success, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetSuccess() bool { return v.Success } - -// GetBlock_height returns GetPostTransactionsTransactionsTransaction.Block_height, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetBlock_height() int { return v.Block_height } - -// GetGas_wanted returns GetPostTransactionsTransactionsTransaction.Gas_wanted, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetGas_wanted() int { return v.Gas_wanted } - -// GetGas_used returns GetPostTransactionsTransactionsTransaction.Gas_used, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetGas_used() int { return v.Gas_used } - -// GetMemo returns GetPostTransactionsTransactionsTransaction.Memo, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetMemo() string { return v.Memo } - -// GetMessages returns GetPostTransactionsTransactionsTransaction.Messages, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetMessages() []GetPostTransactionsTransactionsTransactionMessagesTransactionMessage { - return v.Messages -} - -// GetResponse returns GetPostTransactionsTransactionsTransaction.Response, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransaction) GetResponse() GetPostTransactionsTransactionsTransactionResponse { - return v.Response -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessage includes the requested fields of the GraphQL type TransactionMessage. -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessage struct { - // The type of transaction message. - // The value of `typeUrl` can be `send`, `exec`, `add_package`, `run`. - TypeUrl string `json:"typeUrl"` - // The route of transaction message. - // The value of `route` can be `bank`, `vm`. - Route string `json:"route"` - // MessageValue is the content of the transaction. - // `value` can be of type `BankMsgSend`, `MsgCall`, `MsgAddPackage`, `MsgRun`, `UnexpectedMessage`. - Value GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue `json:"-"` -} - -// GetTypeUrl returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessage.TypeUrl, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage) GetTypeUrl() string { - return v.TypeUrl -} - -// GetRoute returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessage.Route, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage) GetRoute() string { - return v.Route -} - -// GetValue returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessage.Value, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage) GetValue() GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue { - return v.Value -} - -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage) UnmarshalJSON(b []byte) error { - - if string(b) == "null" { - return nil - } - - var firstPass struct { - *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage - Value json.RawMessage `json:"value"` - graphql.NoUnmarshalJSON - } - firstPass.GetPostTransactionsTransactionsTransactionMessagesTransactionMessage = v - - err := json.Unmarshal(b, &firstPass) - if err != nil { - return err - } - - { - dst := &v.Value - src := firstPass.Value - if len(src) != 0 && string(src) != "null" { - err = __unmarshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue( - src, dst) - if err != nil { - return fmt.Errorf( - "unable to unmarshal GetPostTransactionsTransactionsTransactionMessagesTransactionMessage.Value: %w", err) - } - } - } - return nil -} - -type __premarshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessage struct { - TypeUrl string `json:"typeUrl"` - - Route string `json:"route"` - - Value json.RawMessage `json:"value"` -} - -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage) MarshalJSON() ([]byte, error) { - premarshaled, err := v.__premarshalJSON() - if err != nil { - return nil, err - } - return json.Marshal(premarshaled) -} - -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessage) __premarshalJSON() (*__premarshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessage, error) { - var retval __premarshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessage - - retval.TypeUrl = v.TypeUrl - retval.Route = v.Route - { - - dst := &retval.Value - src := v.Value - var err error - *dst, err = __marshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue( - &src) - if err != nil { - return nil, fmt.Errorf( - "unable to marshal GetPostTransactionsTransactionsTransactionMessagesTransactionMessage.Value: %w", err) - } - } - return &retval, nil -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue includes the requested fields of the GraphQL interface MessageValue. -// -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue is implemented by the following types: -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue interface { - implementsGraphQLInterfaceGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue() - // GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values). - GetTypename() string -} - -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend) implementsGraphQLInterfaceGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue() { -} -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage) implementsGraphQLInterfaceGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue() { -} -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) implementsGraphQLInterfaceGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue() { -} -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun) implementsGraphQLInterfaceGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue() { -} -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage) implementsGraphQLInterfaceGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue() { -} - -func __unmarshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue(b []byte, v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue) error { - if string(b) == "null" { - return nil - } - - var tn struct { - TypeName string `json:"__typename"` - } - err := json.Unmarshal(b, &tn) - if err != nil { - return err - } - - switch tn.TypeName { - case "BankMsgSend": - *v = new(GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend) - return json.Unmarshal(b, *v) - case "MsgAddPackage": - *v = new(GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage) - return json.Unmarshal(b, *v) - case "MsgCall": - *v = new(GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) - return json.Unmarshal(b, *v) - case "MsgRun": - *v = new(GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun) - return json.Unmarshal(b, *v) - case "UnexpectedMessage": - *v = new(GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage) - return json.Unmarshal(b, *v) - case "": - return fmt.Errorf( - "response was missing MessageValue.__typename") - default: - return fmt.Errorf( - `unexpected concrete type for GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue: "%v"`, tn.TypeName) - } -} - -func __marshalGetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue(v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue) ([]byte, error) { - - var typename string - switch v := (*v).(type) { - case *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend: - typename = "BankMsgSend" - - result := struct { - TypeName string `json:"__typename"` - *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend - }{typename, v} - return json.Marshal(result) - case *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage: - typename = "MsgAddPackage" - - result := struct { - TypeName string `json:"__typename"` - *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage - }{typename, v} - return json.Marshal(result) - case *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall: - typename = "MsgCall" - - result := struct { - TypeName string `json:"__typename"` - *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall - }{typename, v} - return json.Marshal(result) - case *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun: - typename = "MsgRun" - - result := struct { - TypeName string `json:"__typename"` - *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun - }{typename, v} - return json.Marshal(result) - case *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage: - typename = "UnexpectedMessage" - - result := struct { - TypeName string `json:"__typename"` - *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage - }{typename, v} - return json.Marshal(result) - case nil: - return []byte("null"), nil - default: - return nil, fmt.Errorf( - `unexpected concrete type for GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValue: "%T"`, v) - } -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend includes the requested fields of the GraphQL type BankMsgSend. -// The GraphQL type's documentation follows. -// -// `BankMsgSend` is a message with a message router of `bank` and a message type of `send`. -// `BankMsgSend` is the fund transfer tx message. -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend struct { - Typename string `json:"__typename"` -} - -// GetTypename returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend.Typename, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueBankMsgSend) GetTypename() string { - return v.Typename -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage includes the requested fields of the GraphQL type MsgAddPackage. -// The GraphQL type's documentation follows. -// -// `MsgAddPackage` is a message with a message router of `vm` and a message type of `add_package`. -// `MsgAddPackage` is the package deployment tx message. -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage struct { - Typename string `json:"__typename"` -} - -// GetTypename returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage.Typename, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgAddPackage) GetTypename() string { - return v.Typename -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall includes the requested fields of the GraphQL type MsgCall. -// The GraphQL type's documentation follows. -// -// `MsgCall` is a message with a message router of `vm` and a message type of `exec`. -// `MsgCall` is the method invocation tx message. -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall struct { - Typename string `json:"__typename"` - // the bech32 address of the function caller. - // ex) `g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5` - Caller string `json:"caller"` - // the amount of funds to be deposited to the package, if any (""). - // ex) `1000000ugnot` - Send string `json:"send"` - // the gno package path. - Pkg_path string `json:"pkg_path"` - // the function name being invoked. - Func string `json:"func"` - // `args` are the arguments passed to the executed function. - Args []string `json:"args"` -} - -// GetTypename returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall.Typename, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) GetTypename() string { - return v.Typename -} - -// GetCaller returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall.Caller, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) GetCaller() string { - return v.Caller -} - -// GetSend returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall.Send, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) GetSend() string { - return v.Send -} - -// GetPkg_path returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall.Pkg_path, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) GetPkg_path() string { - return v.Pkg_path -} - -// GetFunc returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall.Func, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) GetFunc() string { - return v.Func -} - -// GetArgs returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall.Args, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgCall) GetArgs() []string { - return v.Args -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun includes the requested fields of the GraphQL type MsgRun. -// The GraphQL type's documentation follows. -// -// `MsgRun` is a message with a message router of `vm` and a message type of `run`. -// `MsgRun is the execute arbitrary Gno code tx message`. -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun struct { - Typename string `json:"__typename"` -} - -// GetTypename returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun.Typename, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueMsgRun) GetTypename() string { - return v.Typename -} - -// GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage includes the requested fields of the GraphQL type UnexpectedMessage. -// The GraphQL type's documentation follows. -// -// `UnexpectedMessage` is an Undefined Message, which is a message that decoding failed. -type GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage struct { - Typename string `json:"__typename"` -} - -// GetTypename returns GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage.Typename, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionMessagesTransactionMessageValueUnexpectedMessage) GetTypename() string { - return v.Typename -} - -// GetPostTransactionsTransactionsTransactionResponse includes the requested fields of the GraphQL type TransactionResponse. -// The GraphQL type's documentation follows. -// -// `TransactionResponse` is the processing result of the transaction. -// It has `log`, `info`, `error`, and `data`. -type GetPostTransactionsTransactionsTransactionResponse struct { - // The response data associated with the Transaction execution, if any. - Data string `json:"data"` - // The Info associated with the Transaction execution, if any. - Info string `json:"info"` - // The log value associated with the Transaction execution, if any. - Log string `json:"log"` -} - -// GetData returns GetPostTransactionsTransactionsTransactionResponse.Data, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionResponse) GetData() string { return v.Data } - -// GetInfo returns GetPostTransactionsTransactionsTransactionResponse.Info, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionResponse) GetInfo() string { return v.Info } - -// GetLog returns GetPostTransactionsTransactionsTransactionResponse.Log, and is useful for accessing the field via an interface. -func (v *GetPostTransactionsTransactionsTransactionResponse) GetLog() string { return v.Log } - // GetValidationRequestsResponse is returned by GetValidationRequests on success. type GetValidationRequestsResponse struct { // Retrieves a list of Transactions that match the given filter criteria. If the result is incomplete due to errors, both partial results and errors are returned. @@ -699,95 +287,29 @@ func (v *GetValidationRequestsTransactionsTransactionResponseEventsUnknownEvent) return v.Typename } -// __GetPostTransactionsInput is used internally by genqlient -type __GetPostTransactionsInput struct { - StartBlock int `json:"StartBlock"` - PkgPath string `json:"PkgPath"` -} - -// GetStartBlock returns __GetPostTransactionsInput.StartBlock, and is useful for accessing the field via an interface. -func (v *__GetPostTransactionsInput) GetStartBlock() int { return v.StartBlock } - -// GetPkgPath returns __GetPostTransactionsInput.PkgPath, and is useful for accessing the field via an interface. -func (v *__GetPostTransactionsInput) GetPkgPath() string { return v.PkgPath } - // __GetValidationRequestsInput is used internally by genqlient type __GetValidationRequestsInput struct { - StartBlock int `json:"StartBlock"` + StartBlock int `json:"StartBlock"` + RealmPath string `json:"realmPath"` } // GetStartBlock returns __GetValidationRequestsInput.StartBlock, and is useful for accessing the field via an interface. func (v *__GetValidationRequestsInput) GetStartBlock() int { return v.StartBlock } -func GetPostTransactions( - ctx context.Context, - client graphql.Client, - StartBlock int, - PkgPath string, -) (*GetPostTransactionsResponse, error) { - req := &graphql.Request{ - OpName: "GetPostTransactions", - Query: ` -query GetPostTransactions ($StartBlock: Int!, $PkgPath: String!) { - transactions(filter: {success:true,messages:{vm_param:{exec:{func:"CreatePost",pkg_path:$PkgPath}}},from_block_height:$StartBlock}) { - index - hash - success - block_height - gas_wanted - gas_used - memo - messages { - typeUrl - route - value { - __typename - ... on MsgCall { - caller - send - pkg_path - func - args - } - } - } - response { - data - info - log - } - } -} -`, - Variables: &__GetPostTransactionsInput{ - StartBlock: StartBlock, - PkgPath: PkgPath, - }, - } - var err error - - var data GetPostTransactionsResponse - resp := &graphql.Response{Data: &data} - - err = client.MakeRequest( - ctx, - req, - resp, - ) - - return &data, err -} +// GetRealmPath returns __GetValidationRequestsInput.RealmPath, and is useful for accessing the field via an interface. +func (v *__GetValidationRequestsInput) GetRealmPath() string { return v.RealmPath } func GetValidationRequests( ctx context.Context, client graphql.Client, StartBlock int, + realmPath string, ) (*GetValidationRequestsResponse, error) { req := &graphql.Request{ OpName: "GetValidationRequests", Query: ` -query GetValidationRequests ($StartBlock: Int!) { - transactions(filter: {events:{type:"verification_requested",pkg_path:"gno.land/r/teritori/ghverify"},from_block_height:$StartBlock}) { +query GetValidationRequests ($StartBlock: Int!, $realmPath: String!) { + transactions(filter: {events:{type:"verification_requested",pkg_path:$realmPath},from_block_height:$StartBlock}) { success block_height response { @@ -809,6 +331,7 @@ query GetValidationRequests ($StartBlock: Int!) { `, Variables: &__GetValidationRequestsInput{ StartBlock: StartBlock, + RealmPath: realmPath, }, } var err error diff --git a/gno_github_agent/gnoindexerql/indexer-operations.graphql b/gno_github_agent/gnoindexerql/indexer-operations.graphql index 0d434fc288..0c809b5522 100644 --- a/gno_github_agent/gnoindexerql/indexer-operations.graphql +++ b/gno_github_agent/gnoindexerql/indexer-operations.graphql @@ -1,47 +1,10 @@ -query GetPostTransactions($StartBlock: Int!, $PkgPath: String!) { - transactions( - filter: { - success: true - messages: { - vm_param: { exec: { func: "CreatePost", pkg_path: $PkgPath } } - } - from_block_height: $StartBlock - } - ) { - index - hash - success - block_height - gas_wanted - gas_used - memo - messages { - typeUrl - route - value { - ... on MsgCall { - caller - send - pkg_path - func - args - } - } - } - response { - data - info - log - } - } -} - query GetValidationRequests( $StartBlock: Int! + $realmPath: String! ) { transactions( filter: { - events: {type:"verification_requested", pkg_path:"gno.land/r/teritori/ghverify"}, + events: {type:"verification_requested", pkg_path: $realmPath}, from_block_height: $StartBlock } ){ diff --git a/gno_github_agent/main.go b/gno_github_agent/main.go index d84e02fbd5..f97c598b9d 100644 --- a/gno_github_agent/main.go +++ b/gno_github_agent/main.go @@ -34,16 +34,17 @@ func main() { chainID := os.Getenv("GNO_CHAIN_ID") rpcAddr := os.Getenv("GNO_RPC_ADDR") realmPath := os.Getenv("GNO_REALM_PATH") + txIndexerHost := os.Getenv("GNO_TX_INDEXER") gnoSigner = signer.New(db, logger.Sugar(), mnemonic, chainID, rpcAddr, realmPath) - clientql := clientql.New("http://localhost:8546/graphql/query", db, logger.Sugar(), gnoSigner) + clientql := clientql.New(txIndexerHost, db, logger.Sugar(), gnoSigner, realmPath) schedule := gocron.NewScheduler(time.UTC) schedule.Every(30).Seconds().Do(func() { err = clientql.DealWithVerifications() if err != nil { - logger.Error("failed to get names list", zap.Error(err)) + logger.Error("failed to deal with verifications", zap.Error(err)) panic(err) } })