diff --git a/AntSharesCore/Core/Blockchain.cs b/AntSharesCore/Core/Blockchain.cs index b093f529fd..6a0ff714d4 100644 --- a/AntSharesCore/Core/Blockchain.cs +++ b/AntSharesCore/Core/Blockchain.cs @@ -26,7 +26,7 @@ public abstract class Blockchain : IDisposable ECPoint.DecodePoint("039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf9".HexToBytes(), ECCurve.Secp256r1), ECPoint.DecodePoint("038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc5425579".HexToBytes(), ECCurve.Secp256r1), }; - public static readonly Block GenesisBlock = "000000000000000000000000000000000000000000000000000000000000000000000000e9b80ae02a31a55454620f682f6e41f1c4ab825b619f112dd33ce6cda97344ed1d496856000000001dac2b7c00000000d5b21f2e11a9795a22a482f342f53634b5a8cf3afd450140218268890bffef0632d2cc07aee12a31ea715e90df682c49118042bffd58fc661100ae6270a1ac3492a1b0c35e89f41d5243647b2ef2ef917073290fdbe5148640657634ffc7841c6e293aff9d05a4c00bbf830cc75da584835f56d95f1d491818d0ab7139076ba5779b88bcfa2e755bd0364ba5008ce0af10f6c744b01ce8f42e405ebfe773daad02f76d3fe1af637df1632e5fb9ebeb480b11c0082a76fc7f7699c47d0d22c5a74eefda81e18893faffdf81842b92b16423b7e76ad1d877867b4b4034b5c455c3acb90872d990d11a032ebe1f9cca1ef2221e9c2aedbecbe70ee925107c07fa1c31800590f80457f7137b1509f8506a4ba8316a7798dd425133c0d840cfe42c54fb8b5d0497dbc7c4ad49b88cefc1b4ef95b6484d245680f193b2fd0d4c10e17c8cc93411f80882ad2e737ef0862f329bf8862b788e07b49d36175413ad53210209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee821026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d2221038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc542557921039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf955ae0200000000000000004000565b7b276c616e67273a277a682d434e272c276e616d65273a27e5b08fe89a81e882a128e6b58be8af9529277d2c7b276c616e67273a27656e272c276e616d65273a27416e74536861726528546573744e657429277d5d0000c16ff2862300d5b21f2e11a9795a22a482f342f53634b5a8cf3ad5b21f2e11a9795a22a482f342f53634b5a8cf3a000001fd4501409adbbd94f33abe4796861f904d3a3804c434e7795944fbff5241418c2a408f127691197f8dd3ea09d5dacd14cdcb5496d4803889dc6e36a739b2b88cea270473401f5c056b1bad0f92b97b471feebaeb277ece3abdd1478b723950aaeff6ae4202913ea7f9279600054df03c66cc889f6e924e76e57d9e00c706e0a3670b70008540908ea943aed5d1c78db36fcfe00d49d7aafe469a0f3afba16832c85f79641976631e5a89b2489f9c888e0e65a3cf8e1e4d1d207068c140ca56c33defb48dced040137416609c6c92663d741d86162f67b54e9523e1bbb36fe8f63fc15868bc88edc42a19851336b18336327d15607fa12a3bd483b83b9db95d48e2b60459fdf3aa40e6d6d8670e6687ba8751f4c5c241e6c2db038079b43ec201f68127f0b227fc99cf92037941ad2845c6beed85f683a5ba19e7400cc93ed824c16a967c471f2134ad53210209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee821026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d2221038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc542557921039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf955ae".HexToBytes().AsSerializable(); + public static readonly Block GenesisBlock = "0000000000000000000000000000000000000000000000000000000000000000000000003e237594e6e2b0cdd92aea5beecab6662662820597f1424a935c4dfc362bfafc81fc7856000000001dac2b7c00000000d5b21f2e11a9795a22a482f342f53634b5a8cf3afd450140af61f3ede868743262d6efe56dec7fcf6f9c75f42e4289e9165d26a08b870fc65f8a3b2b72f52fed206b9f215f1b993ebb3fce0a27b70d8de9782edb900b12094027bec17f618362a3beb8da43850d192880ab7e77c6d0c7bd12a81669f8afc38fca431adc9c4603ae2a70390ab0945b3484fa6c405742b409be9eb952ada981e8408d4584f68a66962e5a6b4454847bab196776432331a8ee2e538de117f7b4d8371dbcf177581b9e02c7db07253fd653fb249b60597a737d565d6b1209805bbfce40f9a17482f956e0567378f444f2f5256b4c15d4a425302ff96da3530d4e07c47eb08d32ebdd104db01bfb09e4c34292a94d26cdc8b6efd3a86f6fbceff44bfb59404dacce9dda32ec14f17448d6422f95dab8876d75371004183909819090021c58d71c070c66d82591a2a21a40d5cd2af12121b33403280735de1bc6aaf234dd71ad53210209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee821026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d2221038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc542557921039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf955ae020000000000000000004000565b7b276c616e67273a277a682d434e272c276e616d65273a27e5b08fe89a81e882a128e6b58be8af9529277d2c7b276c616e67273a27656e272c276e616d65273a27416e74536861726528546573744e657429277d5d0000c16ff28623000327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee8d5b21f2e11a9795a22a482f342f53634b5a8cf3a000000024140925b0d1dc68ceb21337886439f2cd40009746fe3332b9149d0214ae7c9d3c9d2056d4adb8d5d14d7ff07447b3c71032508b36b81b7014921c819a042dbfbb60a23210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee8acfd450140c85d5de0f90a7ae9e268ef2b092a63d39c9022c7fce44714a7c9171d58304712cbe90cca5718c210ccf6e99cc3a0a1ac27ea52a1f3b18c1d60b9c4842c88153c4049a8674b3637b7b72e2950b75b8333d0294be7d46fe44309e1cc9d47ffa1e55c3b2d9968267316b1425a54369e55c2103915f064a2d479cd34bf665f2ef0acba40c397b172d90401dd38e965489e36dcdf1129cc28c387dfc2d19d2a7d1c9c35e8344fda9bafc7b80be652a892f506ae98013111d2e332a6afe1bf2a98bb92aee34023e4565d362b9d8708c5a661c9b5f3973d4deaa24be18122a97c68286aed76523d79f13afc1ffd75b369afe799c6516ed25d3862c2d6dc9693f9bc360563410f40819abbd4c52c98360f0b54b67e62e1726a3a5704cf4d09ce0a270226ac22d4397158785d5c5b27b05a041a7b52cd993722afff807b9ed227799c06fe6d321e51ad53210209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee821026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d2221038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc542557921039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf955ae".HexToBytes().AsSerializable(); public static readonly RegisterTransaction AntShare = (RegisterTransaction)GenesisBlock.Transactions[1]; public static readonly RegisterTransaction AntCoin = new RegisterTransaction { @@ -39,6 +39,7 @@ public abstract class Blockchain : IDisposable Amount = Fixed8.FromDecimal(100000000), Issuer = ECCurve.Secp256r1.Infinity, Admin = new UInt160(), + Attributes = new TransactionAttribute[0], Inputs = new TransactionInput[0], Outputs = new TransactionOutput[0], Scripts = new Script[0] diff --git a/AntSharesCore/Core/ContractTransaction.cs b/AntSharesCore/Core/ContractTransaction.cs index 05f5945c5c..d3e00db176 100644 --- a/AntSharesCore/Core/ContractTransaction.cs +++ b/AntSharesCore/Core/ContractTransaction.cs @@ -1,43 +1,10 @@ -using AntShares.IO; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace AntShares.Core +namespace AntShares.Core { public class ContractTransaction : Transaction { - public TransactionAttribute[] Attributes; - public ContractTransaction() : base(TransactionType.ContractTransaction) { } - - protected override void DeserializeExclusiveData(BinaryReader reader) - { - this.Attributes = reader.ReadSerializableArray(); - } - - public override UInt160[] GetScriptHashesForVerifying() - { - HashSet hashes = new HashSet(base.GetScriptHashesForVerifying()); - foreach (var group in Outputs.GroupBy(p => p.AssetId)) - { - RegisterTransaction tx = Blockchain.Default.GetTransaction(group.Key) as RegisterTransaction; - if (tx == null) throw new InvalidOperationException(); - if (tx.AssetType == AssetType.Share) - { - hashes.UnionWith(group.Select(p => p.ScriptHash)); - } - } - return hashes.OrderBy(p => p).ToArray(); - } - - protected override void SerializeExclusiveData(BinaryWriter writer) - { - writer.Write(Attributes); - } } } diff --git a/AntSharesCore/Core/IssueTransaction.cs b/AntSharesCore/Core/IssueTransaction.cs index 4bd18b5e34..3ada5e50a5 100644 --- a/AntSharesCore/Core/IssueTransaction.cs +++ b/AntSharesCore/Core/IssueTransaction.cs @@ -1,43 +1,30 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; namespace AntShares.Core { public class IssueTransaction : Transaction { - public override Fixed8 SystemFee => Outputs.All(p => p.AssetId == Blockchain.AntShare.Hash) ? Fixed8.Zero : Fixed8.FromDecimal(500); + public override Fixed8 SystemFee => Outputs.All(p => p.AssetId == Blockchain.AntShare.Hash || p.AssetId == Blockchain.AntCoin.Hash) ? Fixed8.Zero : Fixed8.FromDecimal(500); public IssueTransaction() - : base(TransactionType.IssueTransaction) - { - } - - protected override void DeserializeExclusiveData(BinaryReader reader) + : base(TransactionType.IssueTransaction) { } public override UInt160[] GetScriptHashesForVerifying() { HashSet hashes = new HashSet(base.GetScriptHashesForVerifying()); - foreach (var group in Outputs.GroupBy(p => p.AssetId)) + foreach (TransactionResult result in GetTransactionResults().Where(p => p.Amount < Fixed8.Zero)) { - RegisterTransaction tx = Blockchain.Default.GetTransaction(group.Key) as RegisterTransaction; + RegisterTransaction tx = Blockchain.Default.GetTransaction(result.AssetId) as RegisterTransaction; if (tx == null) throw new InvalidOperationException(); hashes.Add(tx.Admin); - if (tx.AssetType == AssetType.Share) - { - hashes.UnionWith(group.Select(p => p.ScriptHash)); - } } return hashes.OrderBy(p => p).ToArray(); } - protected override void SerializeExclusiveData(BinaryWriter writer) - { - } - public override bool Verify() { if (!base.Verify()) return false; diff --git a/AntSharesCore/Core/RegisterTransaction.cs b/AntSharesCore/Core/RegisterTransaction.cs index f3594724a5..1e42873ead 100644 --- a/AntSharesCore/Core/RegisterTransaction.cs +++ b/AntSharesCore/Core/RegisterTransaction.cs @@ -28,6 +28,8 @@ public class RegisterTransaction : Transaction public ECPoint Issuer; public UInt160 Admin; + private static readonly string ShareName = "[{'lang':'zh-CN','name':'股权'},{'lang':'en','name':'Share'}]"; + public override Fixed8 SystemFee => Fixed8.FromDecimal(10000); public RegisterTransaction() @@ -55,16 +57,10 @@ protected override void DeserializeExclusiveData(BinaryReader reader) private Dictionary _names; public string GetName(CultureInfo culture = null) { - if (AssetType == AssetType.Share) - { - //TODO: 获取证书上的名称 - //股权的名称由证书上的公司名称决定,不能自定义 - //目前实名认证的相关设计还没有完全定型,所以暂时先不实现股权资产的名称查询 - throw new NotImplementedException(); - } + string name_str = AssetType == AssetType.Share ? ShareName : Name; if (_names == null) { - _names = ((JArray)JObject.Parse(Name)).ToDictionary(p => CultureInfo.GetCultureInfo(p["lang"].AsString()), p => p["name"].AsString()); + _names = ((JArray)JObject.Parse(name_str)).ToDictionary(p => CultureInfo.GetCultureInfo(p["lang"].AsString()), p => p["name"].AsString()); } if (culture == null) culture = CultureInfo.CurrentCulture; if (_names.ContainsKey(culture)) @@ -98,9 +94,6 @@ protected override void SerializeExclusiveData(BinaryWriter writer) public override string ToString() { - //TODO: 在资产名称的后面加上发行者的名称 - //如:CNY(由xxx公司发行) - //用以区分不同主体发行的相同名称的资产 return GetName(); } } diff --git a/AntSharesCore/Core/Transaction.cs b/AntSharesCore/Core/Transaction.cs index 9c79275e7b..99e8e0f689 100644 --- a/AntSharesCore/Core/Transaction.cs +++ b/AntSharesCore/Core/Transaction.cs @@ -12,6 +12,7 @@ namespace AntShares.Core public abstract class Transaction : Inventory, ISignable { public readonly TransactionType Type; + public TransactionAttribute[] Attributes; public TransactionInput[] Inputs; public TransactionOutput[] Outputs; public Script[] Scripts; @@ -71,7 +72,9 @@ public override void Deserialize(BinaryReader reader) Scripts = reader.ReadSerializableArray