-
Notifications
You must be signed in to change notification settings - Fork 100
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
trigger type for getapplicationlog #380
Changes from 24 commits
4b18582
330b158
120f52c
c7997a9
7c9f02b
1079aa3
aa8e120
928f3f4
2c8cf6e
0b5473a
cd4645e
7d93776
319328d
dbc0f5a
1bdeb72
3fdc740
88554dd
582a785
43d0814
2e194b2
745196d
6bf5a8d
4e8b86e
2b58d37
24744d1
edf8e5b
934dd90
7a232fc
823c0f2
ff729ec
2b303d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using Neo.IO.Json; | ||
using Neo.Ledger; | ||
using Neo.Persistence; | ||
using Neo.SmartContract; | ||
using Neo.VM; | ||
using System; | ||
using System.Collections.Generic; | ||
|
@@ -37,30 +38,50 @@ public JObject GetApplicationLog(JArray _params) | |
UInt256 hash = UInt256.Parse(_params[0].AsString()); | ||
byte[] value = db.Get(ReadOptions.Default, hash.ToArray()); | ||
if (value is null) | ||
throw new RpcException(-100, "Unknown transaction"); | ||
return JObject.Parse(Encoding.UTF8.GetString(value)); | ||
throw new RpcException(-100, "Unknown transaction/blockhash"); | ||
|
||
//Additional optional "trigger" parameter to getapplicationlog for clients to be able to get just one execution result for a block. | ||
if (_params.Count >= 2 && Enum.TryParse(_params[1].AsString(), true, out TriggerType trigger)) | ||
{ | ||
var raw = JObject.Parse(Encoding.UTF8.GetString(value)); | ||
var executions = raw["executions"] as JArray; | ||
for (int i = 0; i < executions.Count;) | ||
{ | ||
if (!executions[i]["trigger"].AsString().Equals(trigger.ToString(), StringComparison.OrdinalIgnoreCase)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it supports. If want to query There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the user may not know it, they're more likely to think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we should not allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why? It's the default anyway and I don't see any problem with specifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because neo never execute the contract with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, given the way triggers are defined I was expecting something more like
here (which is what we did in neo-go, for us specifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trigger it's a flag because it can be used for filters (Interops) but we always execute the contract as 'non flag'. |
||
executions.RemoveAt(i); | ||
else | ||
i++; | ||
} | ||
return raw; | ||
} | ||
else | ||
{ | ||
return JObject.Parse(Encoding.UTF8.GetString(value)); | ||
} | ||
} | ||
|
||
public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList) | ||
{ | ||
WriteBatch writeBatch = new WriteBatch(); | ||
|
||
foreach (var appExec in applicationExecutedList) | ||
//processing log for transactions | ||
foreach (var appExec in applicationExecutedList.Where(p => p.Transaction != null)) | ||
{ | ||
JObject json = new JObject(); | ||
json["txid"] = appExec.Transaction?.Hash.ToString(); | ||
json["trigger"] = appExec.Trigger; | ||
json["vmstate"] = appExec.VMState; | ||
json["gasconsumed"] = appExec.GasConsumed.ToString(); | ||
var txJson = new JObject(); | ||
txJson["txid"] = appExec.Transaction.Hash.ToString(); | ||
JObject trigger = new JObject(); | ||
trigger["trigger"] = appExec.Trigger; | ||
trigger["vmstate"] = appExec.VMState; | ||
trigger["gasconsumed"] = appExec.GasConsumed.ToString(); | ||
try | ||
{ | ||
json["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray(); | ||
trigger["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
json["stack"] = "error: recursive reference"; | ||
trigger["stack"] = "error: recursive reference"; | ||
} | ||
json["notifications"] = appExec.Notifications.Select(q => | ||
trigger["notifications"] = appExec.Notifications.Select(q => | ||
{ | ||
JObject notification = new JObject(); | ||
notification["contract"] = q.ScriptHash.ToString(); | ||
|
@@ -75,7 +96,52 @@ public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationEx | |
} | ||
return notification; | ||
}).ToArray(); | ||
writeBatch.Put((appExec.Transaction?.Hash ?? snapshot.PersistingBlock.Hash).ToArray(), Encoding.UTF8.GetBytes(json.ToString())); | ||
|
||
txJson["executions"] = new List<JObject>() { trigger }.ToArray(); | ||
writeBatch.Put(appExec.Transaction.Hash.ToArray(), Encoding.UTF8.GetBytes(txJson.ToString())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strictUtf8 |
||
} | ||
|
||
//processing log for block | ||
var blocks = applicationExecutedList.Where(p => p.Transaction == null); | ||
if (blocks.Count() > 0) | ||
{ | ||
var blockJson = new JObject(); | ||
var blockHash = snapshot.PersistingBlock.Hash.ToArray(); | ||
blockJson["blockhash"] = "0x" + blockHash.Reverse().ToArray().ToHexString(); | ||
shargon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var triggerList = new List<JObject>(); | ||
foreach (var appExec in blocks) | ||
{ | ||
JObject trigger = new JObject(); | ||
trigger["trigger"] = appExec.Trigger; | ||
trigger["vmstate"] = appExec.VMState; | ||
trigger["gasconsumed"] = appExec.GasConsumed.ToString(); | ||
try | ||
{ | ||
trigger["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
trigger["stack"] = "error: recursive reference"; | ||
} | ||
trigger["notifications"] = appExec.Notifications.Select(q => | ||
{ | ||
JObject notification = new JObject(); | ||
notification["contract"] = q.ScriptHash.ToString(); | ||
notification["eventname"] = q.EventName; | ||
try | ||
{ | ||
notification["state"] = q.State.ToJson(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
notification["state"] = "error: recursive reference"; | ||
} | ||
return notification; | ||
}).ToArray(); | ||
triggerList.Add(trigger); | ||
} | ||
blockJson["executions"] = triggerList.ToArray(); | ||
writeBatch.Put(blockHash, Encoding.UTF8.GetBytes(blockJson.ToString())); | ||
} | ||
db.Write(WriteOptions.Default, writeBatch); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StrictUtf8