Hi Nazar, I want to develop subspace SDKs for other languages like C#, but I’m encountering a bit of an issue with RPC, such as with something like SubscribeSlotInfo subscription. In conventional JsonRpc, I do this by adding a local method and then waiting for the server to call me back. However, in your Rust code, I noticed that after you call subspace_subscribeSlotInfo, it returns a Value, but you are able to directly convert this Value into a Stream and wait for subsequent returns. So, I want to know the details of this RPC implementation. I’m not familiar with Rust, and I’d like to understand firstly, how you convert the return Value of subspace_subscribeSlotInfo into a Stream, and secondly, how the Stream is handled or called back when you await it?
It depends on the library you’re using. Since this is just JSON-RPC 2.0, you can use any library that supports it. If you don’t know Rust it is not that big of a deal, you basically only need this to see available methods:
And then check what fields corresponding data structures have.
"Hi Nazar, after I called subspace_subscribeSlotInfo, the node successfully returned a string similar to ‘3PWEWad1yBr88vcl’, but subsequently, it did not continue to call my subspace_slot_info. It seems like some problems have occurred. Can you provide some help?
The definition of SlotInfo
is as follows:
public class SlotInfoModel {
public UInt64 slot_number { get; set; }
// size of 32
public byte[] global_challenge { get; set; }
public UInt64 solution_range { get; set; }
public UInt64 voting_solution_range { get; set; }
}
i use the StreamJsonRpc lib,
The definition of subspace_slot_info
is as follows:
rpcClient.AddLocalRpcMethod("subspace_slot_info", new Action<SlotInfo.SlotInfoModel>((result) =>
{
}));
After I called subspace_subscribeSlotInfo
, this method did not receive any callbacks.
I recommend you read JSON-RPC 2.0 specification if you are not using off-the-shelf JSON-RPC libraries. What you’ve got is an identifier of the subscription. If your node was started with --validator
you’ll see subsequent messages with that subscription ID.
I have successfully completed the subscription to the RPC event. I will refine the library a bit more before making it open source. Thank you for your help.