Skip to content

feat: complete Service client implementation #17

Description

@Rjected

Currently service.rs contains a mostly unimplemented Service on the server side. The tower Service abstraction is convenient for both clients and servers, so a client should be easy to implement for a single peer.

Once implemented, dialing a node should look something like this:

let mut peer = make_client(peer_addr).await.unwrap();

The client should also make p2p requests more ergonomic. For example rather than dealing with peer message channels directly, we should have the following UX for making requests:

// using From<Vec<[u8; 32]>> for GetPooledTransactions
let txs_request: GetPooledTransactions = vec![
    hex!("c05a9eda51dd448c79e1dda1c79a3835c82c1142104f88adc1a64ec80fd193fb"),
    hex!("2fa4c5912523f735581cc731a9d44870fbb45cc3cbfb529d643b5aaca112beda"),
    hex!("3f855459086213a3def40270ee1c6e12aba7f5f81375ca35cdcd8e71e7a9b092"),
].into();

// a lower-level way to make a request, using the `Service` trait, still not bad
let request = Request::GetPooledTransactions(
    RequestPair {
        request_id: 1,
        message: txs_request,
    }
);
let response = peer.call(request).await.unwrap();

// another possible way to make a request
// if using the `Service` under the hood the implementation of this method should be very easy
let txs_response = peer.get_pooled_transactions(txs_request).await.unwrap();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions