Skip to content

Derive From<RpcChannel> to allow connecting to multiple rpc interfaces #469

Open
@ascjones

Description

@ascjones

Allows a single connect for multiple rpc interfaces e.g.

struct Rpc {
    state: StateClient<Hash>,
    chain: ChainClient<BlockNumber, Hash, (), SignedBlock>,
    author: AuthorClient<Hash, Hash>,
}

impl From<RpcChannel> for Rpc {
    fn from(channel: RpcChannel) -> Rpc {
        Rpc {
            state: channel.clone().into(),
            chain: channel.clone().into(),
            author: channel.into(),
        }
    }
}

fn rpc(url: &str) {
    ws::connect(url).and_then(|rpc: Rpc| ... );
}

The From<RpcChannel> could be derived e.g.

#[derive(FromRpcChannel)]
struct Rpc {
    ...
}

Rel: use-ink/ink#131

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions