Skip to content

Commit

Permalink
Change json fields to all lower case for consistency (#277)
Browse files Browse the repository at this point in the history
* Change json field names for GetVersion

* Change json fields to snake case for consistency

* Change json fields to all lower case

* Fix UTs.

* rename

* Add back GetUnclaimedGas()

* Remove "_" in RpcNep5Tracker.cs

* Remove underscore line

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Luchuan <luchuan@neo.org>
  • Loading branch information
3 people committed Jul 8, 2020
1 parent 1cf385d commit bc6d38a
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/LevelDBStore/Plugins/Storage/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Dispose()
snapshot.Dispose();
}

public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte table, byte[] prefix, SeekDirection direction)
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte table, byte[] prefix, SeekDirection direction = SeekDirection.Forward)
{
return db.Seek(options, table, prefix, direction, (k, v) => (k[1..], v));
}
Expand Down
2 changes: 1 addition & 1 deletion src/LevelDBStore/Plugins/Storage/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Dispose()
db.Dispose();
}

public IEnumerable<(byte[], byte[])> Seek(byte table, byte[] prefix, SeekDirection direction)
public IEnumerable<(byte[], byte[])> Seek(byte table, byte[] prefix, SeekDirection direction = SeekDirection.Forward)
{
return db.Seek(ReadOptions.Default, table, prefix, direction, (k, v) => (k[1..], v));
}
Expand Down
4 changes: 2 additions & 2 deletions src/RpcClient/Models/RpcInvokeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public JObject ToJson()
JObject json = new JObject();
json["script"] = Script;
json["state"] = State;
json["gas_consumed"] = GasConsumed;
json["gasconsumed"] = GasConsumed;
try
{
json["stack"] = new JArray(Stack.Select(p => p.ToJson()));
Expand All @@ -41,7 +41,7 @@ public static RpcInvokeResult FromJson(JObject json)
RpcInvokeResult invokeScriptResult = new RpcInvokeResult();
invokeScriptResult.Script = json["script"].AsString();
invokeScriptResult.State = json["state"].TryGetEnum<VM.VMState>();
invokeScriptResult.GasConsumed = json["gas_consumed"].AsString();
invokeScriptResult.GasConsumed = json["gasconsumed"].AsString();
try
{
invokeScriptResult.Stack = ((JArray)json["stack"]).Select(p => ContractParameter.FromJson(p)).ToArray();
Expand Down
8 changes: 4 additions & 4 deletions src/RpcClient/Models/RpcNep5Balances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public class RpcNep5Balance
public JObject ToJson()
{
JObject json = new JObject();
json["asset_hash"] = AssetHash.ToString();
json["assethash"] = AssetHash.ToString();
json["amount"] = Amount.ToString();
json["last_updated_block"] = LastUpdatedBlock;
json["lastupdatedblock"] = LastUpdatedBlock;
return json;
}

public static RpcNep5Balance FromJson(JObject json)
{
RpcNep5Balance balance = new RpcNep5Balance
{
AssetHash = UInt160.Parse(json["asset_hash"].AsString()),
AssetHash = UInt160.Parse(json["assethash"].AsString()),
Amount = BigInteger.Parse(json["amount"].AsString()),
LastUpdatedBlock = (uint)json["last_updated_block"].AsNumber()
LastUpdatedBlock = (uint)json["lastupdatedblock"].AsNumber()
};
return balance;
}
Expand Down
20 changes: 10 additions & 10 deletions src/RpcClient/Models/RpcNep5Transfers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ public JObject ToJson()
{
JObject json = new JObject();
json["timestamp"] = TimestampMS;
json["asset_hash"] = AssetHash.ToString();
json["transfer_address"] = UserScriptHash.ToAddress();
json["assethash"] = AssetHash.ToString();
json["transferaddress"] = UserScriptHash.ToAddress();
json["amount"] = Amount.ToString();
json["block_index"] = BlockIndex;
json["transfer_notify_index"] = TransferNotifyIndex;
json["tx_hash"] = TxHash.ToString();
json["blockindex"] = BlockIndex;
json["transfernotifyindex"] = TransferNotifyIndex;
json["txhash"] = TxHash.ToString();
return json;
}

public static RpcNep5Transfer FromJson(JObject json)
{
RpcNep5Transfer transfer = new RpcNep5Transfer();
transfer.TimestampMS = (ulong)json["timestamp"].AsNumber();
transfer.AssetHash = UInt160.Parse(json["asset_hash"].AsString());
transfer.UserScriptHash = json["transfer_address"].AsString().ToScriptHash();
transfer.AssetHash = UInt160.Parse(json["assethash"].AsString());
transfer.UserScriptHash = json["transferaddress"].AsString().ToScriptHash();
transfer.Amount = BigInteger.Parse(json["amount"].AsString());
transfer.BlockIndex = (uint)json["block_index"].AsNumber();
transfer.TransferNotifyIndex = (ushort)json["transfer_notify_index"].AsNumber();
transfer.TxHash = UInt256.Parse(json["tx_hash"].AsString());
transfer.BlockIndex = (uint)json["blockindex"].AsNumber();
transfer.TransferNotifyIndex = (ushort)json["transfernotifyindex"].AsNumber();
transfer.TxHash = UInt256.Parse(json["txhash"].AsString());
return transfer;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/RpcClient/Models/RpcTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public JObject ToJson()
json["blocktime"] = BlockTime;
if (VMState != null)
{
json["vm_state"] = VMState;
json["vmstate"] = VMState;
}
}
return json;
Expand All @@ -41,7 +41,7 @@ public static RpcTransaction FromJson(JObject json)
transaction.BlockHash = UInt256.Parse(json["blockhash"].AsString());
transaction.Confirmations = (uint)json["confirmations"].AsNumber();
transaction.BlockTime = (ulong)json["blocktime"].AsNumber();
transaction.VMState = json["vm_state"]?.TryGetEnum<VMState>();
transaction.VMState = json["vmstate"]?.TryGetEnum<VMState>();
}
return transaction;
}
Expand Down
12 changes: 6 additions & 6 deletions src/RpcClient/Models/RpcVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public class RpcVersion
public JObject ToJson()
{
JObject json = new JObject();
json["tcp_port"] = TcpPort;
json["ws_port"] = WsPort;
json["tcpport"] = TcpPort;
json["wsport"] = WsPort;
json["nonce"] = Nonce;
json["user_agent"] = UserAgent;
json["useragent"] = UserAgent;
return json;
}

