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

Change json fields to all lower case for consistency #277

Merged
merged 15 commits into from
Jul 8, 2020
2 changes: 1 addition & 1 deletion src/LevelDBStore/LevelDBStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

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

</Project>
5 changes: 3 additions & 2 deletions src/LevelDBStore/Plugins/Storage/Snapshot.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo.IO.Caching;
using Neo.IO.Data.LevelDB;
using Neo.Persistence;
using System.Collections.Generic;
Expand Down Expand Up @@ -35,9 +36,9 @@ public void Dispose()
snapshot.Dispose();
}

public IEnumerable<(byte[] Key, byte[] Value)> Find(byte table, byte[] prefix)
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte table, byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
{
return db.Find(options, Helper.CreateKey(table, prefix), (k, v) => (k[1..], v));
return db.Find(options, Helper.CreateKey(table, keyOrPrefix), (k, v) => (k[1..], v));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

direction is not working

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shargon ByteArrayComparer is internal, which I cannot use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help to fix this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for #279

}

public void Put(byte table, byte[] key, byte[] value)
Expand Down
3 changes: 2 additions & 1 deletion src/LevelDBStore/Plugins/Storage/Store.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo.IO.Caching;
using Neo.IO.Data.LevelDB;
using Neo.Persistence;
using System;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void Dispose()
db.Dispose();
}

public IEnumerable<(byte[], byte[])> Find(byte table, byte[] prefix)
public IEnumerable<(byte[], byte[])> Seek(byte table, byte[] prefix, SeekDirection direction = SeekDirection.Forward)
{
return db.Find(ReadOptions.Default, Helper.CreateKey(table, prefix), (k, v) => (k[1..], v));
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
4 changes: 2 additions & 2 deletions src/RpcClient/Models/RpcApplicationLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public JObject ToJson()
json["txid"] = TxId?.ToString();
json["trigger"] = Trigger;
json["vmstate"] = VMState;
json["gas_consumed"] = GasConsumed.ToString();
json["gasconsumed"] = GasConsumed.ToString();
json["stack"] = Stack.Select(q => q.ToJson()).ToArray();
json["notifications"] = Notifications.Select(q => q.ToJson()).ToArray();
return json;
Expand All @@ -38,7 +38,7 @@ public static RpcApplicationLog FromJson(JObject json)
log.TxId = json["txid"] is null ? null : UInt256.Parse(json["txid"].AsString());
log.Trigger = json["trigger"].TryGetEnum<TriggerType>();
log.VMState = json["vmstate"].TryGetEnum<VMState>();
log.GasConsumed = long.Parse(json["gas_consumed"].AsString());
log.GasConsumed = long.Parse(json["gasconsumed"].AsString());
log.Stack = ((JArray)json["stack"]).Select(p => ContractParameter.FromJson(p)).ToList();
log.Notifications = ((JArray)json["notifications"]).Select(p => RpcNotifyEventArgs.FromJson(p)).ToList();
return log;
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
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
28 changes: 1 addition & 27 deletions src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
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 +57,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 Expand Up @@ -96,27 +92,5 @@ private JObject InvokeScript(JArray _params)
CheckWitnessHashes checkWitnessHashes = _params.Count >= 2 ? new CheckWitnessHashes(((JArray)_params[1]).Select(u => UInt160.Parse(u.AsString())).ToArray()) : null;
return GetInvokeResult(script, checkWitnessHashes);
}

[RpcMethod]
private JObject GetUnclaimedGas(JArray _params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joeqian10 Move to #273?

{
string address = _params[0].AsString();
JObject json = new JObject();
UInt160 script_hash;
try
{
script_hash = address.ToScriptHash();
}
catch
{
script_hash = null;
}
if (script_hash == null)
throw new RpcException(-100, "Invalid address");
SnapshotView snapshot = Blockchain.Singleton.GetSnapshot();
json["unclaimed"] = NativeContract.NEO.UnclaimedGas(snapshot, script_hash, snapshot.Height + 1).ToString();
json["address"] = script_hash.ToAddress();
return json;
}
}
}
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>
Loading