paritytech / jsonrpc Goto Github PK
View Code? Open in Web Editor NEWRust JSON-RPC implementation
License: MIT License
Rust JSON-RPC implementation
License: MIT License
Websockets server with Pub-Sub support.
Looks like there is a limitation to the number of parameters you can define in build_rpc_trait! macros
So I am looking for a way to circumvent this shortcoming with a generic parameter I could parse myself inside impl but couldn't realize so far, tried this:
use jsonrpc_core::{Error, Params};
use jsonrpc_core::futures::BoxFuture;
use std::collections::BTreeMap;
use serde_json::{self,Value};
build_rpc_trait! {
/// RPC Interface.
pub trait Faucet {
type Metadata;
#[rpc(meta, name = "faucet_new")]
fn faucet_new(&self, Self::Metadata, BTreeMap<String, Value>) -> BoxFuture<BTreeMap<String, String>, Error>;
}
}
Or
use jsonrpc_core::{Error, Params};
use jsonrpc_core::futures::BoxFuture;
use std::collections::BTreeMap;
use serde_json::{self,Value};
build_rpc_trait! {
/// RPC Interface.
pub trait Faucet {
type Metadata;
#[rpc(meta, name = "faucet_new")]
fn faucet_new(&self, Self::Metadata, Value) -> BoxFuture<BTreeMap<String, String>, Error>;
}
}
But I am getting error code -32601 "Method not found", What can be done to receive a serialized Json Object over RPC ?
pubsub::Sink
and macros::pubsub::Sink
should implement futures::Sink
.
Actually instead of using those structures it should be possible to do self.transport.with(Box::new(FnMut))
and just declare those structs as type aliases to futures::sink::With
.
Access-Control-Request-Headers: Origin, Content-Type, Accept
in request with Authorization
HTTP header.Access-Control-Allow-Headers
from response will contain Authorization
as accepted HTTP headerAccess-Control-Allow-Headers
from response doesn't contain Authorization
HTTP header> rustc --version --verbose
rustc 1.18.0-nightly (bbdaad0dc 2017-04-14)
binary: rustc
commit-hash: bbdaad0dc8dc64e036ccee817f90a91876b32a9d
commit-date: 2017-04-14
host: x86_64-pc-windows-msvc
release: 1.18.0-nightly
LLVM version: 3.9
Server: jsonrpc-minihttp-server/7.0.0
rust 0.15 was just released and with it custom derive
!
Serde released version 0.9, which is now incompatible with this library:
error[E0308]: mismatched types
--> src/api/handler.rs:40:12
|
40 | Ok(value)
| ^^^^^ expected enum `jsonrpc_core::Value`, found enum `serde_json::Value`
|
= note: expected type `jsonrpc_core::Value`
= note: found type `serde_json::Value`
migrating shouldn't be difficult. If you would like, I can open a pull request.
I might be totally noobish, but I can't get the example code to compile :(
I put the exact code I'm compiling in https://github.com/eriklarko/jsonrpc-recreate
2017-02-13 17:24:39 TRACE tcp Sent response: {"jsonrpc":null,"result":true,"id":1}
That field supposed to be 2.0
for json-rpc 2.0 and ommited for json-rpc 1.0 (or at least be 1.0
)
I have a use case where I want to bind the server to a local port and I don't really care what the port is, I just need to know it when done setting up. So I have a loop where I iterate from port X to Y and try each until ServerBuilder::start
returns success or I'm all out of options.
The problem is that ServerBuilder::new
consumes my handler. So I have to create a new one for each try. This severely limits how I can implement my handlers and force me to either put stuff behind clonable Arc<Mutex<...>>
es or some other weird solution.
Is this a use case you would like to support? If so I have two ideas how to solve it:
ServerBuilder::start
can contain my handler so I can extract it from a failed try.ServerBuilder::new
does not take my handler. Instead the API is rewritten so the handler is given after it is known that the server can be created. To do this ServerBuilder::start
could return a Result<IntermediateServerBuilder>
with one method: start(handler) -> Server
.warning: Quasi-quoting might make incremental compilation very inefficient: NtExpr(..)
--> rpc/src/v1/traits/rpc.rs:23:1
|
23 | build_rpc_trait! {
| ^
|
= note: this error originates in a macro outside of the current crate
Would there be an interest to implement a file descriptor 'transport server' ?
So you could just use stdin to send json command, and pipe programs together.
Useful for test purposes as well.
https://github.com/serde-rs/serde/releases/tag/v1.0.0
It might be just PubSub stuff, but perhaps #![warn(missing_docs)]
is missing as well.
Currently you can supply any string to cors or hosts validation.
We do know however what format the strings should look like. Implement pre-procesing and validation for those.
Use Metadata
to provide a way to send notifications
Hi. The jsonrpc-core
crate published on crates.io says it has the MIT license. However, this repository and the Cargo.toml
files does not mention any license. Is everything under MIT? Could you please specify the license in these crates?
Currently jsonrpc-http-server
uses hyper
. And since I remember there were some issues with it (that's why we have forked it). What do you think about replacing hyper with some other / smaller library? eg. tiny-http
Creating a new project and doing a cut-n-paste of the code in example server.rs fails to compile with error; error.txt
The only way to fix this is to clone the entire jsonrpc repository and then set Cargo.toml to path into the cloned projects subdirectories for core and http. Setting up Cargo the way as instructed in the documentation doesn't work.
I want to be able to just get the jsonrpc-core and jsonrpc-http-server crates from crates.io in my Cargo.toml.
Instead it should be possible to distinguish if parameter was provided.
Also a method unwrap_or_default()
should be available for Trailing<T: Default>
.
jsonrpc-core
should not have dependency on tokio-core
.
jsonrpc-core::reactor
could be moved to separate crate, but RpcHandler
and Remote
needs to be abstracted.
Currently some upstream changes can break our builds, see #117
I don't find very much information how to talk to a server using the PubSub feature of this repository. Would it be possible to add an example or some docs on that?
I have followed the example file to set up a server, and it is running. But I don't know what send to it to register my client.
Some help with this would be awesome. Thanks.
Instead of allocating a String and then passing it to jsonrpc-core
it should be possible to just pass instance of io::Read
and io::Write
(later). See:
https://docs.rs/serde_json/0.9.5/serde_json/fn.from_reader.html
https://docs.rs/serde_json/0.9.5/serde_json/fn.to_writer.html
Currently we don't have any server that can be referenced from crates.
Would be good to have a simple implementation based for instance on hyper
RequestMiddleware should be able to delegate cors_header handling to the server.
[dependencies]
serde = "0.9"
jsonrpc-core = { version = "7.0", path = "../core" }
jsonrpc-pubsub = { version = "7.0", path = "../pubsub" }
[dev-dependencies]
jsonrpc-tcp-server = { version = "7.0", path = "../tcp" }
jsonrpc-pubsub
and jsonrpc-tcp-server
should be optional
Should attempt to re-use port on *nix, like here:
https://tokio-rs.github.io/tokio-proto/src/tokio_proto/tcp_server.rs.html#212
... and is based on pretty outdated mio version
Could simplify examples, single-server usages and also address #80
Currently http and minihttp servers are processing the request even if Origin
header is not allowed to access. The requester will not be able to read the response, but can cause side effects to happen on the node.
We should rather fail fast in such case and avoid even processing the request.
As it is now, if some urgent fix is required by parity
, we will have to create separate branch for it and update parity Cargo.toml
to use this new branch. This is because jsonrpc/master
usually contains breaking changes and parity
cannot be just updated to this latest master.
Right now it's enforced trait-wide which means that every implementation is limited by the least-capable one.
failing test:
https://github.com/paritytech/jsonrpc/pull/131/files
Currently you need to specify separate methods and alias them on the implementation level.
We can accommodate old uses of Result
with try!
using a Carrier implementation and ?
.
Until Carrier
is stabilized we could just hack around it when porting existing synchronous method implementations
fn previous_sync(&self) -> BoxFuture<Success, Error> {
let body = move || {
// previous function body here
};
Future::done(body()).boxed()
}
Option to supply existing event loop remote instead of spawning one.
Replace build_rpc_trait
macro with custom derive since it starts to get unmaintanable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.