Skip to content

Commit

Permalink
GetManyBlocks; delete NativeContractToJson
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Nov 30, 2023
1 parent 8d3279b commit 23f3c67
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions Fairy.Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ protected virtual JObject VirtualDeploy(JArray _params)
return json;
}

/// <summary>
///
/// </summary>
/// <param name="_params">
/// multiple UInt256 or uint indexes
/// 2 indexes, 1st index <= 2nd index: get all blocks between these indexes
/// other cases: get all blocks defined by each param
/// </param>
/// <returns></returns>
[RpcMethod]
protected virtual JToken GetManyBlocks(JArray _params)
{
using var snapshot = system.GetSnapshot();
JArray result = new();
if (_params.Count == 2 && _params[0] is JNumber && _params[1] is JNumber)
for (uint i = uint.Parse(_params[0]!.AsString()); i <= uint.Parse(_params[1]!.AsString()); ++i)
result.Add(NativeContract.Ledger.GetBlock(snapshot, i).ToJson(system.Settings));
if (result.Count == 0)
foreach (JToken? key in _params)
if (key is JNumber)
result.Add(NativeContract.Ledger.GetBlock(snapshot, uint.Parse(key.AsString())).ToJson(system.Settings));
else
result.Add(NativeContract.Ledger.GetBlock(snapshot, UInt256.Parse(key!.AsString())).ToJson(system.Settings));
return result;
}

[RpcMethod]
protected virtual JToken GetContract(JArray _params)
{
Expand Down Expand Up @@ -339,18 +365,6 @@ protected static JObject TransactionToJson(Transaction tx, ProtocolSettings sett
return json;
}

protected static JObject NativeContractToJson(NativeContract contract, ProtocolSettings settings)
{
return new JObject
{
["id"] = contract.Id,
["hash"] = contract.Hash.ToString(),
["nef"] = contract.Nef.ToJson(),
["manifest"] = contract.Manifest.ToJson(),
["updatehistory"] = settings.NativeUpdateHistory[contract.Name].Select(p => (JToken)p).ToArray()
};
}

protected static JObject ToJson(StackItem item, int max)
{
JObject json = item.ToJson();
Expand Down

0 comments on commit 23f3c67

Please sign in to comment.