Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cmd/stellar-rpc/internal/.DS_Store
Binary file not shown.
Binary file added cmd/stellar-rpc/internal/config/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

type CoreClient interface {
Info(ctx context.Context) (*proto.InfoResponse, error)
SorobanInfo(ctx context.Context) (*proto.SorobanInfoResponse, error)

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, amd64)

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-22.04)

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu, arm64)

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 23)

undefined: proto.SorobanInfoResponse

Check failure on line 26 in cmd/stellar-rpc/internal/daemon/interfaces/interfaces.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 24)

undefined: proto.SorobanInfoResponse
SubmitTransaction(ctx context.Context, txBase64 string) (*proto.TXResponse, error)
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
return &proto.InfoResponse{}, nil
}

func (s noOpCoreClient) SorobanInfo(context.Context) (*proto.SorobanInfoResponse, error) {

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, amd64)

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-22.04)

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu, arm64)

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 23)

undefined: proto.SorobanInfoResponse

Check failure on line 59 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 24)

undefined: proto.SorobanInfoResponse
return &proto.SorobanInfoResponse{}, nil

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, amd64)

undefined: proto.SorobanInfoResponse

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse (typecheck)

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: proto.SorobanInfoResponse) (typecheck)

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-22.04)

undefined: proto.SorobanInfoResponse

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu, arm64)

undefined: proto.SorobanInfoResponse

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 23)

undefined: proto.SorobanInfoResponse

Check failure on line 60 in cmd/stellar-rpc/internal/daemon/interfaces/noOpDaemon.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 24)

undefined: proto.SorobanInfoResponse
}

func (s noOpCoreClient) SubmitTransaction(context.Context, string) (*proto.TXResponse, error) {
return &proto.TXResponse{Status: proto.PreflightStatusOk}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/stellar-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"github.com/stellar/go-stellar-sdk/support/log"

"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/config"
"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/daemon/interfaces"

Check failure on line 22 in cmd/stellar-rpc/internal/jsonrpc.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/daemon/interfaces (-: # github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/daemon/interfaces
"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/db"
"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/feewindow"
"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/methods"
Expand Down Expand Up @@ -190,7 +190,8 @@
underlyingHandler: methods.NewGetNetworkHandler(
cfg.NetworkPassphrase,
cfg.FriendbotURL,
params.LedgerReader,
params.Daemon.CoreClient(),
cfg.StellarCoreBinaryPath,
),
longName: toSnakeCase(protocol.GetNetworkMethodName),
queueLimit: cfg.RequestBacklogGetNetworkQueueLimit,
Expand Down
74 changes: 67 additions & 7 deletions cmd/stellar-rpc/internal/methods/get_network.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,93 @@
package methods

import (
"bytes"
"context"
"os/exec"
"regexp"
"slices"
"strconv"

"github.com/creachadair/jrpc2"

"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/db"
"github.com/stellar/stellar-rpc/protocol"
protocol "github.com/stellar/go-stellar-sdk/protocols/rpc"
"github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/daemon/interfaces"
)

// NewGetNetworkHandler returns a json rpc handler to for the getNetwork method
func NewGetNetworkHandler(
networkPassphrase string,
friendbotURL string,
ledgerReader db.LedgerReader,
coreClient interfaces.CoreClient,
coreBinaryPath string,
) jrpc2.Handler {
return NewHandler(func(ctx context.Context, _ protocol.GetNetworkRequest) (protocol.GetNetworkResponse, error) {
protocolVersion, err := getProtocolVersion(ctx, ledgerReader)
info, err := coreClient.Info(context.Background())
if err != nil {
return protocol.GetNetworkResponse{}, &jrpc2.Error{
Code: jrpc2.InternalError,
Message: err.Error(),
}
}

versionInfo, err := getSupportedProtocolVersions(ctx, coreBinaryPath)
if err != nil {
return protocol.GetNetworkResponse{}, &jrpc2.Error{
Code: jrpc2.InternalError,
Message: "failed to get supported protocol versions: " + err.Error(),
}
}

sorobanInfo, err := coreClient.SorobanInfo(context.Background())
if err != nil {
return protocol.GetNetworkResponse{}, &jrpc2.Error{
Code: jrpc2.InternalError,
Message: "failed to get soroban info: " + err.Error(),
}
}

return protocol.GetNetworkResponse{
FriendbotURL: friendbotURL,
Passphrase: networkPassphrase,
ProtocolVersion: int(protocolVersion),
FriendbotURL: friendbotURL,
Passphrase: networkPassphrase,
Build: info.Info.Build,
ProtocolVersions: versionInfo,
Limits: *sorobanInfo,
}, nil
})
}

func getSupportedProtocolVersions(ctx context.Context, coreBinaryPath string) (protocol.GetProtocolVersions, error) {
// Exec `stellar-core version` to get supported protocol versions
cmd := exec.CommandContext(ctx, coreBinaryPath, "version")
var out, stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return protocol.GetProtocolVersions{}, &jrpc2.Error{
Code: jrpc2.InternalError,
Message: "failed to exec `stellar-core version`: " + err.Error() + " stderr: " + stderr.String(),
}
}

// Find all matches for protocol versions across hosts in stdout
outStr := out.String()
re := regexp.MustCompile(`ledger protocol version:\s*(\d+)`)
matches := re.FindAllStringSubmatch(outStr, -1)

versions := make([]int, len(matches))
for i, match := range matches {
version, err := strconv.Atoi(match[1])
if err != nil {
return protocol.GetProtocolVersions{}, &jrpc2.Error{
Code: jrpc2.InternalError,
Message: "failed to parse protocol version from stellar-core version output: " + err.Error(),
}
}
versions[i] = version
}
return protocol.GetProtocolVersions{
MinSupportedProtocolVersion: slices.Min(versions), // min supported ledger protocol version
MaxSupportedProtocolVersion: slices.Max(versions), // max supported ledger protocol version
CoreSupportedProtocolVersion: versions[0], // core's protocol version. Should == MaxSupportedProtocolVersion
}, nil
}
1 change: 1 addition & 0 deletions protocol/get_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ type GetNetworkResponse struct {
FriendbotURL string `json:"friendbotUrl,omitempty"`
Passphrase string `json:"passphrase"`
ProtocolVersion int `json:"protocolVersion"`
Info string `json:"info,omitempty"`
}
Loading