Skip to content

Commit

Permalink
feat(logic): specify logic query operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jan 2, 2023
1 parent d1396bb commit 8b385e0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 15 deletions.
16 changes: 7 additions & 9 deletions proto/logic/v1beta/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option go_package = "github.com/okp4/okp4d/x/logic/types";
message Params {
option (gogoproto.goproto_stringer) = false;

// Specify the parameter for the logic interpreter.
// Interpreter specifies the parameter for the logic interpreter.
Interpreter interpreter = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"interpreter\""
Expand All @@ -23,39 +23,37 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"limits\""
];

}

// Limits defines the limits of the logic module.
message Limits {
option (gogoproto.goproto_stringer) = true;

// The maximum amount of computing power, measured in "gas," that is allowed to be consumed when executing a request
// by the interpreter is specified here. The interpreter calculates the gas consumption based on the number and type
// max_gas specifies the maximum amount of computing power, measured in "gas," that is allowed to be consumed when
// executing a request by the interpreter. The interpreter calculates the gas consumption based on the number and type
// of operations that are executed, as well as, in some cases, the complexity of the processed data.
uint64 max_gas = 1 [(gogoproto.moretags) = "yaml:\"max_gas\",omitempty"];

// Specify the maximum size, in bytes, that is accepted for a program.
// max_size specifies the maximum size, in bytes, that is accepted for a program.
uint32 max_size = 3 [(gogoproto.moretags) = "yaml:\"max_size\""];

// Specify the maximum number of results that can be requested for a query.
// max_result_count specifies the maximum number of results that can be requested for a query.
uint32 max_result_count = 2 [(gogoproto.moretags) = "yaml:\"max_result_count\""];

}

// Interpreter defines the various parameters for the interpreter.
message Interpreter {
option (gogoproto.goproto_stringer) = true;

// Specify the list of registered predicates/operators, in the form of: `<predicate_name>/<arity>`.
// registered_predicates specifies the list of registered predicates/operators, in the form of: `<predicate_name>/<arity>`.
// For instance: `findall/3`.
// If not specified, the default set of predicates/operators will be registered.
repeated string registered_predicates = 1 [
(gogoproto.nullable) = true,
(gogoproto.moretags) = "yaml:\"registered_predicates\""
];

// Specify the initial program to run when booting the logic interpreter.
// bootstrap specifies the initial program to run when booting the logic interpreter.
// If not specified, the default boot sequence will be executed.
string bootstrap = 2 [
(gogoproto.nullable) = true,
Expand Down
37 changes: 35 additions & 2 deletions proto/logic/v1beta/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ package logic.v1beta;
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "logic/v1beta/params.proto";
import "logic/v1beta/types.proto";

option go_package = "github.com/okp4/okp4d/x/logic/types";

// QueryService defines the gRPC querier service.
service QueryService {
// Parameters queries the parameters of the module.
// Params queries all parameters for the logic module.
rpc Params(QueryServiceParamsRequest) returns (QueryServiceParamsResponse) {
option (google.api.http).get = "/okp4/okp4d/logic/params";
}

// Query executes a logic query and returns the solutions found.
// Since the query is without any side-effect, the query is not executed in the context of a transaction and no fee
// is charged for this, but the execution is constrained by the current limits configured in the module.
rpc Query(QueryServiceQueryRequest) returns (QueryServiceQueryResponse) {
option (google.api.http).get = "/okp4/okp4d/logic/query";
}
}

// QueryServiceParamsRequest is request type for the QueryService/Params RPC method.
Expand All @@ -22,5 +30,30 @@ message QueryServiceParamsRequest {}
// QueryServiceParamsResponse is response type for the QueryService/Params RPC method.
message QueryServiceParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
Params params = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"params\",omitempty"
];
}

// QueryServiceQueryRequest is request type for the QueryService/Query RPC method.
message QueryServiceQueryRequest {
option (gogoproto.goproto_stringer) = true;

// program is the logic program to be queried.
string program = 1 [(gogoproto.moretags) = "yaml:\"program\",omitempty"];
// query is the query string to be executed.
string query = 2 [(gogoproto.moretags) = "yaml:\"query\",omitempty"];
}

// QueryServiceQueryResponse is response type for the QueryService/Query RPC method.
message QueryServiceQueryResponse {
option (gogoproto.goproto_stringer) = true;

// height is the block height at which the query was executed.
uint64 height = 1 [(gogoproto.moretags) = "yaml:\"height\",omitempty"];
// gas_used is the amount of gas used to execute the query.
uint64 gas_used = 2 [(gogoproto.moretags) = "yaml:\"gas_used\",omitempty"];
// answer is the answer to the query.
Answer answer = 3 [(gogoproto.moretags) = "yaml:\"answer\",omitempty"];
}
7 changes: 3 additions & 4 deletions proto/logic/v1beta/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ syntax = "proto3";

package logic.v1beta;

import "gogoproto/gogo.proto";

option go_package = "github.com/okp4/okp4d/x/logic/types";

service MsgService {
}
// MsgService defines the service for the logic module.
// Do nothing for now as the service is without any side effects.
service MsgService {}
64 changes: 64 additions & 0 deletions proto/logic/v1beta/types.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
syntax = "proto3";

package logic.v1beta;

import "gogoproto/gogo.proto";

option go_package = "github.com/okp4/okp4d/x/logic/types";

// Term is the representation of a piece of data and can be a constant, a variable, or an atom.
message Term {
option (gogoproto.goproto_stringer) = true;

// name is the name of the term.
string name = 1 [(gogoproto.moretags) = "yaml:\"name\",omitempty"];
// arguments are the arguments of the term, which can be constants, variables, or atoms.
repeated Term arguments = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"arguments\",omitempty"
];
}

// Substitution represents a substitution made to the variables in the query to obtain the answer.
message Substitution {
option (gogoproto.goproto_stringer) = true;

// variable is the name of the variable.
string variable = 1 [(gogoproto.moretags) = "yaml:\"variable\",omitempty"];
// term is the term that the variable is substituted with.
Term term = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"term\",omitempty"
];
}

// Result represents the result of a query.
message Result {
option (gogoproto.goproto_stringer) = true;

// substitutions represent all the substitutions made to the variables in the query to obtain the answer.
repeated Substitution substitutions = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"substitutions\",omitempty"
];
}

// Answer represents the answer to a logic query.
message Answer {
option (gogoproto.goproto_stringer) = true;

// result is the result of the query.
bool success = 1 [(gogoproto.moretags) = "yaml:\"success\",omitempty"];
// has_more specifies if there are more solutions than the ones returned.
bool has_more = 2 [(gogoproto.moretags) = "yaml:\"has_next\",omitempty"];
// variables represent all the variables in the query.
repeated string variables = 3 [
(gogoproto.nullable) = true,
(gogoproto.moretags) = "yaml:\"variables\",omitempty"
];
// results represent all the results of the query.
repeated Result results = 4 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"results\",omitempty"
];
}

0 comments on commit 8b385e0

Please sign in to comment.