Skip to content

Commit

Permalink
Merge branch 'master' into feature/docs/crate-level-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Dec 22, 2023
2 parents fc5ca7c + a527da5 commit 544b6c0
Show file tree
Hide file tree
Showing 44 changed files with 2,007 additions and 363 deletions.
87 changes: 19 additions & 68 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: CI

permissions:
pull-requests: write
contents: write

on:
push:
branches: [ master ]
Expand Down Expand Up @@ -47,74 +51,21 @@ jobs:
- name: Run cargo fmt
run: cargo fmt --all -- --check

publish:
runs-on: ubuntu-20.04
release-plz:
runs-on: ubuntu-latest
needs: [test, clippy, cargo-fmt]
if: github.ref == 'refs/heads/master'

steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
# fetch tags for cargo ws publish
# might be a simple `fetch-tags: true` option soon, see https://github.com/actions/checkout/pull/579
fetch-depth: 0

- name: Setup
run: |
git config user.name github-actions
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
cargo install --git https://github.com/miraclx/cargo-workspaces --rev b2d49b9e575e29fd2395352e4d0df47def025039 cargo-workspaces
export GIT_PREVIOUS_TAG=$(git describe --tags --abbrev=0)
echo "GIT_PREVIOUS_TAG=${GIT_PREVIOUS_TAG}" >> $GITHUB_ENV
echo "[ pre run] current latest git tag is \"${GIT_PREVIOUS_TAG}\""
- name: Publish to crates.io and tag the commit
id: tag-and-publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo ws publish --all --yes --exact \
--skip-published --no-git-commit --allow-dirty \
--tag-existing --tag-prefix 'v' \
--tag-msg 'crates.io snapshot' --tag-msg '%{https://crates.io/crates/%n/%v}' \
--no-individual-tags --no-git-push
export GIT_LATEST_TAG=$(git describe --tags --abbrev=0)
echo "GIT_LATEST_TAG=${GIT_LATEST_TAG}" >> $GITHUB_ENV
echo "[post run] current latest git tag is \"${GIT_LATEST_TAG}\""
echo "::set-output name=tagged::$( [[ "$GIT_LATEST_TAG" == "$GIT_PREVIOUS_TAG" ]] && echo 0 || echo 1 )"
# returning multi-line outputs gets truncated to include only the first line
# we have to escape the newline chars, runner auto unescapes them later
# https://github.community/t/set-output-truncates-multiline-strings/16852/3
GIT_TAG_MESSAGE="$(git tag -l --format='%(body)' ${GIT_LATEST_TAG})"
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//'%'/'%25'}"
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//$'\n'/'%0A'}"
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//$'\r'/'%0D'}"
echo "::set-output name=git_tag_message::${GIT_TAG_MESSAGE}"
- name: Push tags to GitHub (if any)
if: steps.tag-and-publish.outputs.tagged == 1
run: git push --tags

- name: Extract release notes
if: steps.tag-and-publish.outputs.tagged == 1
id: extract-release-notes
uses: ffurrer2/extract-release-notes@c24866884b7a0d2fd2095be2e406b6f260479da8

- name: Create release
if: steps.tag-and-publish.outputs.tagged == 1
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.GIT_LATEST_TAG }}
release_name: ${{ env.GIT_LATEST_TAG }}
body: |
## What's changed?
${{ steps.extract-release-notes.outputs.release_notes }}
**Crate Link**: ${{ steps.tag-and-publish.outputs.git_tag_message }}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ env.GIT_PREVIOUS_TAG }}...${{ env.GIT_LATEST_TAG }}
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/[email protected]
env:
# https://marcoieni.github.io/release-plz/github-action.html#triggering-further-workflow-runs
GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Rust artifacts
/target
Cargo.lock

# IDEs
.idea
.vscode

# macOS
.DS_Store
72 changes: 68 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,72 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Added the `methods::to_json()` helper method for visualizing the serialization of the RPC methods. <https://github.com/near/near-jsonrpc-client-rs/pull/49>
- Extracted all the RPC methods into their own modules instead of all being defined in the same `methods.rs` file. <https://github.com/near/near-jsonrpc-client-rs/pull/50>
- Moved auth specific logic behind a feature flag. <https://github.com/near/near-jsonrpc-client-rs/pull/55>
## [0.6.0](https://github.com/near/near-jsonrpc-client-rs/compare/v0.5.1...v0.6.0) - 2023-06-02

### Other
- [**breaking**] Upgrade near primitive crates version to 0.17.0 ([#126](https://github.com/near/near-jsonrpc-client-rs/pull/126))

## [0.5.1] - 2023-03-22

- Updated `borsh` to `0.10.2`. <https://github.com/near/near-jsonrpc-client-rs/pull/124>

## [0.5.0] - 2023-02-24

### Added

- `ApiKey::new` now accepts byte arrays and byte slices. <https://github.com/near/near-jsonrpc-client-rs/pull/119>
- `Authorization::bearer` method for token-authenticated requests. <https://github.com/near/near-jsonrpc-client-rs/pull/121>
- `ApiKey::as_bytes` returns a byte slice of the key without utf-8 validation. <https://github.com/near/near-jsonrpc-client-rs/pull/119>

### Changed

- Updated nearcore dependencies to `0.16.0`, which now requires a MSRV of `1.67.1`. <https://github.com/near/near-jsonrpc-client-rs/pull/122>
- `ApiKey::new` no longer requres the input of a valid UUID. <https://github.com/near/near-jsonrpc-client-rs/pull/119>
- `Debug` on `ApiKey` doesn't reveal the key anymore. <https://github.com/near/near-jsonrpc-client-rs/pull/120>
- The `auth` module is no longer feature gated. <https://github.com/near/near-jsonrpc-client-rs/pull/119>

### Breaking

- Removed the `auth::IntoApiKey` trait, any thing you can get a byte slice from is now a valid `ApiKey` input. <https://github.com/near/near-jsonrpc-client-rs/pull/119>
- Replaced the `ApiKey::as_str` method with `ApiKey::to_str`, now returning a `Result`. <https://github.com/near/near-jsonrpc-client-rs/pull/119>
- Replaced the `InvalidApiKey` error with `InvalidHeaderValue` re-exported from `http`. <https://github.com/near/near-jsonrpc-client-rs/pull/119>
- Removed `Display` on `ApiKey`. <https://github.com/near/near-jsonrpc-client-rs/pull/117>

## [0.4.1] - 2022-11-11

- Fixed an issue where an `&RpcMethod`'s response was being parsed differently from an `RpcMethod`. <https://github.com/near/near-jsonrpc-client-rs/pull/114>

## [0.4.0] - 2022-10-04

- Updated nearcore dependencies, which now requires a MSRV of `1.64.0`. <https://github.com/near/near-jsonrpc-client-rs/pull/100>, <https://github.com/near/near-jsonrpc-client-rs/pull/110>
- Updated other dependencies, with some general improvements. <https://github.com/near/near-jsonrpc-client-rs/pull/111>
- Added `rustls-tls` feature flag to enable `rustls` as an alternative to `native-tls`. <https://github.com/near/near-jsonrpc-client-rs/pull/103>
- Switched to using `log::debug!` instead of `log::info!` for debug logging. <https://github.com/near/near-jsonrpc-client-rs/pull/107>
- Fixed `gas_price` RPC method serialization. <https://github.com/near/near-jsonrpc-client-rs/pull/73>
- Fixed `query` method error deserialization. <https://github.com/near/near-jsonrpc-client-rs/pull/82>
- Reworked the `JsonRpcError`::`handler_error` method. <https://github.com/near/near-jsonrpc-client-rs/pull/99>
- Moved auth specific logic behind a feature flag. <https://github.com/near/near-jsonrpc-client-rs/pull/55>
- Added the `methods::to_json()` helper method for visualizing the serialization of the RPC methods. <https://github.com/near/near-jsonrpc-client-rs/pull/49>

## [0.4.0-beta.0] - 2022-05-31

<details>
<summary>
<em>
Superseded by <a href="https://github.com/near/near-jsonrpc-client-rs/compare/v0.4.0-beta.0...v0.4.0">
<code> 0.4.0 </code>
</a>
</em>
</summary>

> - Updated nearcore dependencies, fixing a previous breaking change. <https://github.com/near/near-jsonrpc-client-rs/pull/100>
> - Fixed `gas_price` RPC method serialization. <https://github.com/near/near-jsonrpc-client-rs/pull/73>
> - Fixed `query` method error deserialization. <https://github.com/near/near-jsonrpc-client-rs/pull/82>
> - Reworked the `JsonRpcError`::`handler_error` method. <https://github.com/near/near-jsonrpc-client-rs/pull/99>
> - Moved auth specific logic behind a feature flag. <https://github.com/near/near-jsonrpc-client-rs/pull/55>
> - Added the `methods::to_json()` helper method for visualizing the serialization of the RPC methods. <https://github.com/near/near-jsonrpc-client-rs/pull/49>
</details>

## [0.3.0] - 2022-02-09

Expand All @@ -36,7 +97,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

> Release Page: <https://github.com/near/near-jsonrpc-client-rs/releases/tag/v0.1.0>
[unreleased]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.3.0...HEAD
[unreleased]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.4.1...HEAD
[0.4.1]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.3.0...v0.4.0
[0.4.0-beta.0]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.3.0...v0.4.0-beta.0
[0.3.0]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/near/near-jsonrpc-client-rs/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/near/near-jsonrpc-client-rs/releases/tag/v0.1.0
39 changes: 18 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
[package]
name = "near-jsonrpc-client"
version = "0.0.0" # managed by cargo-workspaces, see below
version = "0.6.0"
authors = ["Near Inc <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/near/near-jsonrpc-client-rs"
description = "Lower-level API for interfacing with the NEAR Protocol via JSONRPC"
categories = ["asynchronous", "api-bindings", "network-programming"]
keywords = ["near", "api", "jsonrpc", "rpc", "async"]
rust-version = "1.56.0"

# cargo-workspaces
[workspace.metadata.workspaces]
version = "0.3.0"
rust-version = "1.67.1"

[dependencies]
uuid = { version = "0.8", features = ["v4"], optional = true }
borsh = "0.9"
serde = "1.0.127"
reqwest = { version = "0.11.4", features = ["json"] }
thiserror = "1.0.28"
serde_json = "1.0.66"
log = "0.4.17"
borsh = "1.3.0"
serde = "1.0.145"
reqwest = { version = "0.11.12", features = ["json"], default-features = false }
thiserror = "1.0.37"
serde_json = "1.0.85"
lazy_static = "1.4.0"

near-crypto = "0.12.0"
near-primitives = "0.12.0"
near-chain-configs = "0.12.0"
near-jsonrpc-primitives = "0.12.0"
near-crypto = "0.19.0"
near-primitives = "0.19.0"
near-chain-configs = "0.19.0"
near-jsonrpc-primitives = "0.19.0"

[dev-dependencies]
tokio = { version = "1.1", features = ["rt", "macros"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
env_logger = "0.10.0"

[features]
default = ["auth"]
default = ["native-tls"]
any = []
auth = ["uuid"]
sandbox = []
adversarial = []
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]

[[example]]
name = "auth"
required-features = ["auth"]

[package.metadata.docs.rs]
features = ["any", "auth", "sandbox"]
features = ["any", "sandbox"]
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Lower-level API for interfacing with the NEAR Protocol via JSONRPC.

[![crates.io](https://img.shields.io/crates/v/near-jsonrpc-client?label=latest)](https://crates.io/crates/near-jsonrpc-client)
[![Crates.io](https://img.shields.io/crates/v/near-jsonrpc-client?label=latest)](https://crates.io/crates/near-jsonrpc-client)
[![Documentation](https://docs.rs/near-jsonrpc-client/badge.svg)](https://docs.rs/near-jsonrpc-client)
![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/near-jsonrpc-client.svg)
[![Dependency Status](https://deps.rs/crate/near-jsonrpc-client/0.3.0/status.svg)](https://deps.rs/crate/near-jsonrpc-client/0.3.0)
[![MIT or Apache 2.0 Licensed](https://img.shields.io/crates/l/near-jsonrpc-client.svg)](#license)
[![Dependency Status](https://deps.rs/crate/near-jsonrpc-client/0.5.1/status.svg)](https://deps.rs/crate/near-jsonrpc-client/0.5.1)

## Usage

Expand Down Expand Up @@ -49,7 +49,7 @@ use serde::Deserialize;
use serde_json::json;

use near_jsonrpc_client::{methods, JsonRpcClient};
use near_primitives::serialize::u128_dec_format;
use near_primitives::serialize::dec_format;
use near_primitives::types::*;

#[derive(Debug, Deserialize)]
Expand All @@ -58,11 +58,11 @@ struct PartialGenesisConfig {
chain_id: String,
genesis_height: BlockHeight,
epoch_length: BlockHeightDelta,
#[serde(with = "u128_dec_format")]
#[serde(with = "dec_format")]
min_gas_price: Balance,
#[serde(with = "u128_dec_format")]
#[serde(with = "dec_format")]
max_gas_price: Balance,
#[serde(with = "u128_dec_format")]
#[serde(with = "dec_format")]
total_supply: Balance,
validators: Vec<AccountInfo>,
}
Expand All @@ -81,6 +81,15 @@ let partial_genesis = mainnet_client.call(genesis_config_request).await?;
println!("{:#?}", partial_genesis);
```

By default, `near-jsonrpc-client` uses `native-tls`. On Linux, this introduces a dependency on the system `openssl` library. In some situations, for example when cross-compiling, it can be problematic to depend on non-Rust libraries.

If you wish to switch to an all-Rust TLS implementation, you may do so using the `rustls-tls` feature flag. Note that the `native-tls` feature is enabled by default. Therefore, to disable it and use `rustls-tls` instead, you must also use `default-features = false`. The default `auth` feature must then be declared explicitly.

```toml
# in Cargo.toml
near-jsonrpc-client = { ..., default-features = false, features = ["auth","rustls-tls"] }
```

## Releasing

Versioning and releasing of this crate is automated and managed by [custom fork](https://github.com/miraclx/cargo-workspaces/tree/grouping-versioning-and-exclusion) of [`cargo-workspaces`](https://github.com/pksunkara/cargo-workspaces). To publish a new version of this crate, you can do so by bumping the `version` under the `[workspace.metadata.workspaces]` section in the [package manifest](https://github.com/near/near-jsonrpc-client-rs/blob/master/Cargo.toml) and submit a PR.
Expand Down
2 changes: 2 additions & 0 deletions examples/access_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ fn indent(indentation: usize, s: String) -> String {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

let client = utils::select_network()?;

let account_id = utils::input("Enter the Account ID whose keys we're listing: ")?.parse()?;
Expand Down
Loading

0 comments on commit 544b6c0

Please sign in to comment.