-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,136 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package examples | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
pubsub "github.com/peggyjv/sommelier/v7/x/pubsub/types" | ||
) | ||
|
||
// Requests to schedule a contract call must be sent to many Steward instances. This is required because calls that do not have enough votes of approval from the validator set will not be | ||
// executed. Right now there is no single endpoint that handles broadcastic the call to each | ||
// Steward instance, so we must query the endpoints and then send the request to each one. | ||
// | ||
// This example simple sends the requests sequentially in a loop. In production it would be better to | ||
// send the requests concurrently. | ||
func ExampleBroadcastRequests() { | ||
// Query the Sommelier chain to get the list of Steward instances | ||
sommCtx := client.Context{}.WithNodeURI("http://localhost:26657") | ||
sommQueryClient := pubsub.NewQueryClient(sommCtx) | ||
|
||
res, err := sommQueryClient.QuerySubscribers(context.Background(), &pubsub.QuerySubscribersRequest{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
subscribers := res.Subscribers | ||
|
||
// Get client | ||
client, err := CreateTlsClient() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Build request | ||
request, err := BuildMulticallRequest() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Send request to each subscriber | ||
for _, subscriber := range subscribers { | ||
response, err := client.Schedule(context.Background(), request) | ||
if err != nil { | ||
fmt.Printf("Error sending request to %s: %s\n", subscriber, err) | ||
} | ||
|
||
fmt.Print("Sent request to ", subscriber, " with response: ", response, "\n") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package examples | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/peggyjv/steward/steward_proto_go/steward_proto" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// When running the production server, Steward exposes a Status/Version method that shows the current | ||
// running version of Steward. It can be useful for verifying connectivity and compatability. TLS authentication | ||
// is required to access this endpoint. | ||
func CreateTlsStatusClient() (steward_proto.StatusServiceClient, error) { | ||
// This example uses fake file paths for the auth materials | ||
creds, err := buildCredentials("client.crt", "client.key", "server_ca.crt") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addr := "localhost:5734" | ||
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(creds)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer conn.Close() | ||
|
||
client := steward_proto.NewStatusServiceClient(conn) | ||
|
||
return client, nil | ||
} | ||
|
||
func ExampleCheckStewardStatus() { | ||
// Get client and context | ||
client, err := CreateTlsStatusClient() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() | ||
|
||
// Send request | ||
response, err := client.Version(ctx, &steward_proto.VersionRequest{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Print(response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.