Skip to content

Commit

Permalink
Fixed "RpcClient doesn't compile against Neo master" (neo-project#449)
Browse files Browse the repository at this point in the history
* [RpcServer] Querying contracts by ID/name (neo-project#378)

* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* draft

* draft

* update

* fixed bug with decimal of GAS consumed in invokefunction/invokescript

* remove modify of invokescript

* Querying contracts by ID/name, server side

* update

* Enable using native.name for search

Enable using native.name for search

* Using keyword instead of addressOrScriptHash

* revert

* _initialize

* split

* update

* Update exception message in ApplicationLog

* Update src/ApplicationLogs/LogReader.cs

Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* update

* a

* More fix

* fix

* Fixed UT

* Simplify Code

* Simplify Code 2

* Update RpcServer

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* MPT in StateService from core (neo-project#410)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (neo-project#413)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal

* fix

* Fixed UT (Neo CI01089) (neo-project#416)

* [RpcServer] Querying contracts by ID/name (neo-project#378)

* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* draft

* draft

* update

* fixed bug with decimal of GAS consumed in invokefunction/invokescript

* remove modify of invokescript

* Querying contracts by ID/name, server side

* update

* Enable using native.name for search

Enable using native.name for search

* Using keyword instead of addressOrScriptHash

* revert

* _initialize

* split

* update

* Update exception message in ApplicationLog

* Update src/ApplicationLogs/LogReader.cs

Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* update

* a

* More fix

* fix

* Fixed UT

* Simplify Code

* Simplify Code 2

* Update RpcServer

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* MPT in StateService from core (neo-project#410)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (neo-project#413)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal

* fix

* Fixed UT (Neo CI01089)

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: ZhangTao <ztgoforit@163.com>

* Nep17 (neo-project#412)

* [RpcServer] Querying contracts by ID/name (neo-project#378)

* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* draft

* draft

* update

* fixed bug with decimal of GAS consumed in invokefunction/invokescript

* remove modify of invokescript

* Querying contracts by ID/name, server side

* update

* Enable using native.name for search

Enable using native.name for search

* Using keyword instead of addressOrScriptHash

* revert

* _initialize

* split

* update

* Update exception message in ApplicationLog

* Update src/ApplicationLogs/LogReader.cs

Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* update

* a

* More fix

* fix

* Fixed UT

* Simplify Code

* Simplify Code 2

* Update RpcServer

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* String Substitution

* Modify filename and name methods

* update

* update

* Update src/RpcClient/Models/RpcNep5TokenInfo.cs

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>

* Update src/RpcClient/Nep17API.cs

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>

* MPT in StateService from core (neo-project#410)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (neo-project#413)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal

* fix

* Fixed UT (Neo CI01089)

* Update Nep17API.cs

* Update README.md

Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>

* update filename

* Fix UT

* Format

* fix

* update

* update UT

* Add Unit Tests

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: ZhangTao <ztgoforit@163.com>

* merge

* clear

* Transfer bug fix (neo-project#429)

* [RpcServer] Querying contracts by ID/name (neo-project#378)

* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* draft

* draft

* update

* fixed bug with decimal of GAS consumed in invokefunction/invokescript

* remove modify of invokescript

* Querying contracts by ID/name, server side

* update

* Enable using native.name for search

Enable using native.name for search

* Using keyword instead of addressOrScriptHash

* revert

* _initialize

* split

* update

* Update exception message in ApplicationLog

* Update src/ApplicationLogs/LogReader.cs

Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* update

* a

* More fix

* fix

* Fixed UT

* Simplify Code

* Simplify Code 2

* Update RpcServer

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* MPT in StateService from core (neo-project#410)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (neo-project#413)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal

* fix

* Fixed UT (Neo CI01089) (neo-project#416)

* [RpcServer] Querying contracts by ID/name (neo-project#378)

* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* draft

* draft

* update

* fixed bug with decimal of GAS consumed in invokefunction/invokescript

* remove modify of invokescript

* Querying contracts by ID/name, server side

* update

* Enable using native.name for search

Enable using native.name for search

* Using keyword instead of addressOrScriptHash

* revert

* _initialize

* split

* update

* Update exception message in ApplicationLog

* Update src/ApplicationLogs/LogReader.cs

Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* update

* a

* More fix

* fix

* Fixed UT

* Simplify Code

* Simplify Code 2

* Update RpcServer

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* MPT in StateService from core (neo-project#410)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (neo-project#413)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal

* fix

* Fixed UT (Neo CI01089)

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: ZhangTao <ztgoforit@163.com>

* Nep17 (neo-project#412)

* [RpcServer] Querying contracts by ID/name (neo-project#378)

* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* draft

* draft

* update

* fixed bug with decimal of GAS consumed in invokefunction/invokescript

* remove modify of invokescript

* Querying contracts by ID/name, server side

* update

* Enable using native.name for search

Enable using native.name for search

* Using keyword instead of addressOrScriptHash

* revert

* _initialize

* split

* update

* Update exception message in ApplicationLog

* Update src/ApplicationLogs/LogReader.cs

Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* update

* a

* More fix

* fix

* Fixed UT

* Simplify Code

* Simplify Code 2

* Update RpcServer

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>

* String Substitution

* Modify filename and name methods

* update

* update

* Update src/RpcClient/Models/RpcNep5TokenInfo.cs

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>

* Update src/RpcClient/Nep17API.cs

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>

* MPT in StateService from core (neo-project#410)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (neo-project#413)

* Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal

* fix

* Fixed UT (Neo CI01089)

* Update Nep17API.cs

* Update README.md

Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>

* update filename

* Fix UT

* Format

* fix

* update

* update UT

* Add Unit Tests

* update

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: ZhangTao <ztgoforit@163.com>

* merge

* fixed bug

* clear

* UT

* Add a little code coverage

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: ZhangTao <ztgoforit@163.com>

* Preview4 (neo-project#430)

* Preview4

* Remove syslog in README.md

* dotnet 5.0 (neo-project#407)

* CI01123 (neo-project#435)

* Fix dotnet5 (neo-project#442)

* Update

* Add RpcMethodToken and RpcNefFile

* Format?

* Increase test coverage

* Increase test coverage

* Increase test coverage

* Increase test coverage

* Increase test coverage

* Clean code

* format

Co-authored-by: 陈志同 <chenzhitong12@hotmail.com>
Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
Co-authored-by: superboyiii <573504781@qq.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: ZhangTao <ztgoforit@163.com>
Co-authored-by: Erik Zhang <erik@neo.org>
Co-authored-by: Shine Li <bfshm@qq.com>
  • Loading branch information
10 people authored and joeqian10 committed Apr 7, 2021
1 parent a6340ff commit 416ac96
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01130" />
<PackageReference Include="Neo" Version="3.0.0-CI01139" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion src/RpcClient/Models/RpcContractState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Neo;
using Neo.IO;
using Neo.IO.Json;
using Neo.Network.RPC.Models;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using System;
Expand All @@ -22,7 +24,7 @@ public static RpcContractState FromJson(JObject json)
Id = (int)json["id"].AsNumber(),
UpdateCounter = (ushort)json["updatecounter"].AsNumber(),
Hash = UInt160.Parse(json["hash"].AsString()),
Script = Convert.FromBase64String(json["script"].AsString()),
Nef = RpcNefFile.FromJson(json["nef"]),
Manifest = ContractManifest.FromJson(json["manifest"])
}
};
Expand Down
25 changes: 25 additions & 0 deletions src/RpcClient/Models/RpcMethodToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Neo.IO.Json;
using Neo.SmartContract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Neo.Network.RPC.Models
{
class RpcMethodToken
{
public static MethodToken FromJson(JObject json)
{
return new MethodToken
{
Hash = UInt160.Parse(json["hash"].AsString()),
Method = json["method"].AsString(),
ParametersCount = (ushort)json["paramcount"].AsNumber(),
HasReturnValue = json["hasreturnvalue"].AsBoolean(),
CallFlags = (CallFlags)Enum.Parse(typeof(CallFlags), json["callflags"].AsString())
};
}
}
}
25 changes: 25 additions & 0 deletions src/RpcClient/Models/RpcNefFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Neo.IO.Json;
using Neo.SmartContract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Neo.Network.RPC.Models
{
class RpcNefFile
{
public static NefFile FromJson(JObject json)
{
return new NefFile
{
Compiler = json["compiler"].AsString(),
Version = json["version"].AsString(),
Tokens = ((JArray)json["tokens"]).Select(p => RpcMethodToken.FromJson(p)).ToArray(),
Script = Convert.FromBase64String(json["script"].AsString()),
CheckSum = (uint)json["checksum"].AsNumber()
};
}
}
}
24 changes: 20 additions & 4 deletions src/RpcClient/Nep17API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,32 @@ public async Task<BigInteger> TotalSupplyAsync(UInt160 scriptHash)
/// <returns></returns>
public async Task<RpcNep17TokenInfo> GetTokenInfoAsync(UInt160 scriptHash)
{
var contractState = await rpcClient.GetContractStateAsync(scriptHash.ToString()).ConfigureAwait(false);
byte[] script = Concat(
scriptHash.MakeScript("symbol", true),
scriptHash.MakeScript("decimals", true),
scriptHash.MakeScript("totalSupply", true));

var contractState = await rpcClient.GetContractStateAsync(scriptHash.ToString()).ConfigureAwait(false);
var name = contractState.Manifest.Name;
var result = await rpcClient.InvokeScriptAsync(script).ConfigureAwait(false);
var stack = result.Stack;

return new RpcNep17TokenInfo
{
Name = name,
Symbol = stack[0].GetString(),
Decimals = (byte)stack[1].GetInteger(),
TotalSupply = stack[2].GetInteger()
};
}

public async Task<RpcNep17TokenInfo> GetTokenInfoAsync(string contractName)
{
var contractState = await rpcClient.GetContractStateAsync(contractName).ConfigureAwait(false);
byte[] script = Concat(
contractState.Hash.MakeScript("symbol", true),
contractState.Hash.MakeScript("decimals", true),
contractState.Hash.MakeScript("totalSupply", true));
var name = contractState.Manifest.Name;
var result = await rpcClient.InvokeScriptAsync(script).ConfigureAwait(false);
var stack = result.Stack;

Expand All @@ -109,7 +127,6 @@ public async Task<Transaction> CreateTransferTxAsync(UInt160 scriptHash, KeyPair
{
var sender = Contract.CreateSignatureRedeemScript(fromKey.PublicKey).ToScriptHash();
Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } };

byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data);

TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic);
Expand All @@ -136,7 +153,6 @@ public async Task<Transaction> CreateTransferTxAsync(UInt160 scriptHash, int m,
throw new ArgumentException($"Need at least {m} KeyPairs for signing!");
var sender = Contract.CreateMultiSigContract(m, pubKeys).ScriptHash;
Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } };

byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data);

TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic);
Expand Down
2 changes: 1 addition & 1 deletion src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static ContractState ContractStateFromJson(JObject json)
Id = (int)json["id"].AsNumber(),
UpdateCounter = (ushort)json["updatecounter"].AsNumber(),
Hash = UInt160.Parse(json["hash"].AsString()),
Script = Convert.FromBase64String(json["script"].AsString()),
Nef = RpcNefFile.FromJson(json["nef"]),
Manifest = ContractManifest.FromJson(json["manifest"])
};
}
Expand Down
Loading

0 comments on commit 416ac96

Please sign in to comment.