public static RpcVersion FromJson(JObject json)
{
RpcVersion version = new RpcVersion();
version.TcpPort = (int)json["tcp_port"].AsNumber();
version.WsPort = (int)json["ws_port"].AsNumber();
version.TcpPort = (int)json["tcpport"].AsNumber();
version.WsPort = (int)json["wsport"].AsNumber();
version.Nonce = (uint)json["nonce"].AsNumber();
version.UserAgent = json["user_agent"].AsString();
version.UserAgent = json["useragent"].AsString();
return version;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/RpcClient/RpcClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00958" />
<PackageReference Include="Neo" Version="3.0.0-CI00961" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/RpcClient/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static Block BlockFromJson(JObject json)
Block block = new Block();
BlockBase blockBase = block;
blockBase.FromJson(json);
block.ConsensusData = ConsensusDataFromJson(json["consensus_data"]);
block.ConsensusData = ConsensusDataFromJson(json["consensusdata"]);
block.Transactions = ((JArray)json["tx"]).Select(p => TransactionFromJson(p)).ToArray();
return block;
}
Expand All @@ -120,9 +120,9 @@ public static Transaction TransactionFromJson(JObject json)
tx.Version = byte.Parse(json["version"].AsString());
tx.Nonce = uint.Parse(json["nonce"].AsString());
tx.Sender = json["sender"].AsString().ToScriptHash();
tx.SystemFee = long.Parse(json["sys_fee"].AsString());
tx.NetworkFee = long.Parse(json["net_fee"].AsString());
tx.ValidUntilBlock = uint.Parse(json["valid_until_block"].AsString());
tx.SystemFee = long.Parse(json["sysfee"].AsString());
tx.NetworkFee = long.Parse(json["netfee"].AsString());
tx.ValidUntilBlock = uint.Parse(json["validuntilblock"].AsString());
tx.Attributes = ((JArray)json["attributes"]).Select(p => TransactionAttributeFromJson(p)).ToArray();
tx.Script = Convert.FromBase64String(json["script"].AsString());
tx.Witnesses = ((JArray)json["witnesses"]).Select(p => WitnessFromJson(p)).ToArray();
Expand Down
16 changes: 8 additions & 8 deletions src/RpcNep5Tracker/RpcNep5Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RpcNep5Tracker : Plugin, IPersistencePlugin
private uint _maxResults;
private Snapshot _levelDbSnapshot;

