diff --git a/neo.UnitTests/Ledger/UT_ContractState.cs b/neo.UnitTests/Ledger/UT_ContractState.cs index 87f1d7ac88..097e9c3e04 100644 --- a/neo.UnitTests/Ledger/UT_ContractState.cs +++ b/neo.UnitTests/Ledger/UT_ContractState.cs @@ -1,4 +1,4 @@ -using FluentAssertions; +using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.IO.Json; @@ -92,7 +92,7 @@ public void TestToJson() { JObject json = contract.ToJson(); json["hash"].AsString().Should().Be("0x820944cfdc70976602d71b0091445eedbc661bc5"); - json["script"].AsString().Should().Be("01"); + json["script"].AsString().Should().Be("AQ=="); json["manifest"].AsString().Should().Be(manifest.ToJson().AsString()); } } diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs index f27421dd74..a26741c732 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs @@ -210,7 +210,7 @@ public void ToJson() JObject scObj = ((JArray)jObj["witnesses"])[0]; scObj["invocation"].AsString().Should().Be(""); - scObj["verification"].AsString().Should().Be("51"); + scObj["verification"].AsString().Should().Be("UQ=="); jObj["tx"].Should().NotBeNull(); JArray txObj = (JArray)jObj["tx"]; diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index d52867e99e..217e207f83 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -1093,7 +1093,7 @@ public void ToJson() ((JArray)jObj["attributes"]).Count.Should().Be(0); ((JArray)jObj["cosigners"]).Count.Should().Be(0); jObj["net_fee"].AsString().Should().Be("0"); - jObj["script"].AsString().Should().Be("4220202020202020202020202020202020202020202020202020202020202020"); + jObj["script"].AsString().Should().Be("QiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA="); jObj["sys_fee"].AsString().Should().Be("4200000000"); } } diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 1ef1e2d120..502317e604 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -146,8 +146,8 @@ public void ToJson() JObject json = uut.ToJson(); Assert.IsTrue(json.ContainsProperty("invocation")); Assert.IsTrue(json.ContainsProperty("verification")); - Assert.AreEqual(json["invocation"].AsString(), "2020"); - Assert.AreEqual(json["verification"].AsString(), "202020"); + Assert.AreEqual(json["invocation"].AsString(), "ICA="); + Assert.AreEqual(json["verification"].AsString(), "ICAg"); } } } diff --git a/neo.UnitTests/Network/RPC/Models/UT_RpcNep5Balance.cs b/neo.UnitTests/Network/RPC/Models/UT_RpcNep5Balance.cs index ee32c1998e..9131db811a 100644 --- a/neo.UnitTests/Network/RPC/Models/UT_RpcNep5Balance.cs +++ b/neo.UnitTests/Network/RPC/Models/UT_RpcNep5Balance.cs @@ -45,7 +45,7 @@ public void TestToJson() balance.Amount = BigInteger.Zero; balance.LastUpdatedBlock = 0; var json = balance.ToJson(); - json["asset_hash"].AsString().Should().Be("0000000000000000000000000000000000000000"); + json["asset_hash"].AsString().Should().Be("0x0000000000000000000000000000000000000000"); json["amount"].AsNumber().Should().Be(0); json["last_updated_block"].AsNumber().Should().Be(0); } @@ -54,7 +54,7 @@ public void TestToJson() public void TestFromJson() { var json = new JObject(); - json["asset_hash"] = "0000000000000000000000000000000000000000"; + json["asset_hash"] = "0x0000000000000000000000000000000000000000"; json["amount"] = "0"; json["last_updated_block"] = "0"; var rpcNep5Balance = RpcNep5Balance.FromJson(json); diff --git a/neo.UnitTests/SmartContract/Manifest/UT_ContractManifest.cs b/neo.UnitTests/SmartContract/Manifest/UT_ContractManifest.cs index 910f30b019..5c2a99ff56 100644 --- a/neo.UnitTests/SmartContract/Manifest/UT_ContractManifest.cs +++ b/neo.UnitTests/SmartContract/Manifest/UT_ContractManifest.cs @@ -77,7 +77,7 @@ public void ParseFromJson_Trust() [TestMethod] public void ParseFromJson_Groups() { - var json = @"{""groups"":[{""pubKey"":""03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"",""signature"":""41414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141""}],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[]}"; + var json = @"{""groups"":[{""pubKey"":""03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"",""signature"":""QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQQ==""}],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[]}"; var manifest = ContractManifest.Parse(json); Assert.AreEqual(manifest.ToString(), json); diff --git a/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs b/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs index 0b06260b24..0e035349d1 100644 --- a/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs +++ b/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs @@ -1,4 +1,4 @@ -using FluentAssertions; +using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Network.P2P.Payloads; @@ -46,13 +46,13 @@ public void TestToString() var context = new ContractParametersContext(tx); context.Add(contract, 0, new byte[] { 0x01 }); string str = context.ToString(); - str.Should().Be("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"0000000000f277f1144035a43897f9fa115258eac015adcabe000000000000000000000000000000000000000000000100\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"21026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca1668747476aa\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"01\"}]}}}"); + str.Should().Be("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAADyd\\/EUQDWkOJf5\\u002BhFSWOrAFa3KvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA==\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}"); } [TestMethod] public void TestParse() { - var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"0000000000f277f1144035a43897f9fa115258eac015adcabe000000000000000000000000000000000000000000000100\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"21026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca1668747476aa\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"01\"}]}}}"); + var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAADyd\\/EUQDWkOJf5\\u002BhFSWOrAFa3KvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA==\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}"); ret.ScriptHashes[0].ToString().Should().Be("0xbecaad15c0ea585211faf99738a4354014f177f2"); ((Transaction)ret.Verifiable).Script.ToHexString().Should().Be(new byte[1].ToHexString()); } diff --git a/neo.UnitTests/SmartContract/UT_JsonSerializer.cs b/neo.UnitTests/SmartContract/UT_JsonSerializer.cs index 9863d72b0d..ed9c9cd72b 100644 --- a/neo.UnitTests/SmartContract/UT_JsonSerializer.cs +++ b/neo.UnitTests/SmartContract/UT_JsonSerializer.cs @@ -268,7 +268,7 @@ public void Serialize_Array_Bool_Str_Num() var json = JsonSerializer.Serialize(entry).ToString(); - Assert.AreEqual(json, "[true,\"74657374\",123]"); + Assert.AreEqual(json, "[true,\"dGVzdA==\",123]"); } [TestMethod] @@ -297,7 +297,7 @@ public void Serialize_Array_OfArray() var json = JsonSerializer.Serialize(entry).ToString(); - Assert.AreEqual(json, "[[true,\"7465737431\",123],[true,\"7465737432\",321]]"); + Assert.AreEqual(json, "[[true,\"dGVzdDE=\",123],[true,\"dGVzdDI=\",321]]"); } [TestMethod] diff --git a/neo.UnitTests/SmartContract/UT_Syscalls.cs b/neo.UnitTests/SmartContract/UT_Syscalls.cs index d24850de40..b778f63d94 100644 --- a/neo.UnitTests/SmartContract/UT_Syscalls.cs +++ b/neo.UnitTests/SmartContract/UT_Syscalls.cs @@ -76,7 +76,7 @@ public void System_Blockchain_GetBlock() Assert.AreEqual(1, engine.ResultStack.Count); Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteArray)); Assert.AreEqual(engine.ResultStack.Pop().GetByteArray().ToHexString(), - "5b2235316138373966636161303339626461663437353436306637316334616130383562353964313833616239313764356437363762333865613738323766356266222c332c2230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c2230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c322c312c2230303030303030303030303030303030303030303030303030303030303030303030303030303030222c315d"); + "5b22556168355c2f4b6f446d39723064555950636353714346745a30594f726b583164646e7334366e676e3962383d222c332c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c322c312c224141414141414141414141414141414141414141414141414141413d222c315d"); Assert.AreEqual(0, engine.ResultStack.Count); // Clean @@ -127,7 +127,7 @@ public void System_ExecutionEngine_GetScriptContainer() Assert.AreEqual(1, engine.ResultStack.Count); Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteArray)); Assert.AreEqual(engine.ResultStack.Pop().GetByteArray().ToHexString(), - @"5b2266613434383036313834373332636138613136363037356430306133643861326531353462333337313333333138303336356561643732373561663132666264222c362c342c2266666666666666666666666666666666666666666666666666666666666666666666666666666666222c332c322c352c223031225d"); + @"5b225c75303032426b53415959527a4c4b69685a676464414b50596f754655737a63544d7867445a6572584a3172784c37303d222c362c342c225c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f5c2f383d222c332c322c352c2241513d3d225d"); Assert.AreEqual(0, engine.ResultStack.Count); } } diff --git a/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs b/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs index ed84b1bad3..0477b8a595 100644 --- a/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs +++ b/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs @@ -104,7 +104,7 @@ public void TestGetKeyWithString() public void TestToJson() { JObject nep6contract = new JObject(); - nep6contract["script"] = "2103603f3880eb7aea0ad4500893925e4a42fea48a44ee6f898a10b3c7ce05d2a267ac"; + nep6contract["script"] = "IQNgPziA63rqCtRQCJOSXkpC/qSKRO5viYoQs8fOBdKiZ6w="; JObject parameters = new JObject(); parameters["type"] = 0x00; parameters["name"] = "Sig"; @@ -121,7 +121,7 @@ public void TestToJson() json["isDefault"].ToString().Should().Be("false"); json["lock"].ToString().Should().Be("false"); json["key"].Should().BeNull(); - json["contract"]["script"].ToString().Should().Be("\"2103603f3880eb7aea0ad4500893925e4a42fea48a44ee6f898a10b3c7ce05d2a267ac\""); + json["contract"]["script"].ToString().Should().Be("\"IQNgPziA63rqCtRQCJOSXkpC\\/qSKRO5viYoQs8fOBdKiZ6w=\""); json["extra"].Should().BeNull(); _account.Contract = null; diff --git a/neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs b/neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs index 3f4e7b3a63..1594672946 100644 --- a/neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs +++ b/neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs @@ -3,6 +3,7 @@ using Neo.IO.Json; using Neo.SmartContract; using Neo.Wallets.NEP6; +using System; namespace Neo.UnitTests.Wallets.NEP6 { @@ -19,7 +20,7 @@ public void TestFromNullJson() [TestMethod] public void TestFromJson() { - string json = "{\"script\":\"2103ef891df4c0b7eefb937d21ea0fb88cde8e0d82a7ff11872b5e7047969dafb4eb68747476aa\"," + + string json = "{\"script\":\"IQPviR30wLfu+5N9IeoPuIzejg2Cp/8RhytecEeWna+062h0dHaq\"," + "\"parameters\":[{\"name\":\"signature\",\"type\":\"Signature\"}],\"deployed\":false}"; JObject @object = JObject.Parse(json); @@ -45,7 +46,7 @@ public void TestToJson() JObject @object = nep6Contract.ToJson(); JString jString = (JString)@object["script"]; - jString.Value.Should().Be(nep6Contract.Script.ToHexString()); + jString.Value.Should().Be(Convert.ToBase64String(nep6Contract.Script, Base64FormattingOptions.None)); JBoolean jBoolean = (JBoolean)@object["deployed"]; jBoolean.Value.Should().BeFalse(); diff --git a/neo/Ledger/ContractState.cs b/neo/Ledger/ContractState.cs index c369e5d59f..ea1860668e 100644 --- a/neo/Ledger/ContractState.cs +++ b/neo/Ledger/ContractState.cs @@ -4,6 +4,7 @@ using Neo.SmartContract.Manifest; using Neo.VM; using Neo.VM.Types; +using System; using System.IO; namespace Neo.Ledger @@ -62,7 +63,7 @@ public JObject ToJson() { JObject json = new JObject(); json["hash"] = ScriptHash.ToString(); - json["script"] = Script.ToHexString(); + json["script"] = Convert.ToBase64String(Script); json["manifest"] = Manifest.ToJson(); return json; } @@ -70,7 +71,7 @@ public JObject ToJson() public static ContractState FromJson(JObject json) { ContractState contractState = new ContractState(); - contractState.Script = json["script"].AsString().HexToBytes(); + contractState.Script = Convert.FromBase64String(json["script"].AsString()); contractState.Manifest = ContractManifest.FromJson(json["manifest"]); return contractState; } @@ -82,8 +83,8 @@ public StackItem ToStackItem() new StackItem[] { new ByteArray(Script), - new Boolean(HasStorage), - new Boolean(Payable), + new VM.Types.Boolean(HasStorage), + new VM.Types.Boolean(Payable), } ); } diff --git a/neo/Network/P2P/Payloads/Transaction.cs b/neo/Network/P2P/Payloads/Transaction.cs index af38ef6dcc..c135185272 100644 --- a/neo/Network/P2P/Payloads/Transaction.cs +++ b/neo/Network/P2P/Payloads/Transaction.cs @@ -183,7 +183,7 @@ public JObject ToJson() json["valid_until_block"] = ValidUntilBlock; json["attributes"] = Attributes.Select(p => p.ToJson()).ToArray(); json["cosigners"] = Cosigners.Select(p => p.ToJson()).ToArray(); - json["script"] = Script.ToHexString(); + json["script"] = Convert.ToBase64String(Script); json["witnesses"] = Witnesses.Select(p => p.ToJson()).ToArray(); return json; } @@ -199,7 +199,7 @@ public static Transaction FromJson(JObject json) tx.ValidUntilBlock = uint.Parse(json["valid_until_block"].AsString()); tx.Attributes = ((JArray)json["attributes"]).Select(p => TransactionAttribute.FromJson(p)).ToArray(); tx.Cosigners = ((JArray)json["cosigners"]).Select(p => Cosigner.FromJson(p)).ToArray(); - tx.Script = json["script"].AsString().HexToBytes(); + tx.Script = Convert.FromBase64String(json["script"].AsString()); tx.Witnesses = ((JArray)json["witnesses"]).Select(p => Witness.FromJson(p)).ToArray(); return tx; } diff --git a/neo/Network/P2P/Payloads/TransactionAttribute.cs b/neo/Network/P2P/Payloads/TransactionAttribute.cs index 5adc34db8e..fa92010004 100644 --- a/neo/Network/P2P/Payloads/TransactionAttribute.cs +++ b/neo/Network/P2P/Payloads/TransactionAttribute.cs @@ -30,7 +30,7 @@ public JObject ToJson() { JObject json = new JObject(); json["usage"] = Usage; - json["data"] = Data.ToHexString(); + json["data"] = Convert.ToBase64String(Data); return json; } @@ -38,7 +38,7 @@ public static TransactionAttribute FromJson(JObject json) { TransactionAttribute transactionAttribute = new TransactionAttribute(); transactionAttribute.Usage = (TransactionAttributeUsage)(byte.Parse(json["usage"].AsString())); - transactionAttribute.Data = json["data"].AsString().HexToBytes(); + transactionAttribute.Data = Convert.FromBase64String(json["data"].AsString()); return transactionAttribute; } } diff --git a/neo/Network/P2P/Payloads/Witness.cs b/neo/Network/P2P/Payloads/Witness.cs index 227d810a39..55ba4f2564 100644 --- a/neo/Network/P2P/Payloads/Witness.cs +++ b/neo/Network/P2P/Payloads/Witness.cs @@ -1,7 +1,7 @@ using Neo.IO; using Neo.IO.Json; using Neo.SmartContract; -using Neo.VM; +using System; using System.IO; namespace Neo.Network.P2P.Payloads @@ -44,16 +44,16 @@ void ISerializable.Serialize(BinaryWriter writer) public JObject ToJson() { JObject json = new JObject(); - json["invocation"] = InvocationScript.ToHexString(); - json["verification"] = VerificationScript.ToHexString(); + json["invocation"] = Convert.ToBase64String(InvocationScript); + json["verification"] = Convert.ToBase64String(VerificationScript); return json; } public static Witness FromJson(JObject json) { Witness witness = new Witness(); - witness.InvocationScript = json["invocation"].AsString().HexToBytes(); - witness.VerificationScript = json["verification"].AsString().HexToBytes(); + witness.InvocationScript = Convert.FromBase64String(json["invocation"].AsString()); + witness.VerificationScript = Convert.FromBase64String(json["verification"].AsString()); return witness; } } diff --git a/neo/Network/RPC/Models/RpcNep5Balances.cs b/neo/Network/RPC/Models/RpcNep5Balances.cs index b471ab4545..74fe7be729 100644 --- a/neo/Network/RPC/Models/RpcNep5Balances.cs +++ b/neo/Network/RPC/Models/RpcNep5Balances.cs @@ -39,7 +39,7 @@ public class RpcNep5Balance public JObject ToJson() { JObject json = new JObject(); - json["asset_hash"] = AssetHash.ToArray().ToHexString(); + json["asset_hash"] = AssetHash.ToString(); json["amount"] = Amount.ToString(); json["last_updated_block"] = LastUpdatedBlock.ToString(); return json; diff --git a/neo/SmartContract/ContractParameter.cs b/neo/SmartContract/ContractParameter.cs index cae59229b8..5cdc520808 100644 --- a/neo/SmartContract/ContractParameter.cs +++ b/neo/SmartContract/ContractParameter.cs @@ -66,7 +66,7 @@ public static ContractParameter FromJson(JObject json) { case ContractParameterType.Signature: case ContractParameterType.ByteArray: - parameter.Value = json["value"].AsString().HexToBytes(); + parameter.Value = Convert.FromBase64String(json["value"].AsString()); break; case ContractParameterType.Boolean: parameter.Value = json["value"].AsBoolean(); @@ -147,7 +147,7 @@ private static JObject ToJson(ContractParameter parameter, HashSet ContractParameter.FromJson(p)).ToArray(), Signatures = json["signatures"]?.Properties.Select(p => new { PublicKey = ECPoint.Parse(p.Key, ECCurve.Secp256r1), - Signature = p.Value.AsString().HexToBytes() + Signature = Convert.FromBase64String(p.Value.AsString()) }).ToDictionary(p => p.PublicKey, p => p.Signature) }; } @@ -47,13 +47,13 @@ public JObject ToJson() { JObject json = new JObject(); if (Script != null) - json["script"] = Script.ToHexString(); + json["script"] = Convert.ToBase64String(Script); json["parameters"] = new JArray(Parameters.Select(p => p.ToJson())); if (Signatures != null) { json["signatures"] = new JObject(); foreach (var signature in Signatures) - json["signatures"][signature.Key.ToString()] = signature.Value.ToHexString(); + json["signatures"][signature.Key.ToString()] = Convert.ToBase64String(signature.Value); } return json; } @@ -215,7 +215,7 @@ public static ContractParametersContext FromJson(JObject json) if (!typeof(IVerifiable).IsAssignableFrom(type)) throw new FormatException(); var verifiable = (IVerifiable)Activator.CreateInstance(type); - using (MemoryStream ms = new MemoryStream(json["hex"].AsString().HexToBytes(), false)) + using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(json["hex"].AsString()), false)) using (BinaryReader reader = new BinaryReader(ms, Encoding.UTF8)) { verifiable.DeserializeUnsigned(reader); @@ -284,7 +284,7 @@ public JObject ToJson() { Verifiable.SerializeUnsigned(writer); writer.Flush(); - json["hex"] = ms.ToArray().ToHexString(); + json["hex"] = Convert.ToBase64String(ms.ToArray()); } json["items"] = new JObject(); foreach (var item in ContextItems) diff --git a/neo/SmartContract/JsonSerializer.cs b/neo/SmartContract/JsonSerializer.cs index 030585420e..96c525e0b1 100644 --- a/neo/SmartContract/JsonSerializer.cs +++ b/neo/SmartContract/JsonSerializer.cs @@ -26,7 +26,7 @@ public static JObject Serialize(StackItem item) } case ByteArray buffer: { - return buffer.GetByteArray().ToHexString(); + return Convert.ToBase64String(buffer.GetByteArray()); } case Integer num: { diff --git a/neo/SmartContract/Manifest/ContractGroup.cs b/neo/SmartContract/Manifest/ContractGroup.cs index 75359e782a..249c6b8a53 100644 --- a/neo/SmartContract/Manifest/ContractGroup.cs +++ b/neo/SmartContract/Manifest/ContractGroup.cs @@ -1,6 +1,7 @@ using Neo.Cryptography; using Neo.Cryptography.ECC; using Neo.IO.Json; +using System; namespace Neo.SmartContract.Manifest { @@ -30,7 +31,7 @@ public static ContractGroup FromJson(JObject json) return new ContractGroup { PubKey = ECPoint.Parse(json["pubKey"].AsString(), ECCurve.Secp256r1), - Signature = json["signature"].AsString().HexToBytes(), + Signature = Convert.FromBase64String(json["signature"].AsString()), }; } @@ -48,7 +49,7 @@ public virtual JObject ToJson() { var json = new JObject(); json["pubKey"] = PubKey.ToString(); - json["signature"] = Signature.ToHexString(); + json["signature"] = Convert.ToBase64String(Signature); return json; } } diff --git a/neo/Wallets/NEP6/NEP6Contract.cs b/neo/Wallets/NEP6/NEP6Contract.cs index 45f0b5e157..af27db6c4c 100644 --- a/neo/Wallets/NEP6/NEP6Contract.cs +++ b/neo/Wallets/NEP6/NEP6Contract.cs @@ -1,5 +1,6 @@ using Neo.IO.Json; using Neo.SmartContract; +using System; using System.Linq; namespace Neo.Wallets.NEP6 @@ -14,7 +15,7 @@ public static NEP6Contract FromJson(JObject json) if (json == null) return null; return new NEP6Contract { - Script = json["script"].AsString().HexToBytes(), + Script = Convert.FromBase64String(json["script"].AsString()), ParameterList = ((JArray)json["parameters"]).Select(p => p["type"].TryGetEnum()).ToArray(), ParameterNames = ((JArray)json["parameters"]).Select(p => p["name"].AsString()).ToArray(), Deployed = json["deployed"].AsBoolean() @@ -24,7 +25,7 @@ public static NEP6Contract FromJson(JObject json) public JObject ToJson() { JObject contract = new JObject(); - contract["script"] = Script.ToHexString(); + contract["script"] = Convert.ToBase64String(Script); contract["parameters"] = new JArray(ParameterList.Zip(ParameterNames, (type, name) => { JObject parameter = new JObject();