Skip to content

Commit

Permalink
Merge pull request #6 from gotabit/add_workspace
Browse files Browse the repository at this point in the history
feat(cli): Add option account info
  • Loading branch information
jacksoom authored Sep 26, 2023
2 parents 718372e + fbbd766 commit 76a5b3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
36 changes: 21 additions & 15 deletions grpc-client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,30 @@ impl GrpcClient {
memo: String,
timeout_height: u64,
gas: u64,
// (seq, account_number), if set none. it will query from grpc node
acct: Option<(u64, u64)>,
tx_tip: Option<Tip>,
) -> Result<tonic::Response<BroadcastTxResponse>, Box<dyn Error>>
where
T: gotabit_sdk_proto::traits::MessageExt + gotabit_sdk_proto::traits::TypeUrl,
{
// get account seq
let base_account_resp = self
.clients
.cosmos
.auth
.account(QueryAccountRequest {
address: addr.to_owned(),
})
.await?
.into_inner();
let base_acct: BaseAccount =
BaseAccount::from_any(&base_account_resp.account.unwrap()).unwrap();

let acct_info = if acct.is_some() {
acct.unwrap()
} else {
// get account seq
let base_account_resp = self
.clients
.cosmos
.auth
.account(QueryAccountRequest {
address: addr.to_owned(),
})
.await?
.into_inner();
let base_acct: BaseAccount =
BaseAccount::from_any(&base_account_resp.account.unwrap()).unwrap();
(base_acct.sequence, base_acct.account_number)
};
// build a simple transfer transction and sign
let tx_body = TxBody {
messages: vec![msg.to_any().unwrap()],
Expand All @@ -178,7 +184,7 @@ impl GrpcClient {
mode: SignMode::Direct.into(),
})),
}),
sequence: base_acct.sequence,
sequence: acct_info.0,
};

let auth_info = AuthInfo {
Expand All @@ -196,7 +202,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: base_acct.account_number,
account_number: acct_info.1,
};

let sign_doc_bytes = sign_doc.to_bytes()?;
Expand Down
1 change: 1 addition & 0 deletions grpc-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async fn test_submit_tx() {
timeout_height,
gas,
None,
None,
)
.await
.unwrap();
Expand Down

0 comments on commit 76a5b3c

Please sign in to comment.