Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sync to master] Unify base64 #397

Merged
merged 4 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LevelDBStore/LevelDBStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01056" />
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/RocksDBStore/RocksDBStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01056" />
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
<PackageReference Include="RocksDbNative" Version="6.2.2" />
<PackageReference Include="RocksDbSharp" Version="6.2.2" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public async Task<RpcVersion> GetVersionAsync()
/// </summary>
public async Task<UInt256> SendRawTransactionAsync(byte[] rawTransaction)
{
var result = await RpcSendAsync(GetRpcName(), rawTransaction.ToHexString()).ConfigureAwait(false);
var result = await RpcSendAsync(GetRpcName(), Convert.ToBase64String(rawTransaction)).ConfigureAwait(false);
return UInt256.Parse(result["hash"].AsString());
}

Expand All @@ -346,7 +346,7 @@ public Task<UInt256> SendRawTransactionAsync(Transaction transaction)
/// </summary>
public async Task<UInt256> SubmitBlockAsync(byte[] block)
{
var result = await RpcSendAsync(GetRpcName(), block.ToHexString()).ConfigureAwait(false);
var result = await RpcSendAsync(GetRpcName(), Convert.ToBase64String(block)).ConfigureAwait(false);
return UInt256.Parse(result["hash"].AsString());
}

Expand Down Expand Up @@ -450,9 +450,9 @@ public async Task<string> GetNewAddressAsync()
/// <returns>new address as string</returns>
public async Task<BigDecimal> GetWalletBalanceAsync(string assetId)
{
byte decimals = await new Nep5API(this).DecimalsAsync(UInt160.Parse(assetId.AsScriptHash())).ConfigureAwait(false);
var result = await RpcSendAsync(GetRpcName(), assetId).ConfigureAwait(false);
BigInteger balance = BigInteger.Parse(result["balance"].AsString());
byte decimals = await new Nep5API(this).DecimalsAsync(UInt160.Parse(assetId.AsScriptHash())).ConfigureAwait(false);
return new BigDecimal(balance, decimals);
}

Expand Down
2 changes: 1 addition & 1 deletion src/RpcClient/RpcClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01056" />
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions src/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Neo.Ledger;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
using System;
using System.Linq;
using static Neo.Ledger.Blockchain;

Expand Down Expand Up @@ -71,15 +72,15 @@ protected virtual JObject GetVersion(JArray _params)
[RpcMethod]
protected virtual JObject SendRawTransaction(JArray _params)
{
Transaction tx = _params[0].AsString().HexToBytes().AsSerializable<Transaction>();
Transaction tx = Convert.FromBase64String(_params[0].AsString()).AsSerializable<Transaction>();
RelayResult reason = system.Blockchain.Ask<RelayResult>(tx).Result;
return GetRelayResult(reason.Result, tx.Hash);
}

[RpcMethod]
protected virtual JObject SubmitBlock(JArray _params)
{
Block block = _params[0].AsString().HexToBytes().AsSerializable<Block>();
Block block = Convert.FromBase64String(_params[0].AsString()).AsSerializable<Block>();
RelayResult reason = system.Blockchain.Ask<RelayResult>(block).Result;
return GetRelayResult(reason.Result, block.Hash);
}
Expand Down
3 changes: 2 additions & 1 deletion src/RpcServer/RpcServer.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ private void ProcessInvokeWithWallet(JObject result, Signers signers = null)
tx = null;
}
}
result["tx"] = tx?.ToArray().ToHexString();
if (tx != null)
result["tx"] = Convert.ToBase64String(tx.ToArray());
}

[RpcMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/RpcServer/RpcServer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview3</Version>
Expand All @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
<PackageReference Include="Neo" Version="3.0.0-CI01056" />
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/StatesDumper/StatesDumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01056" />
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
<PackageReference Include="Neo.ConsoleService" Version="1.0.0" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Request": {
"jsonrpc": "2.0",
"method": "sendrawtransaction",
"params": [ "0089d9a541587389000000000046e71300000000007b212000011c0357464b777ecf6b5f3ac3893ace1f8b1621f6100325059ecb4878d3a875f91c51ceded330d4575fdee3137eddba5f6485cad334a79bdb67c43273171fbcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e660054180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b5201420c40b90107fe5d251a9ef10b22c3bb0d329c0fa8f1d0d1aab8ad430837c069cc2818887c4c387319a55837d72c997f6112698acf80c346c9bb4638d78b0c2623778c290c210222d8515184c7d62ffa99b829aeb4938c4704ecb0dd7e340e842e9df1218263430b4195440d78" ],
"params": [ "ANIHn05ujtUAAAAAACYcEwAAAAAAQkEAAAEKo4e1Ppa3mJpjFDGgVt0fQKBC9gEAXQMAyBeoBAAAAAwUzViuz9M1vh6z0xHh3IAJY9/XLZ8MFAqjh7U+lreYmmMUMaBW3R9AoEL2E8AMCHRyYW5zZmVyDBSlB7dGdv/td+dUuG7NmQnwus08ukFifVtSOAFCDEDh8zgTrGUXyzVX60wBCMyajNRfzFRiEPAe8CgGQ10bA2C3fnVz68Gw+Amgn5gmvuNfYKgWQ/W68Km1bYUPlnEYKQwhA86j4vgfGvk1ItKe3k8kofC+3q1ykzkdM4gPVHXZeHjJC0GVRA14" ],
"id": 1
},
"Response": {
Expand Down Expand Up @@ -679,7 +679,7 @@
"Request": {
"jsonrpc": "2.0",
"method": "sendrawtransaction",
"params": [ "0089d9a541587389000000000046e71300000000007b212000011c0357464b777ecf6b5f3ac3893ace1f8b1621f6100325059ecb4878d3a875f91c51ceded330d4575fdee3137eddba5f6485cad334a79bdb67c43273171fbcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e660054180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b5201420c40b90107fe5d251a9ef10b22c3bb0d329c0fa8f1d0d1aab8ad430837c069cc2818887c4c387319a55837d72c997f6112698acf80c346c9bb4638d78b0c2623778c290c210222d8515184c7d62ffa99b829aeb4938c4704ecb0dd7e340e842e9df1218263430b4195440d78" ],
"params": [ "ANIHn05ujtUAAAAAACYcEwAAAAAAQkEAAAEKo4e1Ppa3mJpjFDGgVt0fQKBC9gEAXQMAyBeoBAAAAAwUzViuz9M1vh6z0xHh3IAJY9/XLZ8MFAqjh7U+lreYmmMUMaBW3R9AoEL2E8AMCHRyYW5zZmVyDBSlB7dGdv/td+dUuG7NmQnwus08ukFifVtSOAFCDEDh8zgTrGUXyzVX60wBCMyajNRfzFRiEPAe8CgGQ10bA2C3fnVz68Gw+Amgn5gmvuNfYKgWQ/W68Km1bYUPlnEYKQwhA86j4vgfGvk1ItKe3k8kofC+3q1ykzkdM4gPVHXZeHjJC0GVRA14" ],
"id": 1
},
"Response": {
Expand All @@ -695,7 +695,7 @@
"Request": {
"jsonrpc": "2.0",
"method": "submitblock",
"params": [ "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000" ],
"params": [ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI+JfEVZZd6cjX2qJADFSuzRR40IzeV3K1zS9Q2wqetqI6hnvVQEAAAAAAAD6lrDvowCyjK9dBALCmE1fvMuahQEAARECAB2sK3wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHKYeUuiB1BN05kD4Gc0RjMFTshpwAABUESPn/oAQABEQ==" ],
"id": 1
},
"Response": {
Expand Down
7 changes: 3 additions & 4 deletions tests/Neo.Network.RPC.Tests/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task TestErrorResponse()
var test = TestUtils.RpcTestCases.Find(p => p.Name == (nameof(rpc.SendRawTransactionAsync) + "error").ToLower());
try
{
var result = await rpc.SendRawTransactionAsync(test.Request.Params[0].AsString().HexToBytes().AsSerializable<Transaction>());
var result = await rpc.SendRawTransactionAsync(Convert.FromBase64String(test.Request.Params[0].AsString()).AsSerializable<Transaction>());
}
catch (RpcException ex)
{
Expand Down Expand Up @@ -253,16 +253,15 @@ public async Task TestGetVersion()
public async Task TestSendRawTransaction()
{
var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.SendRawTransactionAsync).ToLower());
var result = await rpc.SendRawTransactionAsync(test.Request.Params[0].AsString().HexToBytes().AsSerializable<Transaction>());
var result = await rpc.SendRawTransactionAsync(Convert.FromBase64String(test.Request.Params[0].AsString()).AsSerializable<Transaction>());
Assert.AreEqual(test.Response.Result["hash"].AsString(), result.ToString());
}

[TestMethod]
public async Task TestSubmitBlock()
{
var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.SubmitBlockAsync).ToLower());
var block = TestUtils.GetBlock(2).Hash;
var result = await rpc.SubmitBlockAsync(test.Request.Params[0].AsString().HexToBytes());
var result = await rpc.SubmitBlockAsync(Convert.FromBase64String(test.Request.Params[0].AsString()));
Assert.AreEqual(test.Response.Result["hash"].AsString(), result.ToString());
}

Expand Down