0

I am using eos-sharp to get data from the eos smart contract. I am trying to get actions data by using:

var resultaction = await eos.GetActions("dqzmember", 0, 30);

I need information from resultaction and pass it to MongoDB. How to access data from variable resultaction as it is of type

EosSharp.Core.Api.v1.GetActionsResponse

How can I convert it into a string? Any help would be appreciated.

1 Answer 1

1

There are many different ways to achieve the conversion between the Objects returned by EosSharp and MongoDb.

If you only want to convert the data to a string and store it in a MongoDB, it only depends on wich part of the data you want to store.

A possible simple (but CPU-consuming because of the string-conversions) solution probably looks like the following:

        var resultaction = await DefaultApi.GetActions(new GetActionsRequest()
        {
            account_name = "dqzmember",
            pos = 0,
            offset = 30
        });

        string globalActionJson = JsonSerializer.Serialize<EosSharp.Core.Api.v1.GlobalAction>(resultAction);
        // serializes the whole Response to a json

        foreach (GlobalAction action in resultaction.actions)
        {
            action.ToString()
            // only returns the full qualified name of the object 
            // ("EosSharp.Core.Api.v1.GetActionsResponse") or something similar

            string actionJson = JsonSerializer.Serialize<EosSharp.Core.Api.v1.GetActionsResponse>(action);
            // serializes each individual action to a json-String


            action.action_trace.act.data.ToString();
            // converts the action_trace only to string
        }

Once you have your json-strings, you could simply do

BsonDocument document = BsonDocument.Parse(somejson);

while using MongoDB C# - BsonDocument Class

and store the Document in your DB.

A better solution would be to write your own classes with serializers/serialization and convert the obejcts returned by EosSharp to something you can process in your C#-buisnes-logic.

1
  • 1
    Thanx! BsonDocument.Parse(somejson); This line helps me a lot.
    – Varsh
    Apr 24, 2020 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.