-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'adrian/light-sdk' (#2220)
* origin/adrian/light-sdk: Adds a method to serialize transactions Makes internal struct of `RevealPk` private Fixes datetime Splits light sdk queries into multiple files Renames light sdk crate and adds description Adds missing feature for tendermint-rpc in light sdk Changelog #2220 Imports `HttpClient` from `tendermint_rpc` Updates types and imports after rebase Updates docstrings and fixes clippy Some small type simplifications in the reading api [feat]: Added rpc functions to light sdk Renames `get_msg_to_sign` to `get_sign_bytes` [feat]: Small fixes and making stuff public First draft of all transactions in light sdk Refactors pos txs in separate file. Improved shared functions Created light SDK builders. First attempt at overview of light-sdk
- Loading branch information
Showing
21 changed files
with
1,992 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Added light sdk ([\#2220](https://github.com/anoma/namada/pull/2220)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "namada_light_sdk" | ||
description = "A more simple version of the Namada SDK" | ||
resolver = "2" | ||
authors.workspace = true | ||
edition.workspace = true | ||
documentation.workspace = true | ||
homepage.workspace = true | ||
keywords.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
borsh.workspace = true | ||
borsh-ext.workspace = true | ||
ibc = "0.47.0" | ||
namada_core = {path = "../core"} | ||
namada_sdk = {path = "../sdk"} | ||
prost.workspace = true | ||
tendermint-config.workspace = true | ||
tendermint-rpc = { worskpace = true, features = ["http-client"] } | ||
tokio = {workspace = true, features = ["rt"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! The Namada light SDK is a simplified version of the SDK aimed at making | ||
//! interaction with the protocol easier and faster. The library is developed | ||
//! with ease-of-use and interoperability in mind so that it should be possible | ||
//! to wrap it for usage in an FFI context. | ||
//! | ||
//! The [`namada_core`] crate of Namada is also re-exported to allow access to | ||
//! its types. | ||
//! | ||
//! # Structure | ||
//! | ||
//! This SDK is divided into three modules: | ||
//! | ||
//! - transaction: contains functions to construct all the transactions | ||
//! currently supported by the protocol | ||
//! - reading: exposes queries to retrieve data from a Namada node | ||
//! - writing: TO BE DONE | ||
|
||
pub mod reading; | ||
pub mod transaction; | ||
pub mod writing; | ||
pub use namada_core; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use namada_core::types::account::Account; | ||
use namada_core::types::address::Address; | ||
use namada_core::types::key::common; | ||
|
||
use super::*; | ||
|
||
/// Query token amount of owner. | ||
pub fn get_token_balance( | ||
tendermint_addr: &str, | ||
token: &Address, | ||
owner: &Address, | ||
) -> Result<token::Amount, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
let rt = Runtime::new().unwrap(); | ||
rt.block_on(rpc::get_token_balance(&client, token, owner)) | ||
} | ||
|
||
/// Check if the address exists on chain. Established address exists if it | ||
/// has a stored validity predicate. Implicit and internal addresses | ||
/// always return true. | ||
pub fn known_address( | ||
tendermint_addr: &str, | ||
address: &Address, | ||
) -> Result<bool, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
let rt = Runtime::new().unwrap(); | ||
rt.block_on(rpc::known_address(&client, address)) | ||
} | ||
|
||
/// Query the accunt substorage space of an address | ||
pub fn get_account_info( | ||
tendermint_addr: &str, | ||
owner: &Address, | ||
) -> Result<Option<Account>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
let rt = Runtime::new().unwrap(); | ||
rt.block_on(rpc::get_account_info(&client, owner)) | ||
} | ||
|
||
/// Query if the public_key is revealed | ||
pub fn is_public_key_revealed( | ||
tendermint_addr: &str, | ||
owner: &Address, | ||
) -> Result<bool, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
let rt = Runtime::new().unwrap(); | ||
rt.block_on(rpc::is_public_key_revealed(&client, owner)) | ||
} | ||
|
||
/// Query an account substorage at a specific index | ||
pub fn get_public_key_at( | ||
tendermint_addr: &str, | ||
owner: &Address, | ||
index: u8, | ||
) -> Result<Option<common::PublicKey>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
let rt = Runtime::new().unwrap(); | ||
rt.block_on(rpc::get_public_key_at(&client, owner, index)) | ||
} |
Oops, something went wrong.