0

I deployed and tested eosio smart contract. I want to record the logs of a smart contract using the web API. How can I do this? I searched but didn't get any satisfying answer. I tried to get logs by accessing actions, using eos-sharp in C# as follow:

try
            {
                UInt64 sequence; UInt32 blocknumber; DateTime datetime; string actionaname; String Receiver; String Trxid;
                var r = getEos();
                var resultaction = await r.GetActions(constants.LOCALCODEACCOUNT, 0, 20);
                string jsondata = ""; string finalresult = "";

                string globalActionJson = JsonConvert.SerializeObject(resultaction);

                foreach (GlobalAction action in resultaction.actions)
                {
                    var test = action.action_trace.act;
                    sequence = Convert.ToUInt64(action.account_action_seq);
                    blocknumber = Convert.ToUInt32(action.block_num);
                    datetime = Convert.ToDateTime(action.block_time);
                    actionaname = test.name.Trim();
                    Receiver = action.action_trace.receipt.receiver.Trim();
                    Trxid = action.action_trace.trx_id.Trim();

                    var dataarguments = JsonConvert.SerializeObject(test.data);
                    dataarguments = "[" + dataarguments + "]";
                    
                    jsondata += "{\"Sequence\":" + sequence + ",\"Block Number\":\"" + blocknumber + "\",\"Datetime\":\"" + datetime + "\",\"Action\":\"" + actionaname + "\",\"Receiver\":\"" + Receiver + "\",\"TransactionID\":\"" + Trxid + "\",\"Data\":" + dataarguments + "}"+",";

                }
                string removecomma = jsondata.Remove(jsondata.Length - 1);
                finalresult = "{\"Actions\":[" + removecomma + "]" + "}";
                JsonConvert.SerializeObject(finalresult);
                return finalresult;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

But here the problem is I can get only a certain number of actions. I need all the actions. Any help would be appreciated.

0

Not sure if I understand your question but you are limiting the number of actions returned to 20 by

var resultaction = await r.GetActions(constants.LOCALCODEACCOUNT, 0, 20);

if you want more, just do

var resultaction = await r.GetActions(constants.LOCALCODEACCOUNT, 0, Int32.MaxValue);

or something similar.

You could also fetch the hole Block via the GetBlock()-method but casting/parsing actions will be different.

var transactionReceipts = r.GetBlock("someBlock").Result.transactions;
foreach (var transactionReceipt in transactionReceipts)
{
    // do stuff with transaction-objects
}

if you want to get a permanent stream of specific actions and the network you are using maintains dfuse-nodes, then I would recommend using EosWsSharp instead of eos-sharp.

| improve this answer | |
  • Hi @cmadh, I don't want limited actions. I need all actions. Will Int32.MaxValue cause low performance? – Varsh Oct 15 at 10:23
  • It will be slower due to more computational work on the server- and client-side (far more iterations etc.) but I don't think it's slow unless your client-side algorithms are. – cmadh Oct 15 at 11:14
  • But what if in the future, the transactions are more than Int32.MaxValue? – Varsh Oct 16 at 10:14
  • if the number of actions exceeds Int32.MaxValue (2147483647), you definitely have to change the way you get the data (Probably even if it's far less but in the thousands or ten-thousands of actions). Fetching such an amount of actions at once doesn't make sense and will probably not work due to the size of the data/response. Better change your implementation to use r.GetBlock() or to leverage dfuse. – cmadh Oct 16 at 10:30
  • Okay, will check out. Thank you! – Varsh Oct 19 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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