Skip to content

Commit

Permalink
Merge pull request #219 from rainlanguage/2024-02-10-tauri-mac-unsigned
Browse files Browse the repository at this point in the history
fix(tauri): add default signing identity
  • Loading branch information
thedavidmeister authored Feb 11, 2024
2 parents fa6ee66 + ca755e2 commit 3e6ae8c
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 313 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "CAL-1.0"
homepage = "https://github.com/rainprotocol/rain.orderbook"

[workspace.dependencies]
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "c00a8b8f00802e8291f64b9a89494b83ce9c8169" }
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "846dae9034c79f3935a0021635c9a6ee2d91f13e" }
alloy-sol-types = { version = "0.5.4" }
alloy-primitives = "0.5.4"
alloy-json-abi = "0.5.4"
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rain_interpreter_dispair = { workspace = true }
rain_interpreter_parser = { workspace = true }
serde_bytes = { workspace = true }
forker = { workspace = true }
tokio = { workspace = true }

[dev-dependencies]
tokio = { workspace = true }
10 changes: 5 additions & 5 deletions crates/common/src/add_order.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
front_matter::{try_parse_frontmatter, FrontMatterError},
lsp_services::LANG_SERVICES,
dotrain_add_order_lsp::LANG_SERVICES,
frontmatter::{try_parse_frontmatter, FrontmatterError},
transaction::{TransactionArgs, TransactionArgsError},
};
use alloy_ethers_typecast::transaction::{
Expand All @@ -27,7 +27,7 @@ pub enum AddOrderArgsError {
#[error("Empty Front Matter")]
EmptyFrontmatter,
#[error("Front Matter: {0}")]
FrontmatterError(#[from] FrontMatterError),
FrontmatterError(#[from] FrontmatterError),
#[error(transparent)]
DISPairError(#[from] DISPairError),
#[error(transparent)]
Expand Down Expand Up @@ -116,11 +116,11 @@ impl AddOrderArgs {
// Parse file into dotrain document
let meta_store = LANG_SERVICES.meta_store();

let front_matter = RainDocument::get_front_matter(&self.dotrain)
let frontmatter = RainDocument::get_front_matter(&self.dotrain)
.ok_or(AddOrderArgsError::EmptyFrontmatter)?;

// Prepare call
let (deployer, valid_inputs, valid_outputs, rebinds) = try_parse_frontmatter(front_matter)?;
let (deployer, valid_inputs, valid_outputs, rebinds) = try_parse_frontmatter(frontmatter)?;

let dotrain_doc =
RainDocument::create(self.dotrain.clone(), Some(meta_store), None, rebinds);
Expand Down
84 changes: 84 additions & 0 deletions crates/common/src/dotrain_add_order_lsp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::add_order::ORDERBOOK_ORDER_ENTRYPOINTS;
use crate::frontmatter::try_parse_frontmatter_rebinds;
use crate::rainlang::parse_rainlang_on_fork;
use dotrain::{
error::{ComposeError, ErrorCode},
types::ast::Problem,
RainDocument, Rebind,
};
use dotrain_lsp::{
lsp_types::{CompletionItem, Hover, Position, TextDocumentItem},
RainLanguageServices,
};
use once_cell::sync::Lazy;

/// static lang services instance
/// meta store instance can be taken from this for shared access to a unfied meta store across
/// all the dotrain usage in this crate
pub static LANG_SERVICES: Lazy<RainLanguageServices> = Lazy::new(RainLanguageServices::default);

pub struct DotrainAddOrderLsp {
text_document: TextDocumentItem,
frontmatter: String,
rebinds: Option<Vec<Rebind>>,
}

impl DotrainAddOrderLsp {
pub fn new(text_document: TextDocumentItem) -> Self {
let frontmatter = RainDocument::get_front_matter(&text_document.text);
let rebinds = frontmatter.and_then(try_parse_frontmatter_rebinds);

Self {
text_document: text_document.clone(),
frontmatter: frontmatter.unwrap_or("").to_string(),
rebinds,
}
}

/// get hover for a given text document item
pub fn hover(&self, position: Position) -> Option<Hover> {
LANG_SERVICES.do_hover(&self.text_document, position, None, self.rebinds.clone())
}

/// get completion items for a given text document item
pub fn completion(&self, position: Position) -> Option<Vec<CompletionItem>> {
LANG_SERVICES.do_complete(&self.text_document, position, None, self.rebinds.clone())
}

/// get problems for a given text document item
pub async fn problems(&self, rpc_url: &str, block_number: Option<u64>) -> Vec<Problem> {
let rain_document =
LANG_SERVICES.new_rain_document(&self.text_document, self.rebinds.clone());
let all_problems = rain_document.all_problems();
if !all_problems.is_empty() {
all_problems.iter().map(|&v| v.clone()).collect()
} else {
let rainlang = match rain_document.compose(&ORDERBOOK_ORDER_ENTRYPOINTS) {
Ok(v) => v,
Err(e) => match e {
ComposeError::Reject(msg) => {
return vec![Problem {
msg,
position: [0, 0],
code: ErrorCode::NativeParserError,
}]
}
ComposeError::Problems(problems) => return problems,
},
};

parse_rainlang_on_fork(&self.frontmatter, &rainlang, rpc_url, block_number)
.await
.map_or_else(
|e| {
vec![Problem {
msg: e.to_string(),
position: [0, 0],
code: ErrorCode::NativeParserError,
}]
},
|_| vec![],
)
}
}
}
21 changes: 18 additions & 3 deletions crates/common/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{front_matter::FrontMatterError, transaction::TransactionArgsError};
use crate::{frontmatter::FrontmatterError, transaction::TransactionArgsError};
use alloy_dyn_abi::JsonAbiExt;
use alloy_ethers_typecast::{client::LedgerClientError, transaction::WritableClientError};
use alloy_ethers_typecast::{
client::LedgerClientError,
transaction::{ReadableClientError, WritableClientError},
};
use alloy_json_abi::Error as AlloyError;
use forker::ForkedEvm;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -149,6 +152,8 @@ pub enum ForkCallError {
ForkCachePoisoned,
#[error("Missing expected cache key {0}")]
ForkCacheKeyMissing(String),
#[error(transparent)]
ReadableClientError(#[from] ReadableClientError),
}

impl From<AbiDecodeFailedErrors> for ForkCallError {
Expand All @@ -165,12 +170,16 @@ impl<'a> From<PoisonError<MutexGuard<'a, HashMap<String, ForkedEvm>>>> for ForkC

#[derive(Debug, Error)]
pub enum ForkParseError {
#[error("Fork Cache Poisoned")]
ForkCachePoisoned,
#[error(transparent)]
ForkCallFailed(#[from] ForkCallError),
#[error("{0}")]
AbiDecodedError(AbiDecodedErrorType),
#[error("Front Matter: {0}")]
FrontMatterError(#[from] FrontMatterError),
FrontmatterError(#[from] FrontmatterError),
#[error(transparent)]
ReadableClientError(#[from] ReadableClientError),
}

impl From<AbiDecodedErrorType> for ForkParseError {
Expand All @@ -179,6 +188,12 @@ impl From<AbiDecodedErrorType> for ForkParseError {
}
}

impl<'a> From<PoisonError<MutexGuard<'a, HashMap<String, ForkedEvm>>>> for ForkParseError {
fn from(_value: PoisonError<MutexGuard<'a, HashMap<String, ForkedEvm>>>) -> Self {
Self::ForkCachePoisoned
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 3e6ae8c

Please sign in to comment.