generated from okp4/template-rust
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
27 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
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,55 @@ | ||
use std::env::var; | ||
use cosmwasm_std::{Attribute, Event, SubMsg, to_binary, WasmMsg}; | ||
use logic_bindings::{AskResponse, Substitution}; | ||
use crate::ContractError; | ||
use crate::state::Object; | ||
use cw_storage::msg::ExecuteMsg as StorageMsg; | ||
use crate::ContractError::NotImplemented; | ||
|
||
pub fn get_reply_event_attribute(events: Vec<Event>, key: String) -> Option<String> { | ||
let r = events.iter() | ||
.flat_map(|e| e.attributes.clone()) | ||
.filter(|a| a.key == key) | ||
.map(|a| a.value) | ||
.collect::<Vec<String>>(); | ||
|
||
if r.len() > 0 { Some(r[0].clone())} else { None } | ||
} | ||
|
||
/// Files terms is List atom, List is represented as String in prolog, filter to remove | ||
/// all paterm to represent the list and return the result as Vec<String>. | ||
fn filter_source_files(substitution: Substitution) -> Vec<String> { | ||
substitution.term.name.split(",") | ||
.into_iter() | ||
.map(|s| s.replace(&['\'', '[', ']'], "")) | ||
.collect::<Vec<String>>() | ||
} | ||
|
||
fn uri_to_object(uri: String) -> Result<Object, ContractError> { | ||
Err(NotImplemented {}) | ||
} | ||
|
||
pub fn ask_response_to_submsg(res: AskResponse, storage_addr: String, variable: String) -> Result<Vec<SubMsg>, ContractError> { | ||
let uris = res.answer | ||
.map(|a| a.results) | ||
.unwrap_or(vec![]) | ||
.iter() | ||
.flat_map(|result| result.substitutions.clone()) | ||
.filter(|s| s.variable == variable) | ||
.flat_map(|s| filter_source_files(s)) | ||
.collect::<Vec<String>>(); | ||
|
||
let mut msgs = vec![]; | ||
for uri in uris { | ||
let object = uri_to_object(uri)?; | ||
let msg = WasmMsg::Execute { | ||
contract_addr: storage_addr.to_string(), | ||
msg: to_binary(&StorageMsg::PinObject { | ||
id: object.object_id, | ||
})?, | ||
funds: vec![], | ||
}; | ||
msgs.push(SubMsg::new(msg)) | ||
} | ||
return Ok(msgs) | ||
} |
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
#![forbid(unsafe_code)] | ||
#![deny( | ||
warnings, | ||
rust_2018_idioms, | ||
trivial_casts, | ||
trivial_numeric_casts, | ||
unused_lifetimes, | ||
unused_import_braces, | ||
unused_qualifications, | ||
unused_qualifications | ||
)] | ||
// #![forbid(unsafe_code)] | ||
// #![deny( | ||
// warnings, | ||
// rust_2018_idioms, | ||
// trivial_casts, | ||
// trivial_numeric_casts, | ||
// unused_lifetimes, | ||
// unused_import_braces, | ||
// unused_qualifications, | ||
// unused_qualifications | ||
// )] | ||
|
||
pub mod contract; | ||
mod error; | ||
pub mod msg; | ||
pub mod state; | ||
mod helper; | ||
|
||
pub use crate::error::ContractError; |