terra/contracts: columbus-5 migration for wormhole

Change-Id: I6772a49d3d667633b27d74eb7f349e01c849f505
This commit is contained in:
Reisen 2021-09-06 08:27:27 +00:00 committed by David Paryente
parent c92442e3ce
commit c04fe95859
6 changed files with 119 additions and 177 deletions

View File

@ -14,15 +14,15 @@ backtraces = ["cosmwasm-std/backtraces"]
library = [] library = []
[dependencies] [dependencies]
cosmwasm-std = { version = "0.10.0" } cosmwasm-std = { version = "0.16.0" }
cosmwasm-storage = { version = "0.10.0" } cosmwasm-storage = { version = "0.16.0" }
schemars = "0.7" schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] } serde = { version = "1.0.103", default-features = false, features = ["derive"] }
cw20 = "0.2.2" cw20 = "0.8.0"
cw20-base = { version = "0.2.2", features = ["library"] } cw20-base = { version = "0.8.0", features = ["library"] }
cw20-wrapped = { path = "../cw20-wrapped", features = ["library"] } cw20-wrapped = { path = "../cw20-wrapped", features = ["library"] }
thiserror = { version = "1.0.20" } thiserror = { version = "1.0.20" }
k256 = { version = "0.5.9", default-features = false, features = ["ecdsa"] } k256 = { version = "0.9.4", default-features = false, features = ["ecdsa"] }
sha3 = { version = "0.9.1", default-features = false } sha3 = { version = "0.9.1", default-features = false }
generic-array = { version = "0.14.4" } generic-array = { version = "0.14.4" }
hex = "0.4.2" hex = "0.4.2"
@ -30,4 +30,4 @@ lazy_static = "1.4.0"
[dev-dependencies] [dev-dependencies]
cosmwasm-vm = { version = "0.10.0", default-features = false, features = ["default-cranelift"] } cosmwasm-vm = { version = "0.10.0", default-features = false, features = ["default-cranelift"] }
serde_json = "1.0" serde_json = "1.0"

View File

@ -1,18 +1,16 @@
use cosmwasm_std::{ use cosmwasm_std::{
entry_point,
has_coins, has_coins,
log,
to_binary, to_binary,
Api,
BankMsg, BankMsg,
Binary, Binary,
Coin, Coin,
CosmosMsg, CosmosMsg,
Deps,
DepsMut,
Env, Env,
Extern, MessageInfo,
HandleResponse, Response,
HumanAddr,
InitResponse,
Querier,
StdError, StdError,
StdResult, StdResult,
Storage, Storage,
@ -25,11 +23,11 @@ use crate::{
}, },
error::ContractError, error::ContractError,
msg::{ msg::{
ExecuteMsg,
GetAddressHexResponse, GetAddressHexResponse,
GetStateResponse, GetStateResponse,
GuardianSetInfoResponse, GuardianSetInfoResponse,
HandleMsg, InstantiateMsg,
InitMsg,
QueryMsg, QueryMsg,
}, },
state::{ state::{
@ -59,7 +57,7 @@ use k256::{
Signature as RecoverableSignature, Signature as RecoverableSignature,
}, },
Signature, Signature,
VerifyKey, VerifyingKey,
}, },
EncodedPoint, EncodedPoint,
}; };
@ -71,6 +69,8 @@ use sha3::{
use generic_array::GenericArray; use generic_array::GenericArray;
use std::convert::TryFrom; use std::convert::TryFrom;
type HumanAddr = String;
// Chain ID of Terra // Chain ID of Terra
const CHAIN_ID: u16 = 3; const CHAIN_ID: u16 = 3;
@ -78,11 +78,8 @@ const CHAIN_ID: u16 = 3;
const FEE_AMOUNT: u128 = 10000; const FEE_AMOUNT: u128 = 10000;
pub const FEE_DENOMINATION: &str = "uluna"; pub const FEE_DENOMINATION: &str = "uluna";
pub fn init<S: Storage, A: Api, Q: Querier>( #[cfg_attr(not(feature = "library"), entry_point)]
deps: &mut Extern<S, A, Q>, pub fn instantiate(deps: DepsMut, _env: Env, msg: InstantiateMsg) -> StdResult<Response> {
_env: Env,
msg: InitMsg,
) -> StdResult<InitResponse> {
// Save general wormhole info // Save general wormhole info
let state = ConfigInfo { let state = ConfigInfo {
gov_chain: msg.gov_chain, gov_chain: msg.gov_chain,
@ -91,41 +88,39 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
guardian_set_expirity: msg.guardian_set_expirity, guardian_set_expirity: msg.guardian_set_expirity,
fee: Coin::new(FEE_AMOUNT, FEE_DENOMINATION), // 0.01 Luna (or 10000 uluna) fee by default fee: Coin::new(FEE_AMOUNT, FEE_DENOMINATION), // 0.01 Luna (or 10000 uluna) fee by default
}; };
config(&mut deps.storage).save(&state)?; config(deps.storage).save(&state)?;
// Add initial guardian set to storage // Add initial guardian set to storage
guardian_set_set( guardian_set_set(
&mut deps.storage, deps.storage,
state.guardian_set_index, state.guardian_set_index,
&msg.initial_guardian_set, &msg.initial_guardian_set,
)?; )?;
Ok(InitResponse::default()) Ok(Response::default())
} }
pub fn handle<S: Storage, A: Api, Q: Querier>( #[cfg_attr(not(feature = "library"), entry_point)]
deps: &mut Extern<S, A, Q>, pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> {
env: Env,
msg: HandleMsg,
) -> StdResult<HandleResponse> {
match msg { match msg {
HandleMsg::PostMessage { message, nonce } => { ExecuteMsg::PostMessage { message, nonce } => {
handle_post_message(deps, env, &message.as_slice(), nonce) handle_post_message(deps, env, info, &message.as_slice(), nonce)
} }
HandleMsg::SubmitVAA { vaa } => handle_submit_vaa(deps, env, vaa.as_slice()), ExecuteMsg::SubmitVAA { vaa } => handle_submit_vaa(deps, env, info, vaa.as_slice()),
} }
} }
/// Process VAA message signed by quardians /// Process VAA message signed by quardians
fn handle_submit_vaa<S: Storage, A: Api, Q: Querier>( fn handle_submit_vaa(
deps: &mut Extern<S, A, Q>, deps: DepsMut,
env: Env, env: Env,
_info: MessageInfo,
data: &[u8], data: &[u8],
) -> StdResult<HandleResponse> { ) -> StdResult<Response> {
let state = config_read(&deps.storage).load()?; let state = config_read(deps.storage).load()?;
let vaa = parse_and_verify_vaa(&deps.storage, data, env.block.time)?; let vaa = parse_and_verify_vaa(deps.storage, data, env.block.time.seconds())?;
vaa_archive_add(&mut deps.storage, vaa.hash.as_slice())?; vaa_archive_add(deps.storage, vaa.hash.as_slice())?;
if state.gov_chain == vaa.emitter_chain && state.gov_address == vaa.emitter_address { if state.gov_chain == vaa.emitter_chain && state.gov_address == vaa.emitter_address {
if state.guardian_set_index != vaa.guardian_set_index { if state.guardian_set_index != vaa.guardian_set_index {
@ -139,11 +134,7 @@ fn handle_submit_vaa<S: Storage, A: Api, Q: Querier>(
ContractError::InvalidVAAAction.std_err() ContractError::InvalidVAAAction.std_err()
} }
fn handle_governance_payload<S: Storage, A: Api, Q: Querier>( fn handle_governance_payload(deps: DepsMut, env: Env, data: &Vec<u8>) -> StdResult<Response> {
deps: &mut Extern<S, A, Q>,
env: Env,
data: &Vec<u8>,
) -> StdResult<HandleResponse> {
let gov_packet = GovernancePacket::deserialize(&data)?; let gov_packet = GovernancePacket::deserialize(&data)?;
let module = String::from_utf8(gov_packet.module).unwrap(); let module = String::from_utf8(gov_packet.module).unwrap();
@ -170,8 +161,8 @@ fn handle_governance_payload<S: Storage, A: Api, Q: Querier>(
/// Parses raw VAA data into a struct and verifies whether it contains sufficient signatures of an /// Parses raw VAA data into a struct and verifies whether it contains sufficient signatures of an
/// active guardian set i.e. is valid according to Wormhole consensus rules /// active guardian set i.e. is valid according to Wormhole consensus rules
fn parse_and_verify_vaa<S: Storage>( fn parse_and_verify_vaa(
storage: &S, storage: &dyn Storage,
data: &[u8], data: &[u8],
block_time: u64, block_time: u64,
) -> StdResult<ParsedVAA> { ) -> StdResult<ParsedVAA> {
@ -239,18 +230,14 @@ fn parse_and_verify_vaa<S: Storage>(
Ok(vaa) Ok(vaa)
} }
fn vaa_update_guardian_set<S: Storage, A: Api, Q: Querier>( fn vaa_update_guardian_set(deps: DepsMut, env: Env, data: &Vec<u8>) -> StdResult<Response> {
deps: &mut Extern<S, A, Q>,
env: Env,
data: &Vec<u8>,
) -> StdResult<HandleResponse> {
/* Payload format /* Payload format
0 uint32 new_index 0 uint32 new_index
4 uint8 len(keys) 4 uint8 len(keys)
5 [][20]uint8 guardian addresses 5 [][20]uint8 guardian addresses
*/ */
let mut state = config_read(&deps.storage).load()?; let mut state = config_read(deps.storage).load()?;
let GuardianSetUpgrade { let GuardianSetUpgrade {
new_guardian_set_index, new_guardian_set_index,
@ -265,107 +252,72 @@ fn vaa_update_guardian_set<S: Storage, A: Api, Q: Querier>(
state.guardian_set_index = new_guardian_set_index; state.guardian_set_index = new_guardian_set_index;
guardian_set_set( guardian_set_set(deps.storage, state.guardian_set_index, &new_guardian_set)?;
&mut deps.storage,
state.guardian_set_index,
&new_guardian_set,
)?;
config(&mut deps.storage).save(&state)?; config(deps.storage).save(&state)?;
let mut old_guardian_set = guardian_set_get(&deps.storage, old_guardian_set_index)?; let mut old_guardian_set = guardian_set_get(deps.storage, old_guardian_set_index)?;
old_guardian_set.expiration_time = env.block.time + state.guardian_set_expirity; old_guardian_set.expiration_time = env.block.time.seconds() + state.guardian_set_expirity;
guardian_set_set(&mut deps.storage, old_guardian_set_index, &old_guardian_set)?; guardian_set_set(deps.storage, old_guardian_set_index, &old_guardian_set)?;
Ok(HandleResponse { Ok(Response::new()
messages: vec![], .add_attribute("action", "guardian_set_change")
log: vec![ .add_attribute("old", old_guardian_set_index.to_string())
log("action", "guardian_set_change"), .add_attribute("new", state.guardian_set_index.to_string()))
log("old", old_guardian_set_index),
log("new", state.guardian_set_index),
],
data: None,
})
} }
pub fn handle_set_fee<S: Storage, A: Api, Q: Querier>( pub fn handle_set_fee(deps: DepsMut, _env: Env, data: &Vec<u8>) -> StdResult<Response> {
deps: &mut Extern<S, A, Q>,
env: Env,
data: &Vec<u8>,
) -> StdResult<HandleResponse> {
let set_fee_msg = SetFee::deserialize(&data)?; let set_fee_msg = SetFee::deserialize(&data)?;
// Save new fees // Save new fees
let mut state = config_read(&mut deps.storage).load()?; let mut state = config_read(deps.storage).load()?;
state.fee = set_fee_msg.fee; state.fee = set_fee_msg.fee;
config(&mut deps.storage).save(&state)?; config(deps.storage).save(&state)?;
Ok(HandleResponse { Ok(Response::new()
messages: vec![], .add_attribute("action", "fee_change")
log: vec![ .add_attribute("new_fee.amount", state.fee.amount.to_string())
log("action", "fee_change"), .add_attribute("new_fee.denom", state.fee.denom.to_string()))
log("new_fee.amount", state.fee.amount),
log("new_fee.denom", state.fee.denom),
],
data: None,
})
} }
pub fn handle_transfer_fee<S: Storage, A: Api, Q: Querier>( pub fn handle_transfer_fee(deps: DepsMut, _env: Env, data: &Vec<u8>) -> StdResult<Response> {
deps: &mut Extern<S, A, Q>,
env: Env,
data: &Vec<u8>,
) -> StdResult<HandleResponse> {
let transfer_msg = TransferFee::deserialize(&data)?; let transfer_msg = TransferFee::deserialize(&data)?;
Ok(HandleResponse { Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Send {
messages: vec![CosmosMsg::Bank(BankMsg::Send { to_address: deps.api.addr_humanize(&transfer_msg.recipient)?.to_string(),
from_address: env.contract.address, amount: vec![transfer_msg.amount],
to_address: deps.api.human_address(&transfer_msg.recipient)?, })))
amount: vec![transfer_msg.amount],
})],
log: vec![],
data: None,
})
} }
fn handle_post_message<S: Storage, A: Api, Q: Querier>( fn handle_post_message(
deps: &mut Extern<S, A, Q>, deps: DepsMut,
env: Env, env: Env,
info: MessageInfo,
message: &[u8], message: &[u8],
nonce: u32, nonce: u32,
) -> StdResult<HandleResponse> { ) -> StdResult<Response> {
let state = config_read(&deps.storage).load()?; let state = config_read(deps.storage).load()?;
let fee = state.fee; let fee = state.fee;
// Check fee // Check fee
if !has_coins(env.message.sent_funds.as_ref(), &fee) { if !has_coins(info.funds.as_ref(), &fee) {
return ContractError::FeeTooLow.std_err(); return ContractError::FeeTooLow.std_err();
} }
let emitter = extend_address_to_32(&deps.api.canonical_address(&env.message.sender)?); let emitter = extend_address_to_32(&deps.api.addr_canonicalize(&info.sender.as_str())?);
let sequence = sequence_read(deps.storage, emitter.as_slice());
sequence_set(deps.storage, emitter.as_slice(), sequence + 1)?;
let sequence = sequence_read(&deps.storage, emitter.as_slice()); Ok(Response::new()
sequence_set(&mut deps.storage, emitter.as_slice(), sequence + 1)?; .add_attribute("message.message", hex::encode(message))
.add_attribute("message.sender", hex::encode(emitter))
Ok(HandleResponse { .add_attribute("message.chain_id", CHAIN_ID.to_string())
messages: vec![], .add_attribute("message.nonce", nonce.to_string())
log: vec![ .add_attribute("message.sequence", sequence.to_string())
log("message.message", hex::encode(message)), .add_attribute("message.block_time", env.block.time.seconds().to_string()))
log("message.sender", hex::encode(emitter)),
log("message.chain_id", CHAIN_ID),
log("message.nonce", nonce),
log("message.sequence", sequence),
log("message.block_time", env.block.time),
],
data: None,
})
} }
pub fn query<S: Storage, A: Api, Q: Querier>( pub fn query(deps: Deps, msg: QueryMsg) -> StdResult<Binary> {
deps: &Extern<S, A, Q>,
msg: QueryMsg,
) -> StdResult<Binary> {
match msg { match msg {
QueryMsg::GuardianSetInfo {} => to_binary(&query_guardian_set_info(deps)?), QueryMsg::GuardianSetInfo {} => to_binary(&query_guardian_set_info(deps)?),
QueryMsg::VerifyVAA { vaa, block_time } => to_binary(&query_parse_and_verify_vaa( QueryMsg::VerifyVAA { vaa, block_time } => to_binary(&query_parse_and_verify_vaa(
@ -378,11 +330,9 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
} }
} }
pub fn query_guardian_set_info<S: Storage, A: Api, Q: Querier>( pub fn query_guardian_set_info(deps: Deps) -> StdResult<GuardianSetInfoResponse> {
deps: &Extern<S, A, Q>, let state = config_read(deps.storage).load()?;
) -> StdResult<GuardianSetInfoResponse> { let guardian_set = guardian_set_get(deps.storage, state.guardian_set_index)?;
let state = config_read(&deps.storage).load()?;
let guardian_set = guardian_set_get(&deps.storage, state.guardian_set_index)?;
let res = GuardianSetInfoResponse { let res = GuardianSetInfoResponse {
guardian_set_index: state.guardian_set_index, guardian_set_index: state.guardian_set_index,
addresses: guardian_set.addresses, addresses: guardian_set.addresses,
@ -390,33 +340,28 @@ pub fn query_guardian_set_info<S: Storage, A: Api, Q: Querier>(
Ok(res) Ok(res)
} }
pub fn query_parse_and_verify_vaa<S: Storage, A: Api, Q: Querier>( pub fn query_parse_and_verify_vaa(
deps: &Extern<S, A, Q>, deps: Deps,
data: &[u8], data: &[u8],
block_time: u64, block_time: u64,
) -> StdResult<ParsedVAA> { ) -> StdResult<ParsedVAA> {
parse_and_verify_vaa(&deps.storage, data, block_time) parse_and_verify_vaa(deps.storage, data, block_time)
} }
// returns the hex of the 32 byte address we use for some address on this chain // returns the hex of the 32 byte address we use for some address on this chain
pub fn query_address_hex<S: Storage, A: Api, Q: Querier>( pub fn query_address_hex(deps: Deps, address: &HumanAddr) -> StdResult<GetAddressHexResponse> {
deps: &Extern<S, A, Q>,
address: &HumanAddr,
) -> StdResult<GetAddressHexResponse> {
Ok(GetAddressHexResponse { Ok(GetAddressHexResponse {
hex: hex::encode(extend_address_to_32(&deps.api.canonical_address(&address)?)), hex: hex::encode(extend_address_to_32(&deps.api.addr_canonicalize(&address)?)),
}) })
} }
pub fn query_state<S: Storage, A: Api, Q: Querier>( pub fn query_state(deps: Deps) -> StdResult<GetStateResponse> {
deps: &Extern<S, A, Q>, let state = config_read(deps.storage).load()?;
) -> StdResult<GetStateResponse> {
let state = config_read(&deps.storage).load()?;
let res = GetStateResponse { fee: state.fee }; let res = GetStateResponse { fee: state.fee };
Ok(res) Ok(res)
} }
fn keys_equal(a: &VerifyKey, b: &GuardianAddress) -> bool { fn keys_equal(a: &VerifyingKey, b: &GuardianAddress) -> bool {
let mut hasher = Keccak256::new(); let mut hasher = Keccak256::new();
let point: EncodedPoint = EncodedPoint::from(a); let point: EncodedPoint = EncodedPoint::from(a);

View File

@ -104,7 +104,6 @@ impl ContractError {
pub fn std(&self) -> StdError { pub fn std(&self) -> StdError {
StdError::GenericErr { StdError::GenericErr {
msg: format!("{}", self), msg: format!("{}", self),
backtrace: None,
} }
} }

View File

@ -5,6 +5,3 @@ pub mod msg;
pub mod state; pub mod state;
pub use crate::error::ContractError; pub use crate::error::ContractError;
#[cfg(all(target_arch = "wasm32", not(feature = "library")))]
cosmwasm_std::create_entry_points!(contract);

View File

@ -1,7 +1,6 @@
use cosmwasm_std::{ use cosmwasm_std::{
Binary, Binary,
Coin, Coin,
HumanAddr,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{ use serde::{
@ -14,8 +13,10 @@ use crate::state::{
GuardianSetInfo, GuardianSetInfo,
}; };
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg { pub struct InstantiateMsg {
pub gov_chain: u16, pub gov_chain: u16,
pub gov_address: Binary, pub gov_address: Binary,
@ -25,7 +26,7 @@ pub struct InitMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum HandleMsg { pub enum ExecuteMsg {
SubmitVAA { vaa: Binary }, SubmitVAA { vaa: Binary },
PostMessage { message: Binary, nonce: u32 }, PostMessage { message: Binary, nonce: u32 },
} }

View File

@ -1,6 +1,5 @@
use schemars::{ use schemars::{
JsonSchema, JsonSchema,
Set,
}; };
use serde::{ use serde::{
Deserialize, Deserialize,
@ -11,7 +10,6 @@ use cosmwasm_std::{
Binary, Binary,
CanonicalAddr, CanonicalAddr,
Coin, Coin,
HumanAddr,
StdResult, StdResult,
Storage, Storage,
Uint128, Uint128,
@ -37,6 +35,8 @@ use sha3::{
Keccak256, Keccak256,
}; };
type HumanAddr = String;
pub static CONFIG_KEY: &[u8] = b"config"; pub static CONFIG_KEY: &[u8] = b"config";
pub static GUARDIAN_SET_KEY: &[u8] = b"guardian_set"; pub static GUARDIAN_SET_KEY: &[u8] = b"guardian_set";
pub static SEQUENCE_KEY: &[u8] = b"sequence"; pub static SEQUENCE_KEY: &[u8] = b"sequence";
@ -217,62 +217,62 @@ pub struct WormholeInfo {
pub guardian_set_expirity: u64, pub guardian_set_expirity: u64,
} }
pub fn config<S: Storage>(storage: &mut S) -> Singleton<S, ConfigInfo> { pub fn config(storage: &mut dyn Storage) -> Singleton<ConfigInfo> {
singleton(storage, CONFIG_KEY) singleton(storage, CONFIG_KEY)
} }
pub fn config_read<S: Storage>(storage: &S) -> ReadonlySingleton<S, ConfigInfo> { pub fn config_read(storage: &dyn Storage) -> ReadonlySingleton<ConfigInfo> {
singleton_read(storage, CONFIG_KEY) singleton_read(storage, CONFIG_KEY)
} }
pub fn guardian_set_set<S: Storage>( pub fn guardian_set_set(
storage: &mut S, storage: &mut dyn Storage,
index: u32, index: u32,
data: &GuardianSetInfo, data: &GuardianSetInfo,
) -> StdResult<()> { ) -> StdResult<()> {
bucket(GUARDIAN_SET_KEY, storage).save(&index.to_be_bytes(), data) bucket(storage, GUARDIAN_SET_KEY).save(&index.to_be_bytes(), data)
} }
pub fn guardian_set_get<S: Storage>(storage: &S, index: u32) -> StdResult<GuardianSetInfo> { pub fn guardian_set_get(storage: &dyn Storage, index: u32) -> StdResult<GuardianSetInfo> {
bucket_read(GUARDIAN_SET_KEY, storage).load(&index.to_be_bytes()) bucket_read(storage, GUARDIAN_SET_KEY).load(&index.to_be_bytes())
} }
pub fn sequence_set<S: Storage>(storage: &mut S, emitter: &[u8], sequence: u64) -> StdResult<()> { pub fn sequence_set(storage: &mut dyn Storage, emitter: &[u8], sequence: u64) -> StdResult<()> {
bucket(SEQUENCE_KEY, storage).save(emitter, &sequence) bucket(storage, SEQUENCE_KEY).save(emitter, &sequence)
} }
pub fn sequence_read<S: Storage>(storage: &S, emitter: &[u8]) -> u64 { pub fn sequence_read(storage: &dyn Storage, emitter: &[u8]) -> u64 {
bucket_read(SEQUENCE_KEY, storage) bucket_read(storage, SEQUENCE_KEY)
.load(&emitter) .load(&emitter)
.or::<u64>(Ok(0)) .or::<u64>(Ok(0))
.unwrap() .unwrap()
} }
pub fn vaa_archive_add<S: Storage>(storage: &mut S, hash: &[u8]) -> StdResult<()> { pub fn vaa_archive_add(storage: &mut dyn Storage, hash: &[u8]) -> StdResult<()> {
bucket(GUARDIAN_SET_KEY, storage).save(hash, &true) bucket(storage, GUARDIAN_SET_KEY).save(hash, &true)
} }
pub fn vaa_archive_check<S: Storage>(storage: &S, hash: &[u8]) -> bool { pub fn vaa_archive_check(storage: &dyn Storage, hash: &[u8]) -> bool {
bucket_read(GUARDIAN_SET_KEY, storage) bucket_read(storage, GUARDIAN_SET_KEY)
.load(&hash) .load(&hash)
.or::<bool>(Ok(false)) .or::<bool>(Ok(false))
.unwrap() .unwrap()
} }
pub fn wrapped_asset<S: Storage>(storage: &mut S) -> Bucket<S, HumanAddr> { pub fn wrapped_asset(storage: &mut dyn Storage) -> Bucket<HumanAddr> {
bucket(WRAPPED_ASSET_KEY, storage) bucket(storage, WRAPPED_ASSET_KEY)
} }
pub fn wrapped_asset_read<S: Storage>(storage: &S) -> ReadonlyBucket<S, HumanAddr> { pub fn wrapped_asset_read(storage: &dyn Storage) -> ReadonlyBucket<HumanAddr> {
bucket_read(WRAPPED_ASSET_KEY, storage) bucket_read(storage, WRAPPED_ASSET_KEY)
} }
pub fn wrapped_asset_address<S: Storage>(storage: &mut S) -> Bucket<S, Vec<u8>> { pub fn wrapped_asset_address(storage: &mut dyn Storage) -> Bucket<Vec<u8>> {
bucket(WRAPPED_ASSET_ADDRESS_KEY, storage) bucket(storage, WRAPPED_ASSET_ADDRESS_KEY)
} }
pub fn wrapped_asset_address_read<S: Storage>(storage: &S) -> ReadonlyBucket<S, Vec<u8>> { pub fn wrapped_asset_address_read(storage: &dyn Storage) -> ReadonlyBucket<Vec<u8>> {
bucket_read(WRAPPED_ASSET_ADDRESS_KEY, storage) bucket_read(storage, WRAPPED_ASSET_ADDRESS_KEY)
} }
pub struct GovernancePacket { pub struct GovernancePacket {
@ -351,7 +351,7 @@ impl SetFee {
let (_, amount) = data.get_u256(0); let (_, amount) = data.get_u256(0);
let fee = Coin { let fee = Coin {
denom: String::from(FEE_DENOMINATION), denom: String::from(FEE_DENOMINATION),
amount: Uint128(amount), amount: Uint128::new(amount),
}; };
Ok(SetFee { fee }) Ok(SetFee { fee })
} }
@ -371,7 +371,7 @@ impl TransferFee {
let (_, amount) = data.get_u256(32); let (_, amount) = data.get_u256(32);
let amount = Coin { let amount = Coin {
denom: String::from(FEE_DENOMINATION), denom: String::from(FEE_DENOMINATION),
amount: Uint128(amount), amount: Uint128::new(amount),
}; };
Ok(TransferFee { amount, recipient }) Ok(TransferFee { amount, recipient })
} }