fix bytes -> string, flip arg order to be less confusing
Change-Id: I952b73628e56bc9449e5525bfd85e57851c20143
This commit is contained in:
parent
c8bc1b57cc
commit
2c56a916eb
|
@ -268,9 +268,7 @@ fn handle_governance_payload<S: Storage, A: Api, Q: Querier>(
|
||||||
data: &Vec<u8>,
|
data: &Vec<u8>,
|
||||||
) -> StdResult<HandleResponse> {
|
) -> StdResult<HandleResponse> {
|
||||||
let gov_packet = GovernancePacket::deserialize(&data)?;
|
let gov_packet = GovernancePacket::deserialize(&data)?;
|
||||||
|
let module = get_string_from_32(&gov_packet.module)?;
|
||||||
let module = String::from_utf8(gov_packet.module).unwrap();
|
|
||||||
let module: String = module.chars().filter(|c| c != &'\0').collect();
|
|
||||||
|
|
||||||
if module != "TokenBridge" {
|
if module != "TokenBridge" {
|
||||||
return Err(StdError::generic_err("this is not a valid module"));
|
return Err(StdError::generic_err("this is not a valid module"));
|
||||||
|
@ -407,6 +405,8 @@ fn handle_complete_transfer<S: Storage, A: Api, Q: Querier>(
|
||||||
let recipient = deps.api.human_address(&target_address)?;
|
let recipient = deps.api.human_address(&target_address)?;
|
||||||
let contract_addr = deps.api.human_address(&token_address)?;
|
let contract_addr = deps.api.human_address(&token_address)?;
|
||||||
|
|
||||||
|
// note -- here the amount is the amount the recipient will receive;
|
||||||
|
// amount + fee is the total sent
|
||||||
receive_native(&mut deps.storage, &token_address, Uint128(amount + fee))?;
|
receive_native(&mut deps.storage, &token_address, Uint128(amount + fee))?;
|
||||||
|
|
||||||
// undo normalization to 8 decimals
|
// undo normalization to 8 decimals
|
||||||
|
|
|
@ -61,16 +61,12 @@ pub fn extend_string_to_32(s: &String) -> StdResult<Vec<u8>> {
|
||||||
return Err(StdError::generic_err("string more than 32 "));
|
return Err(StdError::generic_err("string more than 32 "));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result = vec![0; 32 - bytes.len()];
|
let result = vec![0; 32 - bytes.len()];
|
||||||
result.extend(bytes);
|
Ok([bytes.to_vec(), result].concat())
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_string_from_32(v: &Vec<u8>) -> StdResult<String> {
|
pub fn get_string_from_32(v: &Vec<u8>) -> StdResult<String> {
|
||||||
let mut idx = 31usize;
|
let s = String::from_utf8(v.clone())
|
||||||
while v[idx] == 0 {
|
.or_else(|_| Err(StdError::generic_err("could not parse string")))?;
|
||||||
idx -= 1
|
Ok(s.chars().filter(|c| c != &'\0').collect())
|
||||||
}
|
|
||||||
String::from_utf8(v[..idx + 1].to_vec())
|
|
||||||
.or_else(|_| Err(StdError::generic_err("could not parse string")))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,8 +252,8 @@ pub fn wrapped_asset_address_read<S: Storage>(storage: &S) -> ReadonlyBucket<S,
|
||||||
|
|
||||||
pub struct GovernancePacket {
|
pub struct GovernancePacket {
|
||||||
pub module: Vec<u8>,
|
pub module: Vec<u8>,
|
||||||
pub chain: u16,
|
|
||||||
pub action: u8,
|
pub action: u8,
|
||||||
|
pub chain: u16,
|
||||||
pub payload: Vec<u8>,
|
pub payload: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +267,8 @@ impl GovernancePacket {
|
||||||
|
|
||||||
Ok(GovernancePacket {
|
Ok(GovernancePacket {
|
||||||
module,
|
module,
|
||||||
chain,
|
|
||||||
action,
|
action,
|
||||||
|
chain,
|
||||||
payload,
|
payload,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue