Skip to content
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

Can't serialize results to JSON #28

Open
GuybrushX opened this issue Feb 5, 2023 · 2 comments
Open

Can't serialize results to JSON #28

GuybrushX opened this issue Feb 5, 2023 · 2 comments

Comments

@GuybrushX
Copy link

What happened?
Can't serialize results to JSON.

Since switch blocks are more than 10MB per era I wanted to dump a few switch blocks as JSON to process them offline so I don't need to request them again and again from the network. Seems like this isn't supported?

What did you expect to happen?
That serialization just works. Indeed I saw that quite a few Write methods aren't implemented yet:
BidsListConverter: throw new NotImplementedException("Write method for Bid not yet implemented");
Delegator: throw new NotImplementedException("Write method for Delegator not yet implemented");
EntryPoint: throw new NotImplementedException("Write method for EntryPointAccess not yet implemented");
SeigniorageAllocation: throw new NotImplementedException("Write method for SeigniorageAllocation not yet implemented");
StoredValue: throw new NotImplementedException("Write method for StoredValue not yet implemented");
Transform: throw new NotImplementedException("Write method for Transform not yet implemented");

Are you willing to submit a pull request to fix this bug?
Sorry, no.

@davidatwhiletrue
Copy link
Member

Hi @GuybrushX . Thanks for reporting this. I'll look into it in detail.

You can save any RPC response to a JSON file before parsing the response. For instance, to save the block:

var rpcResponse = await casperSdk.GetBlock(1_479_046);

File.WriteAllText("switch_block.json", rpcResponse.Result.GetProperty("block").GetRawText());

Then, you can read the file later and get a Block object:

var switch_block = JsonSerializer.Deserialize<Block>(File.ReadAllText("switch_block.json"));

Console.WriteLine(switch_block.Header.EraEnd.EraReport.Rewards);

@GuybrushX
Copy link
Author

GuybrushX commented Feb 7, 2023

Thank you for your fast reply.

Yeah, I found that after quite some time as well, I was just abusing the following method directly:

RpcResponse.Parse();

Your solution is much better, of course without modifying the SDK itself.

Serialization and Deserialization seem to work fine that way according to some quick tests I've done. I`m using the following code to get switch blocks btw. which you've sent me on Discord some time ago:

var globalStateByEra = await _casperClient.QueryGlobalState(GlobalStateKey.FromString($"era-{eraId}"));

I keep that issue here still open since the original issue still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants