-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rpc): initial RPC server/client implementation #59
base: main
Are you sure you want to change the base?
Conversation
var arena = allocator.create(std.heap.ArenaAllocator) catch { | ||
return .{ .ClientError = .OutOfMemory }; | ||
}; | ||
arena.* = std.heap.ArenaAllocator.init(allocator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this leaks on success?
feeCalculator: FeeCalculator, | ||
}; | ||
|
||
pub const FeeCalculator = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something to note - seems like a lot of these structs also exist in the accounts-db branch but with snake_case field names
var table: *const GossipTable = table_rlock.get(); | ||
|
||
var contact_infos = table.getAllContactInfos() catch return .{ .Err = t.Error.Internal }; | ||
var rpc_contact_infos = std.ArrayList(t.RpcContactInfo).initCapacity(allocator, contact_infos.items.len) catch return .{ .Err = t.Error.Internal }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will all rpc methods need to return this Internal Error? - catch statements might be excessive on more complex rpc calls
|
||
inline fn methodCall(allocator: std.mem.Allocator, processor: *RpcRequestProcessor, request: *t.JsonRpcRequest, response: *httpz.Response) !void { | ||
inline for (@typeInfo(t.RpcServiceImpl(RpcRequestProcessor, t.Result)).Struct.fields) |field| { | ||
if (strEquals(request.method, field.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this fcn is only used once, might as well just have it as std.mem.eql
request.id, | ||
response, | ||
t.jrpc_error_code_invalid_params, | ||
std.fmt.allocPrint(allocator, "Invalid params, expected type: array, got: {s} ", .{@tagName(request.params)}) catch unreachable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this fcn is already anyerror
we should probably keep this as a try
since the alloc can fail?
|
||
args[0] = processor; | ||
args[1] = allocator; | ||
inline for (std.meta.fields(Args)[2..], 2.., 0..) |field, argIndex, valueIndex| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these vars should be snake_case
try response.write(); | ||
} | ||
|
||
inline fn methodCall(allocator: std.mem.Allocator, processor: *RpcRequestProcessor, request: *t.JsonRpcRequest, response: *httpz.Response) !void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why this is a seperate fcn?
return std.mem.eql(u8, value, other); | ||
} | ||
|
||
pub fn RpcFunc(comptime func: anytype) type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename to RpcFnCaller
?
Processor
implementsGossipService
dependent methodsResult
returns a way tofree
allocated memoryServer
returns correct headers, includingCORS
and servingOption
requestsClient
allows for multiple transportsCreate JSON serialization/deserialization framework that replicatesserde
's behaviorTo test out RPC server run it via: