Skip to content

Commit

Permalink
Add vmState field in rpc getrawtransaction result (neo-project#1117)
Browse files Browse the repository at this point in the history
* add internal to DB and WriteBatch

* add vmstate field in rpc getrawtransaction result

* reset db.cs writebatch.cs

* Optimize

* Update RpcServer.cs

* Format

* Update RpcServer.cs

* Update RpcTransaction.cs

* Update UT_RpcClient.cs

* Fixes `RpcTransaction.VMState`
  • Loading branch information
Tommo-L committed Jun 22, 2020
1 parent 3a4327b commit 74f5acf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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

0 comments on commit 74f5acf

Please sign in to comment.