Skip to content

Commit

Permalink
added query smart contract endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xluk committed Aug 8, 2024
1 parent 55f1b29 commit f79c151
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 84 deletions.
26 changes: 26 additions & 0 deletions foundation/rpc_server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ func (s *Server) GetBlockHeight(ctx context.Context, _ *emptypb.Empty) (*protobu
}}, nil
}

func (s *Server) QuerySmartContract(ctx context.Context, req *protobuff.QuerySmartContractRequest) (*protobuff.QuerySmartContractResponse, error) {
reqData, err := base64.StdEncoding.DecodeString(req.RequestData)
if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "failed to decode from base64 the request data: %s", req.RequestData)
}

client, err := s.qPool.Get()
if err != nil {
return nil, status.Errorf(codes.Internal, "getting pool connection %v", err)
}

scData, err := client.QuerySmartContract(ctx, qubic.RequestContractFunction{
ContractIndex: req.ContractIndex,
InputType: uint16(req.InputType),
InputSize: uint16(req.InputSize),
}, reqData)
if err != nil {
s.qPool.Close(client)
return nil, status.Errorf(codes.Internal, "query smart contract %v", err)
}

s.qPool.Put(client)

return &protobuff.QuerySmartContractResponse{ResponseData: base64.StdEncoding.EncodeToString(scData.Data)}, nil
}

type maxTickResponse struct {
MaxTick uint32 `json:"max_tick"`
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ardanlabs/conf v1.5.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/pkg/errors v0.9.1
github.com/qubic/go-node-connector v0.7.1
github.com/qubic/go-node-connector v0.8.0
github.com/qubic/go-schnorrq v1.0.0
google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c
google.golang.org/grpc v1.62.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qubic/go-node-connector v0.7.1 h1:AvkirqMTW6PQ7VxvALJOSI2+Cja3cl1llwFqWftaD6I=
github.com/qubic/go-node-connector v0.7.1/go.mod h1:3Q9xCv5c01AqxVIx1aijMd8Pt3KJyQQiDfc4sG0UnXI=
github.com/qubic/go-node-connector v0.8.0 h1:GzA8rpLvbEAkqz/AWkM/7Ut4P9KkwrkdP++tmF2eKHs=
github.com/qubic/go-node-connector v0.8.0/go.mod h1:3Q9xCv5c01AqxVIx1aijMd8Pt3KJyQQiDfc4sG0UnXI=
github.com/qubic/go-schnorrq v1.0.0 h1:EiCC3v9v3esFFfhKNEGdAI4DFIY3Dm/wbH327pC5qco=
github.com/qubic/go-schnorrq v1.0.0/go.mod h1:KW64PcvyF4+cBA22pCx9wcoKDqPIbGz0EZ9dCZWV6Yo=
github.com/silenceper/pool v1.0.0 h1:JTCaA+U6hJAA0P8nCx+JfsRCHMwLTfatsm5QXelffmU=
Expand Down
5 changes: 3 additions & 2 deletions protobuff/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ all: $(GO)
--go_out=paths=source_relative:. *.proto

openapi: *.proto
protoc --openapiv2_out=logtostderr=true:. $(OPT_ARGS) \
*.proto
protoc --openapiv2_out=logtostderr=true:. \
--proto_path=.:/opt/homebrew/Cellar/protobuf/25.3_1/include \
*.proto

clean:
rm -f *.pb.go
Expand Down
328 changes: 249 additions & 79 deletions protobuff/qubic.pb.go

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions protobuff/qubic.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions protobuff/qubic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,31 @@ message PossessedAssetsResponse {
repeated PossessedAsset possessed_assets = 1;
}

message QuerySmartContractRequest {
uint32 contract_index = 1;
uint32 input_type = 2;
uint32 input_size = 3;
string request_data = 4;
}

message QuerySmartContractResponse {
string response_data = 5;
}

service QubicLiveService {
rpc GetBalance(GetBalanceRequest) returns (GetBalanceResponse) {
option (google.api.http) = {
get: "/balances/{id}"
};
};

rpc QuerySmartContract(QuerySmartContractRequest) returns (QuerySmartContractResponse) {
option (google.api.http) = {
post: "/querySmartContract"
body: "*"
};
};

rpc BroadcastTransaction(BroadcastTransactionRequest) returns (BroadcastTransactionResponse) {
option (google.api.http) = {
post: "/broadcast-transaction"
Expand Down
37 changes: 37 additions & 0 deletions protobuff/qubic_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f79c151

Please sign in to comment.