Code Monkey home page Code Monkey logo

Comments (3)

lontivero avatar lontivero commented on August 18, 2024 1

Yes, the example here is for the equivalent to bitcoin-cli help. Adding help to the script (similar to bitcoin-cli -help) is even easier but not so useful.

from walletwasabi.

MaxHillebrand avatar MaxHillebrand commented on August 18, 2024
--- a/WalletWasabi/Rpc/JsonRpcRequestHandler.cs
+++ b/WalletWasabi/Rpc/JsonRpcRequestHandler.cs
@@ -81,6 +81,11 @@ public class JsonRpcRequestHandler<TService>
     {
         var methodName = jsonRpcRequest.Method;
 
+        if (methodName == "help")
+        {
+            return ServiceMetadata(jsonRpcRequest.Id).ToJson(DefaultSettings);
+        }
+
         if (!MetadataProvider.TryGetMetadata(methodName, out var procedureMetadata))
         {
             return Error(JsonRpcErrorCodes.MethodNotFound, $"'{methodName}' method not found.", jsonRpcRequest.Id);
@@ -182,6 +187,24 @@ public class JsonRpcRequestHandler<TService>
         }
     }
 
+    private JsonRpcResponse ServiceMetadata(string requestId) =>
+        JsonRpcResponse.CreateResultResponse(
+            requestId,
+            MetadataProvider.EnumerateServiceInfo()
+                .Select(
+                    x => new
+                    {
+                        name = x.Name,
+                        parameters = x.Parameters.Select(
+                            p => new
+                            {
+                                name = p.name,
+                                type = p.type.Name.ToLower(),
+                                optional = p.isOptional,
+                                defaultValue = p.defaultValue
+                            })
+                    }));
+
     private string Error(JsonRpcErrorCodes code, string reason, string id)
     {
         var response = JsonRpcResponse.CreateErrorResponse(id, code, reason);

from walletwasabi.

kristapsk avatar kristapsk commented on August 18, 2024

RPC backend could have endpoint that responds with available RPC methods and their usage, but, independently, wcli.sh should have brief usage info about script itself. That is how, for example, bitcoin-cli works (bitcoin-cli help vs bitcoin-cli -help).

from walletwasabi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.