Skip to content

Commit

Permalink
feat(rpc): add custom cluster url (#267)
Browse files Browse the repository at this point in the history
* feat(rpc): add custom cluster url

* add localhost to cluster types
  • Loading branch information
sonicfromnewyoke authored Sep 9, 2024
1 parent 8ed10e4 commit 69b6246
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/rpc/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Epoch = sig.core.Epoch;
const Slot = sig.core.Slot;
const Pubkey = sig.core.Pubkey;
const Signature = sig.core.Signature;
const ClusterType = sig.accounts_db.genesis_config.ClusterType;
const Request = sig.rpc.Request;
const Response = sig.rpc.Response;
const Logger = sig.trace.log.Logger;
Expand All @@ -23,12 +22,13 @@ pub const Client = struct {
logger: Logger = .noop,
};

pub fn init(allocator: std.mem.Allocator, cluster_type: ClusterType, options: Options) Client {
pub fn init(allocator: std.mem.Allocator, cluster_type: types.ClusterType, options: Options) Client {
const http_endpoint = switch (cluster_type) {
.MainnetBeta => "https://api.mainnet-beta.solana.com",
.Testnet => "https://api.testnet.solana.com",
.Devnet => "https://api.devnet.solana.com",
.Development => @panic("Unsupported cluster type 'Development'"),
.LocalHost => "http://localhost:8899",
.Custom => |cluster| cluster.url,
};
return .{
.http_endpoint = http_endpoint,
Expand Down
10 changes: 10 additions & 0 deletions src/rpc/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ pub const SignatureStatuses = struct {
confirmationStatus: ?[]const u8,
};
};

pub const ClusterType = union(enum(u8)) {
MainnetBeta,
Testnet,
Devnet,
LocalHost,
Custom: struct {
url: []const u8,
},
};
2 changes: 1 addition & 1 deletion src/transaction_sender/service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const AtomicBool = std.atomic.Value(bool);
const AtomicSlot = std.atomic.Value(Slot);
const UdpSocket = network.Socket;

const ClusterType = sig.accounts_db.genesis_config.ClusterType;
const Slot = sig.core.Slot;
const Signature = sig.core.Signature;
const GossipTable = sig.gossip.GossipTable;
Expand All @@ -18,6 +17,7 @@ const Counter = sig.prometheus.Counter;
const Gauge = sig.prometheus.Gauge;
const GetMetricError = sig.prometheus.registry.GetMetricError;
const RpcClient = sig.rpc.Client;
const ClusterType = sig.rpc.types.ClusterType;
const RwMux = sig.sync.RwMux;
const Channel = sig.sync.Channel;
const Duration = sig.time.Duration;
Expand Down

0 comments on commit 69b6246

Please sign in to comment.