Rest server
RestServer
In this section you will learn about RestServer plugin and how it works.
Dependencies
-
Microsoft.AspNetCore.JsonPatch.dll
Required -
Microsoft.AspNetCore.Mvc.NewtonsoftJson.dll
Required -
Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer.dll
Required -
Microsoft.AspNetCore.Mvc.Versioning.dll
Required -
Microsoft.OpenApi.dll
Required -
Newtonsoft.Json.Bson.dll
Required -
Newtonsoft.Json.dll
Required -
System.ServiceProcess.ServiceController.dll
linux maybe -
Microsoft.AspNetCore.Mvc.Versioning.dll
Required -
Microsoft.AspNetCore.Mvc.Versioning.dll
Required -
Microsoft.AspNetCore.Mvc.Versioning.dll
Required -
Microsoft.OpenApi.dll
Swagger(optional) -
Swashbuckle.AspNetCore.Swagger.dll
Swagger(optional) -
Swashbuckle.AspNetCore.SwaggerGen.dll
Swagger(optional) -
Swashbuckle.AspNetCore.SwaggerUI.dll
Swagger(optional) -
Swashbuckle.AspNetCore.Newtonsoft.dll
Swagger(optional) -
RestServer.xml
Swagger UI(optional)
In Docker
RestServer
| | |-- Microsoft.AspNetCore.JsonPatch.dll
| | |-- Microsoft.AspNetCore.Mvc.NewtonsoftJson.dll
| | |-- Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer.dll
| | |-- Microsoft.AspNetCore.Mvc.Versioning.dll
| | |-- Microsoft.OpenApi.dll
| | |-- Neo.ConsoleService.dll
| | |-- Newtonsoft.Json.Bson.dll
| | |-- Newtonsoft.Json.dll
| | |-- RestServer.deps.json
| | |-- RestServer.dll
| | |-- RestServer.pdb
| | |-- RestServer.xml
| | |-- Swashbuckle.AspNetCore.Newtonsoft.dll
| | |-- Swashbuckle.AspNetCore.Swagger.dll
| | |-- Swashbuckle.AspNetCore.SwaggerGen.dll
| | |-- Swashbuckle.AspNetCore.SwaggerUI.dll
| | |-- System.ServiceProcess.ServiceController.dll
| | |-- config.json
| | `-- runtimes
| | `-- win
| | `-- lib
| | `-- net6.0
| | `-- System.ServiceProcess.ServiceController.dll
These files go in the same directory as the RestServer.dll. In neo-cli
plugins/RestServer/ folder.
Response Headers
| Name | Value(s) | Description |
|---|---|---|
| server | neo-cli/3.6.0 RestServer/3.6.0 | neo-cli and RestServer version. |
JSON Serializer
RestServer uses custom Newtonsoft Json Converters to serialize controller action
responses and route parameters.
One Way Binding - Write only.
-
Neo.SmartContract.ContractState -
Neo.SmartContract.NefFile -
Neo.SmartContract.MethodToken -
Neo.SmartContract.Native.TrimmedBlock -
Neo.SmartContract.Manifest.ContractAbi -
Neo.SmartContract.Manifest.ContractGroup -
Neo.SmartContract.Manifest.ContractManifest -
Neo.SmartContract.Manifest.ContractPermission -
Neo.SmartContract.Manifest.ContractPermissionDescriptor -
Neo.Network.P2P.Payloads.Block -
Neo.Network.P2P.Payloads.Header -
Neo.Network.P2P.Payloads.Signer -
Neo.Network.P2P.Payloads.TransactionAttribute -
Neo.Network.P2P.Payloads.Transaction -
Neo.Network.P2P.Payloads.Witness
Two Way Binding - Read & Write
-
System.Guid -
System.ReadOnlyMemory<T> -
Neo.BigDecimal -
Neo.UInt160 -
Neo.UInt256 -
Neo.Cryptography.ECC.ECPoint -
Neo.VM.Types.Array -
Neo.VM.Types.Boolean -
Neo.VM.Types.Buffer -
Neo.VM.Types.ByteString -
Neo.VM.Types.Integer -
Neo.VM.Types.InteropInterface -
Neo.VM.Types.Null -
Neo.VM.Types.Map -
Neo.VM.Types.Pointer -
Neo.VM.Types.StackItem -
Neo.VM.Types.Struct
Remote Endpoints
Parametes {hash} can be any Neo N3 address or scripthash; {address} can be any Neo N3 address only; {number} and {index} can be any uint32.
Parameter Examples
-
{hash}- 0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5 or NiHURyS83nX2mpxtA7xq84cGxVbHojj5Wc -
{address}- NiHURyS83nX2mpxtA7xq84cGxVbHojj5Wc -
{number}- 1 -
{index}- 2500000
Paths
- Utils
-
[GET]/api/v1/utils/{hash}/address -
[GET]/api/v1/utils/{address}/scripthash -
[GET]/api/v1/utils/{hash}/{address}/validate
-
- Node
-
[GET]/api/v1/node -
[GET]/api/v1/node/peers -
[GET]/api/v1/node/plugins -
[GET]/api/v1/node/settings
-
- Ledger
-
[GET]/api/v1/ledger/neo/accounts -
[GET]/api/v1/ledger/gas/accounts -
[GET]/api/v1/ledger/blocks?page={number}&size={number} -
[GET]/api/v1/ledger/blocks/height -
[GET]/api/v1/ledger/blocks/{index} -
[GET]/api/v1/ledger/blocks/{index}/header -
[GET]/api/v1/ledger/blocks/{index}/witness -
[GET]/api/v1/ledger/blocks/{index}/transactions?page={number}&size={number} -
[GET]/api/v1/ledger/transactions/{hash} -
[GET]/api/v1/ledger/transactions/{hash}/witnesses -
[GET]/api/v1/ledger/transactions/{hash}/signers -
[GET]/api/v1/ledger/transactions/{hash}/attributes -
[GET]/api/v1/ledger/memorypool?page={number}&size={number} -
[GET]/api/v1/ledger/memorypool/verified?page={number}&size={number} -
[GET]/api/v1/ledger/memorypool/unverified?page={number}&size={number} -
[GET]/api/v1/ledger/memorypool/count
-
- Tokens
-
[GET]/api/v1/tokens/balanceof/{address} - NFTs
-
[GET]/api/v1/tokens/nep-11?page={number}&size={number} -
[GET]/api/v1/tokens/nep-11/count -
[GET]/api/v1/tokens/nep-11/{hash}/balanceof/{address}
-
- NEP-17
-
[GET]/api/v1/tokens/nep-17?page={number}&size={number} -
[GET]/api/v1/tokens/nep-17/count -
[GET]/api/v1/tokens/nep-17/{hash}/balanceof/{address}
-
-
- Contracts
-
[GET]/api/v1/contracts?page={number}&size={number} -
[GET]/api/v1/contracts/count -
[GET]/api/v1/contracts/{hash} -
[GET]/api/v1/contracts/{hash}/abi -
[GET]/api/v1/contracts/{hash}/manifest -
[GET]/api/v1/contracts/{hash}/nef -
[GET]/api/v1/contracts/{hash}/storage
-
- Wallet
-
[POST]/api/v1/wallet/open -
[POST]/api/v1/wallet/create -
[POST]/api/v1/wallet/{session}/address/create -
[GET]/api/v1/wallet/{session}/address/list -
[GET]/api/v1/wallet/{session}/asset/list -
[GET]/api/v1/wallet/{session}/balance/list -
[POST]/api/v1/wallet/{session}/changepassword -
[GET]/api/v1/wallet/{session}/close -
[GET]/api/v1/wallet/{session}/delete/{address} -
[GET]/api/v1/wallet/{session}/export/{address} -
[GET]/api/v1/wallet/{session}/export -
[GET]/api/v1/wallet/{session}/gas/unclaimed -
[GET]/api/v1/wallet/{session}/key/list -
[POST]/api/v1/wallet/{session}/import -
[POST]/api/v1/wallet/{session}/import/multisigaddress -
[POST]/api/v1/wallet/{session}/transfer
-
@superboyiii can you please review and test it?
This is awesome. Need some time for test.
anyone know what this error is about? It builds fine on my computer. CodeQL / Analyze (csharp) gets error only.
MSBuild version 17.8.3+195e7f5a3 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
LevelDBStore -> /home/runner/work/neo-modules/neo-modules/src/LevelDBStore/bin/Debug/net7.0/LevelDBStore.dll
RocksDBStore -> /home/runner/work/neo-modules/neo-modules/src/RocksDBStore/bin/Debug/net7.0/RocksDBStore.dll
StatesDumper -> /home/runner/work/neo-modules/neo-modules/src/StatesDumper/bin/Debug/net7.0/StatesDumper.dll
RpcServer -> /home/runner/work/neo-modules/neo-modules/src/RpcServer/bin/Debug/net7.0/RpcServer.dll
CSC : error CS0006: Metadata file '/home/runner/work/neo-modules/neo-modules/src/RpcServer/obj/Debug/net7.0/ref/RpcServer.dll' could not be found [/home/runner/work/neo-modules/neo-modules/src/OracleService/OracleService.csproj]
CSC : error CS0006: Metadata file '/home/runner/work/neo-modules/neo-modules/src/RpcServer/obj/Debug/net7.0/ref/RpcServer.dll' could not be found [/home/runner/work/neo-modules/neo-modules/src/ApplicationLogs/ApplicationLogs.csproj]
Build well on my local PC, not sure if it referred to the changes on *csproj of Oracle and Applicationlog
Tried to revert the modification from ApplicationLogs and OracleService, forked it to my repo and run CodeQL check. Still failed.
In the code.yml it says if there is an error autobuilding the project to comment out that step and add your own build commands or script to run. we needed to do that for neo-express repo you can have a look at that if you want https://github.com/neo-project/neo-express/blob/master/.github/workflows/code.yml
Is it necessary to put HardFork into
CamelCasePropertyNamesContractResolver() ?
Changed hardfork names. Now removed prefix.
Fixed
@superboyiii This may help you. Just do Ctrl+O in postman. Some URL may have been removed.
Neo API version 1.0.postman_collection.json
should look like this
@cschuchardt88 I can't get any response from Wallet model, even can't debug into it. Other models work well. Is it working on yours?
Check the config? Its disabled by default.
Check the config? Its disabled by default.
Oh, OK. Works now, thanks.
@superboyiii I added you to my repos, so you can commit changes directly.
Is this OK? @cschuchardt88
https://github.com/neo-project/neo-modules/pull/839/commits/784c7dbdcf9bcd207f4c63416e2fa0d11a2628b8
Has to be this:
Rules = signer.Rules != null ? signer.Rules.Select(s => WitnessRuleToJToken(s, serializer)) : Array.Empty<WitnessRule>(),
You have to call WitnessRuleToJToken or else it can't serialize the object, and you will get an error.
Also i forgot to mention there is console commands.
@Jim8y @shargon Need your review for double check.
My environment is kinda painful to set up testing this pr. Will take a while for me, but shargon and superboy's review should be sufficient to merge.
@superboyiii Did you check out the Swagger UI?
- http://127.0.0.1:10339/swagger/index.html
@superboyiii Did you check out the Swagger UI?
Tried it, it's really cool and convinent!
Is not forgotten, I will need time to review it, I really love this PR
neo> FATAL [12:50:32.505] System.Reflection.ReflectionTypeLoadException
Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829...ch()
at System.Thr...eadStart()
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.EnumerateApiVersions(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.LazyApiVersionDescriptions.EnumerateApiVersions()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.get_ApiVersionDescriptions()
at Neo.Plugins.RestServer.RestWebServer.<>c__DisplayClass7_3.<Start>b__37(SwaggerUIOptions options)
at Microsoft.AspNetCore.Builder.SwaggerUIBuilderExtensions.UseSwaggerUI(IApplicationBuilder app, Action`1 setupAction)
at Neo.Plugins.RestServer.RestWebServer.<Start>b__7_2(IApplicationBuilder app)
at Microsoft.Extensions.DependencyInjection.AutoRegisterMiddleware.<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHost.Start()
at Neo.Plugins.RestServer.RestWebServer.Start()
at Neo.Plugins.RestServer.RestServerPlugin.OnSystemLoaded(NeoSystem system)
at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 130
at Neo.CLI.MainService.Start(String[] args) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 379
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
/opt/start_node.sh: line 2: 116 Aborted (core dumped) dotnet neo-cli.dll
root@292575307a6c:/#
I am trying to set it online on neocompiler.io for who wants to test.
I was missing the .xml file in the folder. I will try again.
neo> FATAL [13:05:36.078] System.IO.FileNotFoundException
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer, Version=5.1.0.0, Culture=neutral, PublicKeyToken=adb9793829...ch()
at System.Thr...eadStart()
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer, Version=5.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer, Version=5.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Neo.Plugins.RestServer.RestWebServer.<Start>b__7_1(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Neo.Plugins.RestServer.RestWebServer.Start()
at Neo.Plugins.RestServer.RestServerPlugin.OnSystemLoaded(NeoSystem system)
at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 130
at Neo.CLI.MainService.Start(String[] args) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 379
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
/opt/start_node.sh: line 2: 111 Aborted (core dumped) dotnet neo-cli.dll
root@a262d64d5120:/#
I tried now copying all .dlls to the folder. But still some errors
NEO-CLI v3.6.2 - NEO v3.6.2 - NEO-VM v3.6.2
neo> FATAL [15:12:58.316] System.Reflection.ReflectionTypeLoadException
Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829...ch()
at System.Thr...eadStart()
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.EnumerateApiVersions(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.LazyApiVersionDescriptions.EnumerateApiVersions()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.get_ApiVersionDescriptions()
at Neo.Plugins.RestServer.RestWebServer.<>c__DisplayClass7_3.<Start>b__37(SwaggerUIOptions options)
at Microsoft.AspNetCore.Builder.SwaggerUIBuilderExtensions.UseSwaggerUI(IApplicationBuilder app, Action`1 setupAction)
at Neo.Plugins.RestServer.RestWebServer.<Start>b__7_2(IApplicationBuilder app)
at Microsoft.Extensions.DependencyInjection.AutoRegisterMiddleware.<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHost.Start()
at Neo.Plugins.RestServer.RestWebServer.Start()
at Neo.Plugins.RestServer.RestServerPlugin.OnSystemLoaded(NeoSystem system)
at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 130
at Neo.CLI.MainService.Start(String[] args) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 379
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
/opt/start_node.sh: line 2: 99 Aborted (core dumped) dotnet neo-cli.dll
root@2b23b4535fb1:/#
@vncoelho Looks like you are using Microsoft.EntityFrameworkCore? You site is programmed in asp.net mvc? Looks like my plugin is loading your mvc controllers for your site?
Everything is built with SDK mcr.microsoft.com/dotnet/sdk:7.0.404-jammy
Node is created with dotnet publish -c Release -f net7.0
Plugins are generated with dotnet publish -c Release -o app
Client is run with a container with image mcr.microsoft.com/dotnet/aspnet:7.0.14-jammy
We used to use aspnet because it was enough for neo-cli to run, image was more compact.
Perhaps we may need another image for client now.
My thoughts are, that you are using the wrong image. Why are you using web image like aspnet:7.0.14-jammy? Since your doing that way, Microsoft.Extensions.DependencyInjection.AutoRegisterMiddleware will; you guessed it auto register. In this case its trying to auto register Microsoft.EntityFrameworkCore or something that needs it; but not likely. however i don't use Microsoft.EntityFrameworkCore thats for interacting with SQL databases.
Maybe also try only the dependencies that RestServer Require. Here is an updated list: