diff --git a/AntSharesCore/Consensus/ConsensusMessage.cs b/AntSharesCore/Consensus/ConsensusMessage.cs index f377baa459..751a09958d 100644 --- a/AntSharesCore/Consensus/ConsensusMessage.cs +++ b/AntSharesCore/Consensus/ConsensusMessage.cs @@ -9,6 +9,8 @@ internal abstract class ConsensusMessage : ISerializable public readonly ConsensusMessageType Type; public byte ViewNumber; + public int Size => sizeof(ConsensusMessageType) + sizeof(byte); + protected ConsensusMessage(ConsensusMessageType type) { this.Type = type; diff --git a/AntSharesCore/Core/AgencyTransaction.cs b/AntSharesCore/Core/AgencyTransaction.cs index 83b6a83277..deb2253487 100644 --- a/AntSharesCore/Core/AgencyTransaction.cs +++ b/AntSharesCore/Core/AgencyTransaction.cs @@ -42,6 +42,8 @@ public class AgencyTransaction : Transaction /// public SplitOrder SplitOrder; + public override int Size => base.Size + AssetId.Size + ValueAssetId.Size + Agent.Size + Orders.Length.GetVarSize() + Orders.Sum(p => p.SizeInTransaction) + SplitOrder.Size; + public AgencyTransaction() : base(TransactionType.AgencyTransaction) { diff --git a/AntSharesCore/Core/Block.cs b/AntSharesCore/Core/Block.cs index 8fd2c9e8ad..248a8dcdf6 100644 --- a/AntSharesCore/Core/Block.cs +++ b/AntSharesCore/Core/Block.cs @@ -51,6 +51,8 @@ public Header Header /// InventoryType IInventory.InventoryType => InventoryType.Block; + public override int Size => base.Size + Transactions.Length.GetVarSize() + Transactions.Sum(p => p.Size); + public static Fixed8 CalculateNetFee(IEnumerable transactions) { Transaction[] ts = transactions.Where(p => p.Type != TransactionType.MinerTransaction && p.Type != TransactionType.ClaimTransaction).ToArray(); diff --git a/AntSharesCore/Core/BlockBase.cs b/AntSharesCore/Core/BlockBase.cs index ddfa1e7850..372718a71e 100644 --- a/AntSharesCore/Core/BlockBase.cs +++ b/AntSharesCore/Core/BlockBase.cs @@ -70,6 +70,8 @@ Script[] ISignable.Scripts } } + public virtual int Size => sizeof(uint) + PrevBlock.Size + MerkleRoot.Size + sizeof(uint) + sizeof(uint) + sizeof(ulong) + NextMiner.Size + 1 + Script.Size; + public virtual void Deserialize(BinaryReader reader) { ((ISignable)this).DeserializeUnsigned(reader); @@ -118,6 +120,7 @@ public virtual JObject ToJson() { JObject json = new JObject(); json["hash"] = Hash.ToString(); + json["size"] = Size; json["version"] = Version; json["previousblockhash"] = PrevBlock.ToString(); json["merkleroot"] = MerkleRoot.ToString(); diff --git a/AntSharesCore/Core/ClaimTransaction.cs b/AntSharesCore/Core/ClaimTransaction.cs index 5789085967..7d33171808 100644 --- a/AntSharesCore/Core/ClaimTransaction.cs +++ b/AntSharesCore/Core/ClaimTransaction.cs @@ -18,6 +18,8 @@ public class ClaimTransaction : Transaction /// public TransactionInput[] Claims; + public override int Size => base.Size + Claims.Length.GetVarSize() + Claims.Sum(p => p.Size); + public ClaimTransaction() : base(TransactionType.ClaimTransaction) { diff --git a/AntSharesCore/Core/EnrollmentTransaction.cs b/AntSharesCore/Core/EnrollmentTransaction.cs index 1ae5fc5553..8ee56687a6 100644 --- a/AntSharesCore/Core/EnrollmentTransaction.cs +++ b/AntSharesCore/Core/EnrollmentTransaction.cs @@ -35,6 +35,8 @@ public UInt160 Miner } } + public override int Size => base.Size + PublicKey.Size; + /// /// 系统费用 /// diff --git a/AntSharesCore/Core/Header.cs b/AntSharesCore/Core/Header.cs index b8c31cd1e9..5751af200b 100644 --- a/AntSharesCore/Core/Header.cs +++ b/AntSharesCore/Core/Header.cs @@ -7,6 +7,8 @@ namespace AntShares.Core { public class Header : BlockBase, IEquatable
{ + public override int Size => base.Size + 1; + public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); diff --git a/AntSharesCore/Core/MinerTransaction.cs b/AntSharesCore/Core/MinerTransaction.cs index 0b651ed7ef..bbe3c34aa6 100644 --- a/AntSharesCore/Core/MinerTransaction.cs +++ b/AntSharesCore/Core/MinerTransaction.cs @@ -15,6 +15,8 @@ public class MinerTransaction : Transaction /// public uint Nonce; + public override int Size => base.Size + sizeof(uint); + public MinerTransaction() : base(TransactionType.MinerTransaction) { diff --git a/AntSharesCore/Core/Order.cs b/AntSharesCore/Core/Order.cs index c76bfec32c..4f015f766f 100644 --- a/AntSharesCore/Core/Order.cs +++ b/AntSharesCore/Core/Order.cs @@ -43,19 +43,11 @@ public class Order : ISignable /// /// 用于验证该订单的脚本列表 /// - public Script[] Scripts; + public Script[] Scripts { get; set; } - Script[] ISignable.Scripts - { - get - { - return Scripts; - } - set - { - Scripts = value; - } - } + public int Size => AssetId.Size + ValueAssetId.Size + Agent.Size + SizeInTransaction; + + public int SizeInTransaction => Amount.Size + Price.Size + Client.Size + Inputs.Length.GetVarSize() + Inputs.Sum(p => p.Size) + Scripts.Length.GetVarSize() + Scripts.Sum(p => p.Size); void ISerializable.Deserialize(BinaryReader reader) { diff --git a/AntSharesCore/Core/PublishTransaction.cs b/AntSharesCore/Core/PublishTransaction.cs index 8b94660fc7..5407e876eb 100644 --- a/AntSharesCore/Core/PublishTransaction.cs +++ b/AntSharesCore/Core/PublishTransaction.cs @@ -10,6 +10,8 @@ public class PublishTransaction : Transaction { public byte[][] Contracts; + public override int Size => base.Size + Contracts.Length.GetVarSize() + Contracts.Sum(p => p.Length.GetVarSize() + p.Length); + public override Fixed8 SystemFee => Fixed8.FromDecimal(500 * Contracts.Length); public PublishTransaction() diff --git a/AntSharesCore/Core/RegisterTransaction.cs b/AntSharesCore/Core/RegisterTransaction.cs index 2955a2dc07..7b2c689211 100644 --- a/AntSharesCore/Core/RegisterTransaction.cs +++ b/AntSharesCore/Core/RegisterTransaction.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Text; namespace AntShares.Core { @@ -42,6 +43,8 @@ public class RegisterTransaction : Transaction private static readonly string ShareName = "[{\"lang\":\"zh-CN\",\"name\":\"股权\"},{\"lang\":\"en\",\"name\":\"Share\"}]"; + public override int Size => base.Size + sizeof(AssetType) + Encoding.UTF8.GetByteCount(Name).GetVarSize() + Encoding.UTF8.GetByteCount(Name) + Amount.Size + sizeof(byte) + Issuer.Size + Admin.Size; + /// /// 系统费用 /// diff --git a/AntSharesCore/Core/Scripts/Script.cs b/AntSharesCore/Core/Scripts/Script.cs index c370c954bc..9cb1d66950 100644 --- a/AntSharesCore/Core/Scripts/Script.cs +++ b/AntSharesCore/Core/Scripts/Script.cs @@ -12,6 +12,8 @@ public class Script : ISerializable public byte[] StackScript; public byte[] RedeemScript; + public int Size => StackScript.Length.GetVarSize() + StackScript.Length + RedeemScript.Length.GetVarSize() + RedeemScript.Length; + void ISerializable.Deserialize(BinaryReader reader) { StackScript = reader.ReadVarBytes(); diff --git a/AntSharesCore/Core/SplitOrder.cs b/AntSharesCore/Core/SplitOrder.cs index 199fb3d38b..8d3f5477ca 100644 --- a/AntSharesCore/Core/SplitOrder.cs +++ b/AntSharesCore/Core/SplitOrder.cs @@ -22,6 +22,8 @@ public class SplitOrder : ISerializable /// public UInt160 Client; + public int Size => Amount.Size + Price.Size + Client.Size; + void ISerializable.Deserialize(BinaryReader reader) { this.Amount = reader.ReadSerializable(); diff --git a/AntSharesCore/Core/Transaction.cs b/AntSharesCore/Core/Transaction.cs index ca41965278..cebb42bf16 100644 --- a/AntSharesCore/Core/Transaction.cs +++ b/AntSharesCore/Core/Transaction.cs @@ -92,6 +92,8 @@ public IReadOnlyDictionary References } } + public virtual int Size => sizeof(TransactionType) + sizeof(byte) + Attributes.Length.GetVarSize() + Attributes.Sum(p => p.Size) + Inputs.Length.GetVarSize() + Inputs.Sum(p => p.Size) + Outputs.Length.GetVarSize() + Outputs.Sum(p => p.Size) + Scripts.Length.GetVarSize() + Scripts.Sum(p => p.Size); + /// /// 系统费用 /// @@ -298,6 +300,7 @@ public virtual JObject ToJson() { JObject json = new JObject(); json["txid"] = Hash.ToString(); + json["size"] = Size; json["type"] = Type; json["version"] = Version; json["attributes"] = Attributes.Select(p => p.ToJson()).ToArray(); diff --git a/AntSharesCore/Core/TransactionAttribute.cs b/AntSharesCore/Core/TransactionAttribute.cs index 73a9235972..12e2fbbacf 100644 --- a/AntSharesCore/Core/TransactionAttribute.cs +++ b/AntSharesCore/Core/TransactionAttribute.cs @@ -20,6 +20,17 @@ public class TransactionAttribute : ISerializable /// public byte[] Data; + public int Size + { + get + { + if (Usage == TransactionAttributeUsage.ContractHash || Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03 || Usage == TransactionAttributeUsage.Vote || (Usage >= TransactionAttributeUsage.Hash1 && Usage <= TransactionAttributeUsage.Hash15)) + return sizeof(TransactionAttributeUsage) + 32; + else + return sizeof(TransactionAttributeUsage) + Data.Length.GetVarSize() + Data.Length; + } + } + void ISerializable.Deserialize(BinaryReader reader) { Usage = (TransactionAttributeUsage)reader.ReadByte(); diff --git a/AntSharesCore/Core/TransactionInput.cs b/AntSharesCore/Core/TransactionInput.cs index b7e61bfd09..344ef93cb3 100644 --- a/AntSharesCore/Core/TransactionInput.cs +++ b/AntSharesCore/Core/TransactionInput.cs @@ -19,6 +19,8 @@ public class TransactionInput : IEquatable, ISerializable /// public ushort PrevIndex; + public int Size => PrevHash.Size + sizeof(ushort); + void ISerializable.Deserialize(BinaryReader reader) { PrevHash = reader.ReadSerializable(); diff --git a/AntSharesCore/Core/TransactionOutput.cs b/AntSharesCore/Core/TransactionOutput.cs index ea5c3c9c30..04ceb81c2a 100644 --- a/AntSharesCore/Core/TransactionOutput.cs +++ b/AntSharesCore/Core/TransactionOutput.cs @@ -24,6 +24,8 @@ public class TransactionOutput : ISerializable /// public UInt160 ScriptHash; + public int Size => AssetId.Size + Value.Size + ScriptHash.Size; + void ISerializable.Deserialize(BinaryReader reader) { this.AssetId = reader.ReadSerializable(); diff --git a/AntSharesCore/Cryptography/ECC/ECPoint.cs b/AntSharesCore/Cryptography/ECC/ECPoint.cs index f76e150ea1..41f4ef179a 100644 --- a/AntSharesCore/Cryptography/ECC/ECPoint.cs +++ b/AntSharesCore/Cryptography/ECC/ECPoint.cs @@ -20,6 +20,8 @@ public bool IsInfinity get { return X == null && Y == null; } } + public int Size => IsInfinity ? 1 : 33; + internal ECPoint(ECFieldElement x, ECFieldElement y, ECCurve curve) { if ((x != null && y == null) || (x == null && y != null)) diff --git a/AntSharesCore/Fixed8.cs b/AntSharesCore/Fixed8.cs index 8ed119653f..e9fdcba7b1 100644 --- a/AntSharesCore/Fixed8.cs +++ b/AntSharesCore/Fixed8.cs @@ -23,6 +23,8 @@ public struct Fixed8 : IComparable, IEquatable, IFormattable, IS public static readonly Fixed8 Zero = new Fixed8(); + public int Size => sizeof(long); + public Fixed8(long data) { this.value = data; diff --git a/AntSharesCore/IO/Helper.cs b/AntSharesCore/IO/Helper.cs index dee982e716..21fa0f9bcd 100644 --- a/AntSharesCore/IO/Helper.cs +++ b/AntSharesCore/IO/Helper.cs @@ -29,6 +29,16 @@ public static ISerializable AsSerializable(this byte[] value, Type type) return serializable; } + public static int GetVarSize(this int value) + { + if (value < 0xFD) + return sizeof(byte); + else if (value <= 0xFFFF) + return sizeof(byte) + sizeof(ushort); + else + return sizeof(byte) + sizeof(uint); + } + public static string ReadFixedString(this BinaryReader reader, int length) { byte[] data = reader.ReadBytes(length); diff --git a/AntSharesCore/IO/ISerializable.cs b/AntSharesCore/IO/ISerializable.cs index c17bcdb1ca..7c422af63b 100644 --- a/AntSharesCore/IO/ISerializable.cs +++ b/AntSharesCore/IO/ISerializable.cs @@ -7,12 +7,14 @@ namespace AntShares.IO /// public interface ISerializable { + int Size { get; } + /// /// 序列化 /// /// 存放序列化后的结果 void Serialize(BinaryWriter writer); - + /// /// 反序列化 /// diff --git a/AntSharesCore/Network/Message.cs b/AntSharesCore/Network/Message.cs index 80035a1e82..9927da9fcb 100644 --- a/AntSharesCore/Network/Message.cs +++ b/AntSharesCore/Network/Message.cs @@ -13,6 +13,8 @@ internal class Message : ISerializable public uint Checksum; public byte[] Payload; + public int Size => sizeof(uint) + 12 + sizeof(int) + sizeof(uint) + Payload.Length; + public static Message Create(string command, ISerializable payload = null) { return Create(command, payload == null ? new byte[0] : payload.ToArray()); diff --git a/AntSharesCore/Network/Payloads/AddrPayload.cs b/AntSharesCore/Network/Payloads/AddrPayload.cs index 75e8f2082b..c27d13d838 100644 --- a/AntSharesCore/Network/Payloads/AddrPayload.cs +++ b/AntSharesCore/Network/Payloads/AddrPayload.cs @@ -1,5 +1,6 @@ using AntShares.IO; using System.IO; +using System.Linq; namespace AntShares.Network.Payloads { @@ -7,6 +8,8 @@ internal class AddrPayload : ISerializable { public NetworkAddressWithTime[] AddressList; + public int Size => AddressList.Length.GetVarSize() + AddressList.Sum(p => p.Size); + public static AddrPayload Create(params NetworkAddressWithTime[] addresses) { return new AddrPayload diff --git a/AntSharesCore/Network/Payloads/ConsensusPayload.cs b/AntSharesCore/Network/Payloads/ConsensusPayload.cs index c10157d73b..ec2c6c042f 100644 --- a/AntSharesCore/Network/Payloads/ConsensusPayload.cs +++ b/AntSharesCore/Network/Payloads/ConsensusPayload.cs @@ -48,6 +48,8 @@ Script[] ISignable.Scripts } } + public int Size => sizeof(uint) + PrevHash.Size + sizeof(uint) + sizeof(ushort) + sizeof(uint) + Data.Length.GetVarSize() + Data.Length + 1 + Script.Size; + void ISerializable.Deserialize(BinaryReader reader) { ((ISignable)this).DeserializeUnsigned(reader); diff --git a/AntSharesCore/Network/Payloads/FilterAddPayload.cs b/AntSharesCore/Network/Payloads/FilterAddPayload.cs index 69fa61b838..ca8ab3892e 100644 --- a/AntSharesCore/Network/Payloads/FilterAddPayload.cs +++ b/AntSharesCore/Network/Payloads/FilterAddPayload.cs @@ -7,6 +7,8 @@ internal class FilterAddPayload : ISerializable { public byte[] Data; + public int Size => Data.Length.GetVarSize() + Data.Length; + void ISerializable.Deserialize(BinaryReader reader) { Data = reader.ReadVarBytes(520); diff --git a/AntSharesCore/Network/Payloads/FilterLoadPayload.cs b/AntSharesCore/Network/Payloads/FilterLoadPayload.cs index dff92e7838..38e4cc7cbf 100644 --- a/AntSharesCore/Network/Payloads/FilterLoadPayload.cs +++ b/AntSharesCore/Network/Payloads/FilterLoadPayload.cs @@ -11,6 +11,8 @@ internal class FilterLoadPayload : ISerializable public byte K; public uint Tweak; + public int Size => Filter.Length.GetVarSize() + Filter.Length + sizeof(byte) + sizeof(uint); + public static FilterLoadPayload Create(BloomFilter filter) { byte[] buffer = new byte[filter.M / 8]; diff --git a/AntSharesCore/Network/Payloads/GetBlocksPayload.cs b/AntSharesCore/Network/Payloads/GetBlocksPayload.cs index b926d829a3..847830dcf0 100644 --- a/AntSharesCore/Network/Payloads/GetBlocksPayload.cs +++ b/AntSharesCore/Network/Payloads/GetBlocksPayload.cs @@ -10,6 +10,8 @@ internal class GetBlocksPayload : ISerializable public UInt256[] HashStart; public UInt256 HashStop; + public int Size => HashStart.Length.GetVarSize() + HashStart.Sum(p => p.Size) + HashStop.Size; + public static GetBlocksPayload Create(IEnumerable hash_start, UInt256 hash_stop = null) { return new GetBlocksPayload diff --git a/AntSharesCore/Network/Payloads/HeadersPayload.cs b/AntSharesCore/Network/Payloads/HeadersPayload.cs index 9ce17fbcfc..b395eac54d 100644 --- a/AntSharesCore/Network/Payloads/HeadersPayload.cs +++ b/AntSharesCore/Network/Payloads/HeadersPayload.cs @@ -10,6 +10,8 @@ internal class HeadersPayload : ISerializable { public Header[] Headers; + public int Size => Headers.Length.GetVarSize() + Headers.Sum(p => p.Size); + public static HeadersPayload Create(IEnumerable
headers) { return new HeadersPayload diff --git a/AntSharesCore/Network/Payloads/InvPayload.cs b/AntSharesCore/Network/Payloads/InvPayload.cs index fd3f1a540f..836f50e2f4 100644 --- a/AntSharesCore/Network/Payloads/InvPayload.cs +++ b/AntSharesCore/Network/Payloads/InvPayload.cs @@ -1,6 +1,7 @@ using AntShares.IO; using System; using System.IO; +using System.Linq; namespace AntShares.Network.Payloads { @@ -9,6 +10,8 @@ internal class InvPayload : ISerializable public InventoryType Type; public UInt256[] Hashes; + public int Size => sizeof(InventoryType) + Hashes.Length.GetVarSize() + Hashes.Sum(p => p.Size); + public static InvPayload Create(InventoryType type, params UInt256[] hashes) { return new InvPayload diff --git a/AntSharesCore/Network/Payloads/MerkleBlockPayload.cs b/AntSharesCore/Network/Payloads/MerkleBlockPayload.cs index af0d38d50b..6761147f6a 100644 --- a/AntSharesCore/Network/Payloads/MerkleBlockPayload.cs +++ b/AntSharesCore/Network/Payloads/MerkleBlockPayload.cs @@ -13,6 +13,8 @@ internal class MerkleBlockPayload : BlockBase public UInt256[] Hashes; public byte[] Flags; + public override int Size => base.Size + sizeof(int) + Hashes.Length.GetVarSize() + Hashes.Sum(p => p.Size) + Flags.Length.GetVarSize() + Flags.Length; + public static MerkleBlockPayload Create(Block block, BitArray flags) { MerkleTree tree = new MerkleTree(block.Transactions.Select(p => p.Hash).ToArray()); diff --git a/AntSharesCore/Network/Payloads/NetworkAddressWithTime.cs b/AntSharesCore/Network/Payloads/NetworkAddressWithTime.cs index 37602a6a15..3561e61063 100644 --- a/AntSharesCore/Network/Payloads/NetworkAddressWithTime.cs +++ b/AntSharesCore/Network/Payloads/NetworkAddressWithTime.cs @@ -14,6 +14,8 @@ internal class NetworkAddressWithTime : ISerializable public ulong Services; public IPEndPoint EndPoint; + public int Size => sizeof(uint) + sizeof(ulong) + 16 + sizeof(ushort); + public static NetworkAddressWithTime Create(IPEndPoint endpoint, ulong services, uint timestamp) { return new NetworkAddressWithTime diff --git a/AntSharesCore/Network/Payloads/VersionPayload.cs b/AntSharesCore/Network/Payloads/VersionPayload.cs index 7f7cdcc23f..739ce01d61 100644 --- a/AntSharesCore/Network/Payloads/VersionPayload.cs +++ b/AntSharesCore/Network/Payloads/VersionPayload.cs @@ -2,6 +2,7 @@ using AntShares.IO; using System; using System.IO; +using System.Text; namespace AntShares.Network.Payloads { @@ -16,6 +17,8 @@ internal class VersionPayload : ISerializable public uint StartHeight; public bool Relay; + public int Size => sizeof(uint) + sizeof(ulong) + sizeof(uint) + sizeof(ushort) + sizeof(uint) + Encoding.UTF8.GetByteCount(UserAgent).GetVarSize() + Encoding.UTF8.GetByteCount(UserAgent) + sizeof(uint) + sizeof(bool); + public static VersionPayload Create(int port, uint nonce, string userAgent) { return new VersionPayload diff --git a/AntSharesCore/UIntBase.cs b/AntSharesCore/UIntBase.cs index e88d5ecb68..1bfc62727e 100644 --- a/AntSharesCore/UIntBase.cs +++ b/AntSharesCore/UIntBase.cs @@ -9,6 +9,8 @@ public abstract class UIntBase : IEquatable, ISerializable { private byte[] data_bytes; + public int Size => data_bytes.Length; + protected UIntBase(int bytes, byte[] value) { if (value == null) diff --git a/AntSharesCore/Wallets/Contract.cs b/AntSharesCore/Wallets/Contract.cs index edb96ee5d0..fb4c122685 100644 --- a/AntSharesCore/Wallets/Contract.cs +++ b/AntSharesCore/Wallets/Contract.cs @@ -67,6 +67,8 @@ public UInt160 ScriptHash } } + public int Size => PublicKeyHash.Size + ParameterList.Length.GetVarSize() + ParameterList.Length + RedeemScript.Length.GetVarSize() + RedeemScript.Length; + public static Contract Create(UInt160 publicKeyHash, ContractParameterType[] parameterList, byte[] redeemScript) { return new Contract diff --git a/AntSharesDaemon/App.config b/AntSharesDaemon/App.config index 973b8a9f92..757a49376a 100644 --- a/AntSharesDaemon/App.config +++ b/AntSharesDaemon/App.config @@ -16,6 +16,14 @@ 10333 + + + + http://*:10332/ + + + diff --git a/AntSharesDaemon/Network/RPC/RpcServer.cs b/AntSharesDaemon/Network/RPC/RpcServer.cs index 4cda450235..77e864af25 100644 --- a/AntSharesDaemon/Network/RPC/RpcServer.cs +++ b/AntSharesDaemon/Network/RPC/RpcServer.cs @@ -13,12 +13,6 @@ namespace AntShares.Network.RPC { internal class RpcServer : IDisposable { -#if TESTNET - private const string DEFAULT_URI_PREFIX = "http://*:20332/"; -#else - private const string DEFAULT_URI_PREFIX = "http://*:10332/"; -#endif - private LocalNode localNode; private HttpListener listener = new HttpListener(); private bool stopped = false; @@ -92,9 +86,18 @@ private JObject InternalCall(string method, JArray _params) throw new RpcException(-100, "Unknown block"); bool verbose = _params.Count >= 2 && _params[1].AsBooleanOrDefault(false); if (verbose) - return block.ToJson(); + { + JObject json = block.ToJson(); + json["confirmations"] = Blockchain.Default.Height - block.Height + 1; + UInt256 hash = Blockchain.Default.GetNextBlockHash(block.Hash); + if (hash != null) + json["nextblockhash"] = hash.ToString(); + return json; + } else + { return block.ToArray().ToHexString(); + } } case "getblockcount": return Blockchain.Default.Height + 1; @@ -120,7 +123,13 @@ private JObject InternalCall(string method, JArray _params) if (verbose) { JObject json = tx.ToJson(); - json["height"] = height; + if (height >= 0) + { + Header header = Blockchain.Default.GetHeader((uint)height); + json["blockhash"] = header.Hash.ToString(); + json["confirmations"] = Blockchain.Default.Height - header.Height + 1; + json["blocktime"] = header.Timestamp; + } return json; } else @@ -266,10 +275,9 @@ private JObject ProcessRequest(JObject request) public async void Start(params string[] uriPrefix) { if (uriPrefix.Length == 0) - listener.Prefixes.Add(DEFAULT_URI_PREFIX); - else - foreach (string prefix in uriPrefix) - listener.Prefixes.Add(prefix); + throw new ArgumentException(); + foreach (string prefix in uriPrefix) + listener.Prefixes.Add(prefix); listener.Start(); while (listener.IsListening) { diff --git a/AntSharesDaemon/Properties/Settings.Designer.cs b/AntSharesDaemon/Properties/Settings.Designer.cs index 274e126535..5e192c98b2 100644 --- a/AntSharesDaemon/Properties/Settings.Designer.cs +++ b/AntSharesDaemon/Properties/Settings.Designer.cs @@ -40,5 +40,16 @@ public ushort NodePort { return ((ushort)(this["NodePort"])); } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("\r\n\r\n http://*:10332/\r\n")] + public global::System.Collections.Specialized.StringCollection UriPrefix { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["UriPrefix"])); + } + } } } diff --git a/AntSharesDaemon/Properties/Settings.settings b/AntSharesDaemon/Properties/Settings.settings index 3e1b3fec4b..617cdc905e 100644 --- a/AntSharesDaemon/Properties/Settings.settings +++ b/AntSharesDaemon/Properties/Settings.settings @@ -8,5 +8,11 @@ 10333 + + <?xml version="1.0" encoding="utf-16"?> +<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <string>http://*:10332/</string> +</ArrayOfString> + \ No newline at end of file diff --git a/AntSharesDaemon/Shell/MainService.cs b/AntSharesDaemon/Shell/MainService.cs index 0734469674..4b9bf9070a 100644 --- a/AntSharesDaemon/Shell/MainService.cs +++ b/AntSharesDaemon/Shell/MainService.cs @@ -407,7 +407,7 @@ protected internal override void OnStart(string[] args) if (args.Length >= 1 && args[0] == "/rpc") { rpc = new RpcServer(LocalNode); - rpc.Start(); + rpc.Start(Settings.Default.UriPrefix.OfType().ToArray()); } }