Skip to content

Commit

Permalink
fiddling
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Nov 4, 2024
1 parent ee3ebcd commit 6b60e86
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ jobs:
run: cargo build --all --target=wasm32-unknown-unknown --all-features

- name: Test proto crate
run: wasm-pack test --node proto
run: wasm-pack test --headless --chrome proto

- name: Test types crate
run: wasm-pack test --node types --features=wasm-bindgen
run: wasm-pack test --headless --chrome types --features=wasm-bindgen

- name: Test node crate
run: wasm-pack test --headless --chrome node
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
environment:
# provide amount of bridge nodes to provision (default: 1)
- BRIDGE_COUNT=2
ports:
- 19090:9090
volumes:
- credentials:/credentials
- genesis:/genesis
Expand Down
1 change: 1 addition & 0 deletions ci/run-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ setup_private_validator() {
celestia-appd keys add "$NODE_NAME" --keyring-backend="test"
validator_addr="$(celestia-appd keys show "$NODE_NAME" -a --keyring-backend="test")"
# Create a validator's genesis account for the genesis.json with an initial bag of coins
echo "VALIDATOR ADDR: $validator_addr"
celestia-appd add-genesis-account "$validator_addr" "$VALIDATOR_COINS"
# Generate a genesis transaction that creates a validator with a self-delegation
celestia-appd gentx "$NODE_NAME" 5000000000utia \
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tracing = "0.1.40"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
http = "1.1.0"
jsonrpsee = { version = "0.24.2", features = ["http-client", "ws-client"] }
pbjson-types = "0.7.0"
tonic = { version = "0.12.3", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions rpc/src/tonic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ where

make_method2!(auth::query_client::QueryClient::params; get_auth_params() -> AuthParams);
make_method2!(auth::query_client::QueryClient::account; get_account(account: String) -> BaseAccount);
// TODO: pagination?
make_method2!(auth::query_client::QueryClient::accounts; get_accounts() -> Vec<BaseAccount>);

make_method2!(tx::service_client::ServiceClient::broadcast_tx; broadcast_tx(blob_tx: BlobTx, mode: tx::BroadcastMode) -> TxResponse);
make_method2!(tx::service_client::ServiceClient::get_tx; get_tx(hash: String) -> GetTxResponse);
Expand Down
61 changes: 39 additions & 22 deletions rpc/src/tonic/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use celestia_proto::celestia::blob::v1::{
QueryParamsRequest as QueryBlobParamsRequest, QueryParamsResponse as QueryBlobParamsResponse,
};
use celestia_proto::cosmos::auth::v1beta1::{
BaseAccount as RawBaseAccount, QueryAccountRequest, QueryAccountResponse,
BaseAccount as RawBaseAccount, QueryAccountRequest, QueryAccountResponse, QueryAccountsRequest,
QueryAccountsResponse,
};
use celestia_proto::cosmos::auth::v1beta1::{
QueryParamsRequest as QueryAuthParamsRequest, QueryParamsResponse as QueryAuthParamsResponse,
Expand Down Expand Up @@ -78,30 +79,40 @@ impl FromGrpcResponse<AuthParams> for QueryAuthParamsResponse {
})
}
}
fn account_from_any(any: pbjson_types::Any) -> Result<BaseAccount, Error> {
if any.type_url != RawBaseAccount::type_url() {
return Err(Error::UnexpectedResponseType(any.type_url));
}
let base_account =
RawBaseAccount::decode(&*any.value).map_err(|_| Error::FailedToParseResponse)?;

let any_pub_key = base_account.pub_key.ok_or(Error::FailedToParseResponse)?;
// cosmrs has different Any type than pbjson_types Any
let pub_key = PublicKey::try_from(Any {
type_url: any_pub_key.type_url,
value: any_pub_key.value.to_vec(),
})?;

Ok(BaseAccount {
address: base_account.address,
pub_key,
account_number: base_account.account_number,
sequence: base_account.sequence,
})
}

impl FromGrpcResponse<BaseAccount> for QueryAccountResponse {
fn try_from_response(self) -> Result<BaseAccount, Error> {
let account = self.account.ok_or(Error::FailedToParseResponse)?;
if account.type_url != RawBaseAccount::type_url() {
return Err(Error::UnexpectedResponseType(account.type_url));
}
println!("ACTT: {:#?}", account.value);
let base_account =
RawBaseAccount::decode(&*account.value).map_err(|_| Error::FailedToParseResponse)?;

let any_pub_key = base_account.pub_key.ok_or(Error::FailedToParseResponse)?;
// cosmrs has different Any type than pbjson_types Any
let pub_key = PublicKey::try_from(Any {
type_url: any_pub_key.type_url,
value: any_pub_key.value.to_vec(),
})?;

Ok(BaseAccount {
address: base_account.address,
pub_key,
account_number: base_account.account_number,
sequence: base_account.sequence,
})
account_from_any(self.account.ok_or(Error::FailedToParseResponse)?)
}
}

impl FromGrpcResponse<Vec<BaseAccount>> for QueryAccountsResponse {
fn try_from_response(self) -> Result<Vec<BaseAccount>, Error> {
self.accounts
.into_iter()
.map(|acct| account_from_any(acct))
.collect()
}
}

Expand Down Expand Up @@ -149,6 +160,12 @@ impl IntoGrpcParam<GetTxRequest> for String {
}
}

impl IntoGrpcParam<QueryAccountsRequest> for () {
fn into_parameter(self) -> QueryAccountsRequest {
QueryAccountsRequest { pagination: None }
}
}

macro_rules! make_empty_params {
($request_type:ident) => {
impl IntoGrpcParam<$request_type> for () {
Expand Down
4 changes: 4 additions & 0 deletions rpc/tests/tonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ async fn get_block() {
async fn get_account() {
let mut client = new_test_client(AuthLevel::Write).await.unwrap();

let accounts = client.get_accounts().await.unwrap();

println!("first account : {:?}", accounts.first());

let acct = client
.get_account("celestia1p3ucd3ptpw902fluyjzhq3ffgq4ntddaf0pdta".to_string())
.await
Expand Down
5 changes: 2 additions & 3 deletions rpc/tests/utils/tonic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use tonic::{Request, Status};

use celestia_rpc::tonic::GrpcClient;

//const CELESTIA_GRPC_URL: &str = "http://localhost:9090";
//const CELESTIA_GRPC_URL: &str = "https://public-celestia-consensus.numia.xyz:9090";
const CELESTIA_GRPC_URL: &str = "https://rpc.celestia.pops.one:9090";
const CELESTIA_GRPC_URL: &str = "http://localhost:19090";
//const CELESTIA_GRPC_URL: &str = "https://rpc.celestia.pops.one:9090";

#[derive(Clone)]
pub struct TestAuthInterceptor {
Expand Down

0 comments on commit 6b60e86

Please sign in to comment.