-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathUtility.cs
46 lines (42 loc) · 1.47 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2015-2023 The Neo Project.
//
// The Neo.Network.RPC is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
using Neo.Json;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract.Native;
using System.Linq;
namespace Neo.Plugins
{
static class Utility
{
public static JObject BlockToJson(Block block, ProtocolSettings settings)
{
JObject json = block.ToJson(settings);
json["tx"] = block.Transactions.Select(p => TransactionToJson(p, settings)).ToArray();
return json;
}
public static JObject TransactionToJson(Transaction tx, ProtocolSettings settings)
{
JObject json = tx.ToJson(settings);
json["sysfee"] = tx.SystemFee.ToString();
json["netfee"] = tx.NetworkFee.ToString();
return json;
}
public static JObject NativeContractToJson(this NativeContract contract, ProtocolSettings settings)
{
return new JObject
{
["id"] = contract.Id,
["hash"] = contract.Hash.ToString(),
["nef"] = contract.Nef.ToJson(),
["manifest"] = contract.Manifest.ToJson()
};
}
}
}