-
Notifications
You must be signed in to change notification settings - Fork 9
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
14 changed files
with
1,516 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
module github.com/oasislabs/oasis-core-rosetta-gateway | ||
|
||
go 1.14 | ||
|
||
replace github.com/tendermint/tendermint => github.com/oasislabs/tendermint v0.33.4-oasis1 | ||
|
||
require ( | ||
github.com/coinbase/rosetta-sdk-go v0.1.5 | ||
github.com/oasislabs/oasis-core/go v0.0.0-20200507164617-35b7f62efec5 | ||
google.golang.org/grpc v1.29.1 | ||
) |
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 |
---|---|---|
@@ -1,7 +1,77 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/coinbase/rosetta-sdk-go/server" | ||
"github.com/oasislabs/oasis-core/go/common/logging" | ||
|
||
"github.com/oasislabs/oasis-core-rosetta-gateway/oasis-client" | ||
"github.com/oasislabs/oasis-core-rosetta-gateway/services" | ||
) | ||
|
||
// GatewayPortEnvVar is the name of the environment variable that specifies | ||
// which port the Oasis Rosetta gateway should run on. | ||
const GatewayPortEnvVar = "OASIS_ROSETTA_GATEWAY_PORT" | ||
|
||
var logger = logging.GetLogger("oasis-rosetta-gateway") | ||
|
||
// NewBlockchainRouter returns a Mux http.Handler from a collection of | ||
// Rosetta service controllers. | ||
func NewBlockchainRouter(oasisClient oasis_client.OasisClient) http.Handler { | ||
networkAPIController := server.NewNetworkAPIController(services.NewNetworkAPIService(oasisClient)) | ||
accountAPIController := server.NewAccountAPIController(services.NewAccountAPIService(oasisClient)) | ||
blockAPIController := server.NewBlockAPIController(services.NewBlockAPIService(oasisClient)) | ||
constructionAPIController := server.NewConstructionAPIController(services.NewConstructionAPIService(oasisClient)) | ||
|
||
return server.NewRouter(networkAPIController, accountAPIController, blockAPIController, constructionAPIController) | ||
} | ||
|
||
func main() { | ||
fmt.Println("Hello, world.") | ||
// Get server port from environment variable or use the default. | ||
port := os.Getenv(GatewayPortEnvVar) | ||
if port == "" { | ||
port = "8080" | ||
} | ||
nPort, err := strconv.Atoi(port) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: Malformed %s environment variable: %v\n", GatewayPortEnvVar, err) | ||
os.Exit(1) | ||
} | ||
|
||
// Prepare a new Oasis gRPC client. | ||
oasisClient, err := oasis_client.New() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: Failed to prepare Oasis gRPC client: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Make a test request using the client to see if the node works. | ||
cid, err := oasisClient.GetChainID(context.Background()) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: Node connectivity error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Initialize logging. | ||
err = logging.Initialize(os.Stdout, logging.FmtLogfmt, logging.LevelDebug, nil) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: Unable to initialize logging: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
logger.Info("Connected to Oasis node", "chain_context", cid) | ||
|
||
// Start the server. | ||
router := NewBlockchainRouter(oasisClient) | ||
logger.Info("Oasis Rosetta Gateway listening", "port", nPort) | ||
err = http.ListenAndServe(fmt.Sprintf(":%d", nPort), router) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Oasis Rosetta Gateway server exited with error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.