Esempio n. 1
0
        public void OnPersist(Snapshot snapshot, IReadOnlyList <Blockchain.ApplicationExecuted> applicationExecutedList)
        {
            WriteBatch writeBatch = new WriteBatch();

            foreach (var appExec in applicationExecutedList)
            {
                JObject json = new JObject();
                json["txid"]       = appExec.Transaction.Hash.ToString();
                json["executions"] = appExec.ExecutionResults.Select(p =>
                {
                    JObject execution         = new JObject();
                    execution["trigger"]      = p.Trigger;
                    execution["contract"]     = p.ScriptHash.ToString();
                    execution["vmstate"]      = p.VMState;
                    execution["gas_consumed"] = p.GasConsumed.ToString();
                    try
                    {
                        execution["stack"] = p.Stack.Select(q => q.ToParameter().ToJson()).ToArray();
                    }
                    catch (InvalidOperationException)
                    {
                        execution["stack"] = "error: recursive reference";
                    }
                    execution["notifications"] = p.Notifications.Select(q =>
                    {
                        JObject notification     = new JObject();
                        notification["contract"] = q.ScriptHash.ToString();
                        try
                        {
                            notification["state"] = q.State.ToParameter().ToJson();
                        }
                        catch (InvalidOperationException)
                        {
                            notification["state"] = "error: recursive reference";
                        }
                        return(notification);
                    }).ToArray();
                    return(execution);
                }).ToArray();
                writeBatch.Put(appExec.Transaction.Hash.ToArray(), json.ToString());
            }
            db.Write(WriteOptions.Default, writeBatch);
        }
Esempio n. 2
0
 public void OnCommit(Snapshot snapshot)
 {
 }