public override string Description => "Enquiries NEP-5 balance and transactions history of accounts through RPC";
public override string Description => "Enquiries NEP-5 balances and transaction history of accounts through RPC";

public RpcNep5Tracker()
{
Expand Down Expand Up @@ -233,12 +233,12 @@ public bool ShouldThrowExceptionFromCommit(Exception ex)
if (++resultCount > _maxResults) break;
JObject transfer = new JObject();
transfer["timestamp"] = key.TimestampMS;
transfer["asset_hash"] = key.AssetScriptHash.ToString();
transfer["transfer_address"] = value.UserScriptHash.ToAddress();
transfer["assethash"] = key.AssetScriptHash.ToString();
transfer["transferaddress"] = value.UserScriptHash.ToAddress();
transfer["amount"] = value.Amount.ToString();
transfer["block_index"] = value.BlockIndex;
transfer["transfer_notify_index"] = key.BlockXferNotificationIndex;
transfer["tx_hash"] = value.TxHash.ToString();
transfer["blockindex"] = value.BlockIndex;
transfer["transfernotifyindex"] = key.BlockXferNotificationIndex;
transfer["txhash"] = value.TxHash.ToString();
parentJArray.Add(transfer);
}
}
Expand Down Expand Up @@ -288,9 +288,9 @@ public JObject GetNep5Balances(JArray _params)
JObject balance = new JObject();
if (Blockchain.Singleton.View.Contracts.TryGet(key.AssetScriptHash) is null)
continue;
balance["asset_hash"] = key.AssetScriptHash.ToString();
balance["assethash"] = key.AssetScriptHash.ToString();
balance["amount"] = value.Balance.ToString();
balance["last_updated_block"] = value.LastUpdatedBlock;
balance["lastupdatedblock"] = value.LastUpdatedBlock;
balances.Add(balance);
}
return json;
Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private JObject GetRawTransaction(JArray _params)
json["blockhash"] = header.Hash.ToString();
json["confirmations"] = Blockchain.Singleton.Height - header.Index + 1;
json["blocktime"] = header.Timestamp;
json["vm_state"] = txState.VMState;
json["vmstate"] = txState.VMState;
}
return json;
}
Expand Down
6 changes: 3 additions & 3 deletions src/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash)
private JObject GetVersion(JArray _params)
{
JObject json = new JObject();
json["tcpPort"] = LocalNode.Singleton.ListenerTcpPort;
json["wsPort"] = LocalNode.Singleton.ListenerWsPort;
json["tcpport"] = LocalNode.Singleton.ListenerTcpPort;
json["wsport"] = LocalNode.Singleton.ListenerWsPort;
json["nonce"] = LocalNode.Nonce;
json["userAgent"] = LocalNode.UserAgent;
json["useragent"] = LocalNode.UserAgent;
return json;
}

Expand Down
9 changes: 4 additions & 5 deletions src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
#pragma warning disable IDE0060

using Neo.IO.Json;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System;
using System.IO;
using System.Linq;
using Neo.IO;
using Neo.Ledger;
using Neo.SmartContract.Native;
using Neo.Wallets;

namespace Neo.Plugins
{
Expand Down Expand Up @@ -61,7 +60,7 @@ private JObject GetInvokeResult(byte[] script, IVerifiable checkWitnessHashes =
JObject json = new JObject();
json["script"] = script.ToHexString();
json["state"] = engine.State;
json["gas_consumed"] = engine.GasConsumed.ToString();
json["gasconsumed"] = engine.GasConsumed.ToString();
try
{
json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToJson()));
Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
<PackageReference Include="Neo" Version="3.0.0-CI00958" />
<PackageReference Include="Neo" Version="3.0.0-CI00961" />
</ItemGroup>

</Project>

0 comments on commit bc6d38a

Please sign in to comment.