Skip to content
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

Add vmState field in rpc getrawtransaction result #1117

Merged
merged 21 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions neo.UnitTests/Network/RPC/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,13 @@ public void TestGetRawTransaction()
json["blockhash"] = UInt256.Zero.ToString();
json["confirmations"] = 100;
json["blocktime"] = 10;
json["vmState"] = VMState.HALT;
MockResponse(response.ToString());

result = rpc.GetRawTransaction("0x9786cce0dddb524c40ddbdd5e31a41ed1f6b5c8a683c122f627ca4a007a7cf4e");
Assert.AreEqual(transaction.Hash, result.Transaction.Hash);
Assert.AreEqual(100, result.Confirmations);
Assert.AreEqual(VMState.HALT, result.VMState);
Assert.AreEqual(json.ToString(), result.ToJson().ToString());
}

Expand Down
5 changes: 5 additions & 0 deletions neo/Network/RPC/Models/RpcTransaction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Neo.IO.Json;
using Neo.Network.P2P.Payloads;
using Neo.VM;

namespace Neo.Network.RPC.Models
{
Expand All @@ -13,6 +14,8 @@ public class RpcTransaction

public uint? BlockTime { get; set; }

public VMState? VMState { get; set; }

public JObject ToJson()
{
JObject json = Transaction.ToJson();
Expand All @@ -21,6 +24,7 @@ public JObject ToJson()
json["blockhash"] = BlockHash.ToString();
json["confirmations"] = Confirmations;
json["blocktime"] = BlockTime;
json["vmState"] = VMState;
}
return json;
}
Expand All @@ -34,6 +38,7 @@ public static RpcTransaction FromJson(JObject json)
transaction.BlockHash = UInt256.Parse(json["blockhash"].AsString());
transaction.Confirmations = (int)json["confirmations"].AsNumber();
transaction.BlockTime = (uint)json["blocktime"].AsNumber();
transaction.VMState = json["vmState"].TryGetEnum<VMState>();
}
return transaction;
}
Expand Down
7 changes: 4 additions & 3 deletions neo/Network/RPC/RpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,14 @@ private JObject GetRawTransaction(UInt256 hash, bool verbose)
if (verbose)
{
JObject json = tx.ToJson();
uint? height = Blockchain.Singleton.Store.GetTransactions().TryGet(hash)?.BlockIndex;
if (height != null)
TransactionState txState = Blockchain.Singleton.Store.GetTransactions().TryGet(hash);
if (txState != null)
{
Header header = Blockchain.Singleton.Store.GetHeader((uint)height);
Header header = Blockchain.Singleton.Store.GetHeader(txState.BlockIndex);
json["blockhash"] = header.Hash.ToString();
json["confirmations"] = Blockchain.Singleton.Height - header.Index + 1;
json["blocktime"] = header.Timestamp;
json["vmState"] = txState.VMState;
}
return json;
}
Expand Down