Skip to content

Can't serialize results to JSON #28

Open

Description

@GuybrushX

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.

Activity

  1. davidatwhiletrue commented on Feb 5, 2023

    @davidatwhiletrue
    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);
  2. GuybrushX commented on Feb 7, 2023

    @GuybrushX
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions