Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: JsonRpcClient, default to Unauthenticated state #36

Merged
merged 1 commit into from
Dec 24, 2021

Conversation

miraclx
Copy link
Collaborator

@miraclx miraclx commented Dec 24, 2021

Default the JsonRpcClient's authentication state to being Unauthenticated, much like HashMap's RandomState. Makes it so you don't have to worry about authentication until you actually need to. So the auth module shouldn't be imported without you doing any authentication.

Diff
-use near_jsonrpc_client::{auth, JsonRpcClient};
+use near_jsonrpc_client::JsonRpcClient;

struct App {
-    client: JsonRpcClient<auth::Unauthenticated>, // <-- pain
+    client: JsonRpcClient,
}

enum Network {
    MainNet,
    TestNet,
}

- fn mk_client(network: Network) -> JsonRpcClient<auth::Unauthenticated> { // <-- pain
+ fn mk_client(network: Network) -> JsonRpcClient {
    let rpc_url = match network {
        Network::MainNet => "https://rpc.mainnet.near.org",
        Network::TestNet => "https://rpc.testnet.near.org",
    };
    JsonRpcClient::connect(rpc_url)
}

@miraclx miraclx merged commit fa8c308 into master Dec 24, 2021
@miraclx miraclx deleted the set-default-auth branch December 24, 2021 07:39
@miraclx miraclx mentioned this pull request Feb 9, 2022
miraclx added a commit that referenced this pull request Feb 9, 2022
- Dropped generic authentication and added support for custom headers. <#47>
- Added the `sandbox_fast_forward` RPC Method. <#38>
- Upgraded `nearcore` crates to `v0.12.0` <#48>
- Executing the [examples](https://github.com/near/near-jsonrpc-client-rs/tree/master/examples) now allows custom RPC addr specification with interactive server selection. <b130118> <c5e938a>
- `JsonRpcClient::connect` is now generic over any url-like type. [`Url`](https://docs.rs/url/*/url/struct.Url.html), `&str`, `String` and `&String` are all supported. <#35>
- `JsonRpcClient` now defaults to the `Unauthenticated` state, easing a type specification pain point. <#36>
@frol frol mentioned this pull request Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant