cosmwasm: Fix clippy warnings

This commit is contained in:
Chirantan Ekbote 2022-09-30 18:18:54 +09:00 committed by Evan Gray
parent dedcea34af
commit 8d6bf74262
14 changed files with 66 additions and 74 deletions

View File

@ -208,7 +208,7 @@ mod tests {
use cw20::TokenInfoResponse; use cw20::TokenInfoResponse;
fn get_balance(deps: Deps, address: HumanAddr) -> Uint128 { fn get_balance(deps: Deps, address: HumanAddr) -> Uint128 {
query_balance(deps, address.into()).unwrap().balance query_balance(deps, address).unwrap().balance
} }
fn do_init(mut deps: DepsMut, creator: &HumanAddr) { fn do_init(mut deps: DepsMut, creator: &HumanAddr) {
@ -261,7 +261,7 @@ mod tests {
let env = mock_env(); let env = mock_env();
let info = mock_info(creator, &[]); let info = mock_info(creator, &[]);
let res = execute(deps.branch(), env, info, msg.clone()).unwrap(); let res = execute(deps.branch(), env, info, msg).unwrap();
assert_eq!(0, res.messages.len()); assert_eq!(0, res.messages.len());
assert_eq!(get_balance(deps.as_ref(), mint_to.clone(),), amount); assert_eq!(get_balance(deps.as_ref(), mint_to.clone(),), amount);
@ -293,10 +293,7 @@ mod tests {
do_init(deps.as_mut(), &minter); do_init(deps.as_mut(), &minter);
let amount = Uint128::new(222_222_222); let amount = Uint128::new(222_222_222);
let msg = ExecuteMsg::Mint { let msg = ExecuteMsg::Mint { recipient, amount };
recipient: recipient.clone(),
amount,
};
let other_address = HumanAddr::from("other"); let other_address = HumanAddr::from("other");
let env = mock_env(); let env = mock_env();
@ -326,7 +323,7 @@ mod tests {
let env = mock_env(); let env = mock_env();
let info = mock_info(&owner, &[]); let info = mock_info(&owner, &[]);
let res = execute(deps.as_mut(), env, info, msg.clone()).unwrap(); let res = execute(deps.as_mut(), env, info, msg).unwrap();
assert_eq!(0, res.messages.len()); assert_eq!(0, res.messages.len());
assert_eq!(get_balance(deps.as_ref(), owner), Uint128::new(222_000_000)); assert_eq!(get_balance(deps.as_ref(), owner), Uint128::new(222_000_000));
assert_eq!(get_balance(deps.as_ref(), recipient), amount_transfer); assert_eq!(get_balance(deps.as_ref(), recipient), amount_transfer);
@ -344,12 +341,12 @@ mod tests {
let recipient = HumanAddr::from("recipient"); let recipient = HumanAddr::from("recipient");
let amount_transfer = Uint128::new(222_222); let amount_transfer = Uint128::new(222_222);
let msg = ExecuteMsg::Transfer { let msg = ExecuteMsg::Transfer {
recipient: recipient.clone(), recipient,
amount: amount_transfer, amount: amount_transfer,
}; };
let env = mock_env(); let env = mock_env();
let info = mock_info(&owner, &[]); let info = mock_info(&owner, &[]);
let _ = execute(deps.as_mut(), env, info, msg.clone()).unwrap_err(); // Will panic if no error let _ = execute(deps.as_mut(), env, info, msg).unwrap_err(); // Will panic if no error
} }
} }

View File

@ -7,7 +7,7 @@ use cw20::Expiration;
type HumanAddr = String; type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg { pub struct InstantiateMsg {
pub name: String, pub name: String,
pub symbol: String, pub symbol: String,
@ -18,19 +18,19 @@ pub struct InstantiateMsg {
pub init_hook: Option<InitHook>, pub init_hook: Option<InitHook>,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InitHook { pub struct InitHook {
pub msg: Binary, pub msg: Binary,
pub contract_addr: HumanAddr, pub contract_addr: HumanAddr,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InitMint { pub struct InitMint {
pub recipient: HumanAddr, pub recipient: HumanAddr,
pub amount: Uint128, pub amount: Uint128,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct MigrateMsg {} pub struct MigrateMsg {}
@ -94,7 +94,7 @@ pub enum ExecuteMsg {
UpdateMetadata { name: String, symbol: String }, UpdateMetadata { name: String, symbol: String },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum QueryMsg { pub enum QueryMsg {
// Generic information about the wrapped asset // Generic information about the wrapped asset
@ -113,7 +113,7 @@ pub enum QueryMsg {
}, },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WrappedAssetInfoResponse { pub struct WrappedAssetInfoResponse {
pub asset_chain: u16, // Asset chain id pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address in the original chain pub asset_address: Binary, // Asset smart contract address in the original chain

View File

@ -7,7 +7,7 @@ use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset"; pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset";
// Created at initialization and reference original asset and bridge address // Created at initialization and reference original asset and bridge address
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WrappedAssetInfo { pub struct WrappedAssetInfo {
pub asset_chain: u16, // Asset chain id pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address on the original chain pub asset_address: Binary, // Asset smart contract address on the original chain

View File

@ -59,7 +59,7 @@ fn do_mint(
) { ) {
let mint_msg = ExecuteMsg::Mint { let mint_msg = ExecuteMsg::Mint {
recipient: recipient.to_string(), recipient: recipient.to_string(),
amount: amount.clone(), amount: *amount,
}; };
let info = mock_info(INITIALIZER, &[]); let info = mock_info(INITIALIZER, &[]);
let handle_response: Response = execute(deps.as_mut(), mock_env(), info, mint_msg).unwrap(); let handle_response: Response = execute(deps.as_mut(), mock_env(), info, mint_msg).unwrap();
@ -74,7 +74,7 @@ fn do_transfer(
) { ) {
let transfer_msg = ExecuteMsg::Transfer { let transfer_msg = ExecuteMsg::Transfer {
recipient: recipient.to_string(), recipient: recipient.to_string(),
amount: amount.clone(), amount: *amount,
}; };
let env = mock_env(); let env = mock_env();
let info = mock_info(sender.as_str(), &[]); let info = mock_info(sender.as_str(), &[]);
@ -116,8 +116,8 @@ fn check_token_details(deps: &OwnedDeps<MockStorage, MockApi, MockQuerier>, supp
#[test] #[test]
fn init_works() { fn init_works() {
let mut deps = do_init(); let deps = do_init();
check_token_details(&mut deps, Uint128::new(0)); check_token_details(&deps, Uint128::new(0));
} }
#[test] #[test]
@ -126,7 +126,7 @@ fn query_works() {
let query_response = query(deps.as_ref(), mock_env(), QueryMsg::WrappedAssetInfo {}).unwrap(); let query_response = query(deps.as_ref(), mock_env(), QueryMsg::WrappedAssetInfo {}).unwrap();
assert_eq!( assert_eq!(
from_slice::<WrappedAssetInfoResponse>(&query_response.as_slice()).unwrap(), from_slice::<WrappedAssetInfoResponse>(query_response.as_slice()).unwrap(),
WrappedAssetInfoResponse { WrappedAssetInfoResponse {
asset_chain: 1, asset_chain: 1,
asset_address: vec![1; 32].into(), asset_address: vec![1; 32].into(),
@ -172,6 +172,6 @@ fn transfer_works() {
do_mint(&mut deps, &sender, &Uint128::new(123_123_123)); do_mint(&mut deps, &sender, &Uint128::new(123_123_123));
do_transfer(&mut deps, &sender, &recipient, &Uint128::new(123_123_000)); do_transfer(&mut deps, &sender, &recipient, &Uint128::new(123_123_000));
check_balance(&mut deps, &sender, &Uint128::new(123)); check_balance(&deps, &sender, &Uint128::new(123));
check_balance(&mut deps, &recipient, &Uint128::new(123_123_000)); check_balance(&deps, &recipient, &Uint128::new(123_123_000));
} }

View File

@ -4,22 +4,22 @@ use serde::{Deserialize, Serialize};
type HumanAddr = String; type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg { pub struct InstantiateMsg {
pub token_bridge_contract: HumanAddr, pub token_bridge_contract: HumanAddr,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum ExecuteMsg { pub enum ExecuteMsg {
CompleteTransferWithPayload { data: Binary }, CompleteTransferWithPayload { data: Binary },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct MigrateMsg {} pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum QueryMsg { pub enum QueryMsg {
WrappedRegistry { chain: u16, address: Binary }, WrappedRegistry { chain: u16, address: Binary },

View File

@ -9,7 +9,7 @@ type HumanAddr = String;
pub static CONFIG_KEY: &[u8] = b"config"; pub static CONFIG_KEY: &[u8] = b"config";
// Guardian set information // Guardian set information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Config { pub struct Config {
pub token_bridge_contract: HumanAddr, pub token_bridge_contract: HumanAddr,
} }

View File

@ -20,7 +20,7 @@ use wormhole::{
state::{vaa_archive_add, vaa_archive_check, GovernancePacket, ParsedVAA}, state::{vaa_archive_add, vaa_archive_check, GovernancePacket, ParsedVAA},
}; };
#[allow(unused_imports)] #[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point; use cosmwasm_std::entry_point;
use cosmwasm_std::{ use cosmwasm_std::{
@ -849,7 +849,7 @@ fn handle_complete_transfer_token(
amount = amount amount = amount
.checked_sub(fee) .checked_sub(fee)
.ok_or(StdError::generic_err("Insufficient funds"))?; .ok_or_else(|| StdError::generic_err("Insufficient funds"))?;
// Check high 128 bit of amount value to be empty // Check high 128 bit of amount value to be empty
if not_supported_amount != 0 || not_supported_fee != 0 { if not_supported_amount != 0 || not_supported_fee != 0 {
@ -997,7 +997,7 @@ fn handle_complete_transfer_token_native(
amount = amount amount = amount
.checked_sub(fee) .checked_sub(fee)
.ok_or(StdError::generic_err("Insufficient funds"))?; .ok_or_else(|| StdError::generic_err("Insufficient funds"))?;
// Check high 128 bit of amount value to be empty // Check high 128 bit of amount value to be empty
if not_supported_amount != 0 || not_supported_fee != 0 { if not_supported_amount != 0 || not_supported_fee != 0 {
@ -1106,7 +1106,7 @@ fn handle_initiate_transfer_token(
let mut submessages: Vec<SubMsg> = vec![]; let mut submessages: Vec<SubMsg> = vec![];
// we'll only need this for payload 3 transfers // we'll only need this for payload 3 transfers
let sender_address = deps.api.addr_canonicalize(&info.sender.to_string())?; let sender_address = deps.api.addr_canonicalize(info.sender.as_ref())?;
let sender_address = extend_address_to_32_array(&sender_address); let sender_address = extend_address_to_32_array(&sender_address);
match is_wrapped_asset_read(deps.storage).load(asset_canonical.as_slice()) { match is_wrapped_asset_read(deps.storage).load(asset_canonical.as_slice()) {
@ -1197,14 +1197,14 @@ fn handle_initiate_transfer_token(
.checked_rem(multiplier) .checked_rem(multiplier)
.and_then(|rem| amount.u128().checked_sub(rem)) .and_then(|rem| amount.u128().checked_sub(rem))
.map(Uint128::new) .map(Uint128::new)
.ok_or(StdError::generic_err("Insufficient funds"))?; .ok_or_else(|| StdError::generic_err("Insufficient funds"))?;
fee = fee fee = fee
.u128() .u128()
.checked_rem(multiplier) .checked_rem(multiplier)
.and_then(|rem| fee.u128().checked_sub(rem)) .and_then(|rem| fee.u128().checked_sub(rem))
.map(Uint128::new) .map(Uint128::new)
.ok_or(StdError::generic_err("Invalid fee"))?; .ok_or_else(|| StdError::generic_err("Invalid fee"))?;
// This is a regular asset, transfer its balance // This is a regular asset, transfer its balance
submessages.push(SubMsg::reply_on_success( submessages.push(SubMsg::reply_on_success(
@ -1397,7 +1397,7 @@ fn handle_initiate_transfer_native_token(
} }
} }
TransferType::WithPayload { payload } => { TransferType::WithPayload { payload } => {
let sender_address = deps.api.addr_canonicalize(&info.sender.to_string())?; let sender_address = deps.api.addr_canonicalize(info.sender.as_ref())?;
let sender_address = extend_address_to_32_array(&sender_address); let sender_address = extend_address_to_32_array(&sender_address);
let transfer_info = TransferWithPayloadInfo { let transfer_info = TransferWithPayloadInfo {
amount: (0, amount.u128()), amount: (0, amount.u128()),

View File

@ -9,7 +9,7 @@ type HumanAddr = String;
/// The instantiation parameters of the token bridge contract. See /// The instantiation parameters of the token bridge contract. See
/// [`crate::state::ConfigInfo`] for more details on what these fields mean. /// [`crate::state::ConfigInfo`] for more details on what these fields mean.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg { pub struct InstantiateMsg {
pub gov_chain: u16, pub gov_chain: u16,
pub gov_address: Binary, pub gov_address: Binary,
@ -68,11 +68,11 @@ pub enum ExecuteMsg {
}, },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct MigrateMsg {} pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum QueryMsg { pub enum QueryMsg {
WrappedRegistry { chain: u16, address: Binary }, WrappedRegistry { chain: u16, address: Binary },
@ -81,13 +81,13 @@ pub enum QueryMsg {
IsVaaRedeemed { vaa: Binary }, IsVaaRedeemed { vaa: Binary },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct WrappedRegistryResponse { pub struct WrappedRegistryResponse {
pub address: HumanAddr, pub address: HumanAddr,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct TransferInfoResponse { pub struct TransferInfoResponse {
pub amount: Uint128, pub amount: Uint128,
@ -99,13 +99,13 @@ pub struct TransferInfoResponse {
pub payload: Vec<u8>, pub payload: Vec<u8>,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct ExternalIdResponse { pub struct ExternalIdResponse {
pub token_id: TokenId, pub token_id: TokenId,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct IsVaaRedeemedResponse { pub struct IsVaaRedeemedResponse {
pub is_redeemed: bool, pub is_redeemed: bool,

View File

@ -12,7 +12,6 @@ use wormhole::byte_utils::ByteUtils;
use crate::token_address::{ExternalTokenId, WrappedCW20}; use crate::token_address::{ExternalTokenId, WrappedCW20};
type HumanAddr = String; type HumanAddr = String;
static CONFIG_KEY: &[u8] = b"config"; static CONFIG_KEY: &[u8] = b"config";
static TRANSFER_TMP_KEY: &[u8] = b"transfer_tmp"; static TRANSFER_TMP_KEY: &[u8] = b"transfer_tmp";
static WRAPPED_ASSET_KEY: &[u8] = b"wrapped_asset"; static WRAPPED_ASSET_KEY: &[u8] = b"wrapped_asset";
@ -30,7 +29,7 @@ static NATIVE_CW20_HASHES_KEY: &[u8] = b"native_cw20_hashes";
/// See [`crate::contract::migrate`] for details on why this is necessary. /// See [`crate::contract::migrate`] for details on why this is necessary.
/// Once the migration has been executed, this struct (and the corresponding /// Once the migration has been executed, this struct (and the corresponding
/// migration logic) can be deleted. /// migration logic) can be deleted.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ConfigInfoLegacy { pub struct ConfigInfoLegacy {
/// Governance chain (typically Solana, i.e. chain id 1) /// Governance chain (typically Solana, i.e. chain id 1)
pub gov_chain: u16, pub gov_chain: u16,
@ -47,7 +46,7 @@ pub struct ConfigInfoLegacy {
} }
/// Information about this contract's general parameters. /// Information about this contract's general parameters.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ConfigInfo { pub struct ConfigInfo {
/// Governance chain (typically Solana, i.e. chain id 1) /// Governance chain (typically Solana, i.e. chain id 1)
pub gov_chain: u16, pub gov_chain: u16,
@ -144,7 +143,7 @@ type Serialized128 = String;
/// Structure to keep track of an active CW20 transfer, required to pass state through to the reply /// Structure to keep track of an active CW20 transfer, required to pass state through to the reply
/// handler for submessages during a transfer. /// handler for submessages during a transfer.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferState { pub struct TransferState {
pub account: String, pub account: String,
pub message: Vec<u8>, pub message: Vec<u8>,
@ -227,7 +226,7 @@ impl TokenBridgeMessage {
// 98 u16 recipient_chain // 98 u16 recipient_chain
// 100 u256 fee // 100 u256 fee
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferInfo { pub struct TransferInfo {
pub amount: (u128, u128), pub amount: (u128, u128),
pub token_address: ExternalTokenId, pub token_address: ExternalTokenId,
@ -279,7 +278,7 @@ impl TransferInfo {
// 100 [u8; 32] sender_address // 100 [u8; 32] sender_address
// 132 [u8] payload // 132 [u8] payload
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferWithPayloadInfo { pub struct TransferWithPayloadInfo {
pub amount: (u128, u128), pub amount: (u128, u128),
pub token_address: ExternalTokenId, pub token_address: ExternalTokenId,

View File

@ -55,7 +55,7 @@ use crate::state::{
/// ///
/// For internal consumption of these addresses, we first convert them to /// For internal consumption of these addresses, we first convert them to
/// [`TokenId`] (see below). /// [`TokenId`] (see below).
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[repr(transparent)] #[repr(transparent)]
pub struct ExternalTokenId { pub struct ExternalTokenId {
bytes: [u8; 32], bytes: [u8; 32],
@ -116,7 +116,7 @@ impl ExternalTokenId {
} }
pub fn from_bank_token(denom: &String) -> StdResult<ExternalTokenId> { pub fn from_bank_token(denom: &String) -> StdResult<ExternalTokenId> {
let mut hash = hash(&denom.as_bytes()); let mut hash = hash(denom.as_bytes());
// override first byte with marker byte // override first byte with marker byte
hash[0] = 1; hash[0] = 1;
Ok(ExternalTokenId { bytes: hash }) Ok(ExternalTokenId { bytes: hash })
@ -142,7 +142,7 @@ impl ExternalTokenId {
/// granular. We do differentiate between bank tokens and CW20 tokens, but in /// granular. We do differentiate between bank tokens and CW20 tokens, but in
/// the latter case, we further differentiate between native CW20s and wrapped /// the latter case, we further differentiate between native CW20s and wrapped
/// CW20s (see [`ContractId`]). /// CW20s (see [`ContractId`]).
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub enum TokenId { pub enum TokenId {
Bank { denom: String }, Bank { denom: String },
Contract(ContractId), Contract(ContractId),
@ -163,7 +163,7 @@ impl TokenId {
TokenId::Bank { denom } => bank_token_hashes(storage).save(&external_id.bytes, denom), TokenId::Bank { denom } => bank_token_hashes(storage).save(&external_id.bytes, denom),
TokenId::Contract(contract) => match contract { TokenId::Contract(contract) => match contract {
ContractId::NativeCW20 { contract_address } => { ContractId::NativeCW20 { contract_address } => {
native_c20_hashes(storage).save(&external_id.bytes, &contract_address) native_c20_hashes(storage).save(&external_id.bytes, contract_address)
} }
ContractId::ForeignToken { ContractId::ForeignToken {
chain_id: _, chain_id: _,
@ -181,7 +181,7 @@ impl TokenId {
/// reason we represent the foreign address here instead of storing the wrapped /// reason we represent the foreign address here instead of storing the wrapped
/// CW20 contract's address directly is that the wrapped asset might not be /// CW20 contract's address directly is that the wrapped asset might not be
/// deployed yet. /// deployed yet.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub enum ContractId { pub enum ContractId {
NativeCW20 { NativeCW20 {
contract_address: Addr, contract_address: Addr,
@ -193,7 +193,7 @@ pub enum ContractId {
}, },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[repr(transparent)] #[repr(transparent)]
pub struct WrappedCW20 { pub struct WrappedCW20 {
pub human_address: Addr, pub human_address: Addr,

View File

@ -48,7 +48,7 @@ impl ByteUtils for &[u8] {
if self.get_u128_be(index) >> 32 == 0 { if self.get_u128_be(index) >> 32 == 0 {
return CanonicalAddr::from(&self[index + 12..index + 32]); return CanonicalAddr::from(&self[index + 12..index + 32]);
} }
return CanonicalAddr::from(&self[index..index + 32]); CanonicalAddr::from(&self[index..index + 32])
} }
fn get_bytes32(&self, index: usize) -> &[u8] { fn get_bytes32(&self, index: usize) -> &[u8] {
&self[index..index + 32] &self[index..index + 32]

View File

@ -8,7 +8,7 @@ type HumanAddr = String;
/// The instantiation parameters of the token bridge contract. See /// The instantiation parameters of the token bridge contract. See
/// [`crate::state::ConfigInfo`] for more details on what these fields mean. /// [`crate::state::ConfigInfo`] for more details on what these fields mean.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg { pub struct InstantiateMsg {
pub gov_chain: u16, pub gov_chain: u16,
pub gov_address: Binary, pub gov_address: Binary,
@ -21,18 +21,18 @@ pub struct InstantiateMsg {
pub fee_denom: String, pub fee_denom: String,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum ExecuteMsg { pub enum ExecuteMsg {
SubmitVAA { vaa: Binary }, SubmitVAA { vaa: Binary },
PostMessage { message: Binary, nonce: u32 }, PostMessage { message: Binary, nonce: u32 },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct MigrateMsg {} pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum QueryMsg { pub enum QueryMsg {
GuardianSetInfo {}, GuardianSetInfo {},
@ -41,14 +41,14 @@ pub enum QueryMsg {
QueryAddressHex { address: HumanAddr }, QueryAddressHex { address: HumanAddr },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct GuardianSetInfoResponse { pub struct GuardianSetInfoResponse {
pub guardian_set_index: u32, // Current guardian set index pub guardian_set_index: u32, // Current guardian set index
pub addresses: Vec<GuardianAddress>, // List of querdian addresses pub addresses: Vec<GuardianAddress>, // List of querdian addresses
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct WrappedRegistryResponse { pub struct WrappedRegistryResponse {
pub address: HumanAddr, pub address: HumanAddr,
@ -60,7 +60,7 @@ pub struct GetStateResponse {
pub fee: Coin, pub fee: Coin,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct GetAddressHexResponse { pub struct GetAddressHexResponse {
pub hex: String, pub hex: String,

View File

@ -72,7 +72,7 @@ pub struct ConfigInfo {
} }
// Validator Action Approval(VAA) data // Validator Action Approval(VAA) data
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ParsedVAA { pub struct ParsedVAA {
pub version: u8, pub version: u8,
pub guardian_set_index: u32, pub guardian_set_index: u32,
@ -185,7 +185,7 @@ impl ParsedVAA {
} }
// Guardian address // Guardian address
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct GuardianAddress { pub struct GuardianAddress {
pub bytes: Binary, // 20-byte addresses pub bytes: Binary, // 20-byte addresses
} }
@ -203,7 +203,7 @@ impl GuardianAddress {
} }
// Guardian set information // Guardian set information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct GuardianSetInfo { pub struct GuardianSetInfo {
pub addresses: Vec<GuardianAddress>, pub addresses: Vec<GuardianAddress>,
// List of guardian addresses // List of guardian addresses
@ -221,7 +221,7 @@ impl GuardianSetInfo {
} }
// Wormhole contract generic information // Wormhole contract generic information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WormholeInfo { pub struct WormholeInfo {
// Period for which a guardian set stays active after it has been replaced // Period for which a guardian set stays active after it has been replaced
pub guardian_set_expirity: u64, pub guardian_set_expirity: u64,
@ -258,8 +258,7 @@ pub fn sequence_set(storage: &mut dyn Storage, emitter: &[u8], sequence: u64) ->
pub fn sequence_read(storage: &dyn Storage, emitter: &[u8]) -> u64 { pub fn sequence_read(storage: &dyn Storage, emitter: &[u8]) -> u64 {
bucket_read(storage, SEQUENCE_KEY) bucket_read(storage, SEQUENCE_KEY)
.load(emitter) .load(emitter)
.or::<u64>(Ok(0)) .unwrap_or(0)
.unwrap()
} }
pub fn vaa_archive_add(storage: &mut dyn Storage, hash: &[u8]) -> StdResult<()> { pub fn vaa_archive_add(storage: &mut dyn Storage, hash: &[u8]) -> StdResult<()> {
@ -269,8 +268,7 @@ pub fn vaa_archive_add(storage: &mut dyn Storage, hash: &[u8]) -> StdResult<()>
pub fn vaa_archive_check(storage: &dyn Storage, hash: &[u8]) -> bool { pub fn vaa_archive_check(storage: &dyn Storage, hash: &[u8]) -> bool {
bucket_read(storage, GUARDIAN_SET_KEY) bucket_read(storage, GUARDIAN_SET_KEY)
.load(hash) .load(hash)
.or::<bool>(Ok(false)) .unwrap_or(false)
.unwrap()
} }
pub fn wrapped_asset(storage: &mut dyn Storage) -> Bucket<HumanAddr> { pub fn wrapped_asset(storage: &mut dyn Storage) -> Bucket<HumanAddr> {

View File

@ -11,8 +11,6 @@ use wormhole::{
state::{ConfigInfo, GuardianAddress, GuardianSetInfo, CONFIG_KEY}, state::{ConfigInfo, GuardianAddress, GuardianSetInfo, CONFIG_KEY},
}; };
use hex;
static INITIALIZER: &str = "initializer"; static INITIALIZER: &str = "initializer";
static GOV_ADDR: &[u8] = b"GOVERNANCE_ADDRESS"; static GOV_ADDR: &[u8] = b"GOVERNANCE_ADDRESS";
@ -58,10 +56,10 @@ fn do_init(guardians: &[GuardianAddress]) -> OwnedDeps<MockStorage, MockApi, Moc
#[test] #[test]
fn init_works() { fn init_works() {
let guardians = [GuardianAddress::from(GuardianAddress { let guardians = [GuardianAddress {
bytes: hex::decode("beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe") bytes: hex::decode("beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe")
.expect("Decoding failed") .expect("Decoding failed")
.into(), .into(),
})]; }];
let _deps = do_init(&guardians); let _deps = do_init(&guardians);
} }