Skip to content

Commit

Permalink
Merge pull request #8 from gotabit/ci_and_readme
Browse files Browse the repository at this point in the history
feat(CI/README): Update CI and README
  • Loading branch information
jacksoom authored Sep 28, 2023
2 parents b1fafc2 + e60eaf5 commit f42728e
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 36 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/check-and-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

# This workflow run tests and build for each push

on:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Update local toolchain
run: |
rustup update
rustup component add clippy
rustup install nightly
- name: Toolchain info
run: |
cargo --version --verbose
rustc --version
cargo clippy --version
- name: Lint
run: |
cargo fmt -- --check
cargo clippy -- -D warnings
- name: Test
run: |
cargo check
cargo test --all
20 changes: 0 additions & 20 deletions .github/workflows/rust.yml

This file was deleted.

24 changes: 12 additions & 12 deletions Cargo.lock

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

71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
# Gotabit rust sdk

Rust resources related to the Gotabit ecosystem

## Modules

### 1. gotabit-sdk-proto

GotaBit network Proto and gRPC definitions using [prost](https://github.com/tokio-rs/prost) and [tonic](https://github.com/hyperium/tonic)

### 2. grpc-client

GotaBit gRPC client interacts with gotabit nodes.

## Using gRPC client

### Build a simple transfer transaction using gotabit gRPC client

```rust
use cosmrs::crypto::secp256k1::SigningKey;
use gotabit_sdk_proto::cosmos::bank::v1beta1::MsgSend;
use gotabit_sdk_proto::cosmos::base::v1beta1::Coin;
use grpc_client::cli::GrpcClient;

#[tokio::main]
async fn main() {
let mut grpc_cli = GrpcClient::new(&grpc_client::networks::TEST_NET)
.await
.unwrap();

let sender = "gio1h4nr4eez50szxn6darhhqha8x8tv8zvfd5mhet";
let sign_key = "a823f4ae943b511b7f082227c4f2f0737666d625e7b3431f238a7d4d4baec5f2";
let sign_key = SigningKey::from_slice(hex::decode(sign_key).unwrap().as_slice()).unwrap();
let to_addr = "RECIPIENT_ADDRESS";
let amount = Coin {
denom: "ugtb".to_string(),
amount: "100000".to_string(),
};

let msg_send = MsgSend {
from_address: sender.into(),
to_address: to_addr.to_string(),
amount: vec![amount.clone()],
};

let resp = grpc_cli
.broadcast_tx_sync(
&sign_key,
&sender.to_string(),
msg_send.clone(),
&amount,
"test memo".to_string(),
999999999,
100_000u64,
None,
None,
)
.await
.unwrap()
.into_inner();

if resp.tx_response.as_ref().unwrap().code == 0 {
println!(
"Transfer response. status: {}. hash: {}",
resp.tx_response.as_ref().unwrap().code,
resp.tx_response.as_ref().unwrap().txhash
);
} else {
println!("{:?}", resp.tx_response.unwrap());
}
}
```
9 changes: 5 additions & 4 deletions grpc-client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl GrpcClient {
}

// Build a raw transaction. sign and broadcast it
#[allow(clippy::too_many_arguments)]
pub async fn broadcast_tx_sync<T>(
&mut self,
sign_key: &SigningKey,
Expand All @@ -152,8 +153,8 @@ impl GrpcClient {
where
T: gotabit_sdk_proto::traits::MessageExt + gotabit_sdk_proto::traits::TypeUrl,
{
let acct_info = if acct.is_some() {
acct.unwrap()
let acct = if let Some(acct_info) = acct {
acct_info
} else {
// get account seq
let base_account_resp = self
Expand Down Expand Up @@ -186,7 +187,7 @@ impl GrpcClient {
mode: SignMode::Direct.into(),
})),
}),
sequence: acct_info.0,
sequence: acct.0,
};

let auth_info = AuthInfo {
Expand All @@ -204,7 +205,7 @@ impl GrpcClient {
body_bytes: tx_body.to_bytes()?,
auth_info_bytes: auth_info.to_bytes()?,
chain_id: self.chain_id.to_string(),
account_number: acct_info.1,
account_number: acct.1,
};

let sign_doc_bytes = sign_doc.to_bytes()?;
Expand Down

0 comments on commit f42728e

Please sign in to comment.