Skip to content

Commit d7b0595

Browse files
authored
Update terra sdk api to use Addr (#51)
Addr is a checked version of String in cw ecosystem
1 parent e9c545c commit d7b0595

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

examples/terra-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cosmwasm-storage = { version = "0.16.0" }
3434
cw-storage-plus = "0.8.0"
3535
schemars = "0.8"
3636
serde = { version = "1.0", default-features = false, features = ["derive"] }
37-
pyth-sdk-terra = { version = "0.3.0", path = "../../pyth-sdk-terra" } # Remove path and use version only when you use this example on your own.
37+
pyth-sdk-terra = { version = "0.4.0", path = "../../pyth-sdk-terra" } # Remove path and use version only when you use this example on your own.
3838

3939
[dev-dependencies]
4040
cosmwasm-schema = { version = "0.16.0" }

examples/terra-contract/Developing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ rustup target add wasm32-unknown-unknown
2222
This example uses relative paths in `Cargo.toml`; you must remove any `path` components within `Cargo.toml` dependencies if you intend to compile this code outside of the `pyth-sdk-terra` repository, otherwise this will fail to compile. For example:
2323

2424
```diff
25-
- pyth-sdk-terra = { version = "0.3.0", path = "../../pyth-sdk-terra" }
26-
+ pyth-sdk-terra = { version = "0.3.0" }
25+
- pyth-sdk-terra = { version = "0.4.0", path = "../../pyth-sdk-terra" }
26+
+ pyth-sdk-terra = { version = "0.4.0" }
2727
```
2828

2929
## Compiling

examples/terra-contract/src/contract.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,8 @@ fn query_fetch_price(deps: Deps) -> StdResult<FetchPriceResponse> {
8080
// price feed. The result is a PriceFeed object with fields for the current price and other
8181
// useful information. The function will fail if the contract address or price feed id are
8282
// invalid.
83-
let price_feed = query_price_feed(
84-
&deps.querier,
85-
state.pyth_contract_addr.into_string(),
86-
state.price_feed_id,
87-
)?
88-
.price_feed;
83+
let price_feed =
84+
query_price_feed(&deps.querier, state.pyth_contract_addr, state.price_feed_id)?.price_feed;
8985

9086
// Get the current price and confidence interval from the price feed.
9187
// This function returns None if the price is not currently available.

pyth-sdk-terra/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-sdk-terra"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"

pyth-sdk-terra/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Simply call the `query_price_feed` function in your Terra contract with a price
2020

2121
```rust
2222
// Pyth network testnet contract address
23-
pyth_contract_addr: string = "terra1wzs3rgzgjdde3kg7k3aaz6qx7sc5dcwxqe9fuc";
23+
pyth_contract_addr = deps.api.addr_validate("terra1wzs3rgzgjdde3kg7k3aaz6qx7sc5dcwxqe9fuc")?;
2424
// Price feed id for BTC/USD on testnet
2525
price_feed_id = PriceIdentifier::from_hex("f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b");
2626

pyth-sdk-terra/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cosmwasm_std::{
22
to_binary,
3+
Addr,
34
QuerierWrapper,
45
QueryRequest,
56
StdResult,
@@ -35,12 +36,12 @@ pub struct PriceFeedResponse {
3536
/// Queries the price on-chain
3637
pub fn query_price_feed(
3738
querier: &QuerierWrapper,
38-
contract_addr: String,
39+
contract_addr: Addr,
3940
id: PriceIdentifier,
4041
) -> StdResult<PriceFeedResponse> {
4142
let price_feed_response = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
42-
contract_addr,
43-
msg: to_binary(&QueryMsg::PriceFeed { id })?,
43+
contract_addr: contract_addr.into_string(),
44+
msg: to_binary(&QueryMsg::PriceFeed { id })?,
4445
}))?;
4546
Ok(price_feed_response)
4647
}

0 commit comments

Comments
 (0)