Skip to content

Commit

Permalink
fix: panic if no RPC/ACCOUNT variables provided (fixes #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Nov 7, 2023
1 parent 0345282 commit 657d100
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
6 changes: 3 additions & 3 deletions scripts/demo.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RPC = "KATANA"
ACCOUNT_ADDRESS = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
ACCOUNT_PRIVKEY = "0x1800000000300000180000000000030000000000003006001800006600"
-- RPC = "KATANA"
-- ACCOUNT_ADDRESS = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
-- ACCOUNT_PRIVKEY = "0x1800000000300000180000000000030000000000003006001800006600"

-- No args -> kipt.out, or the output filename.
-- If called several time, only the first one counts.
Expand Down
34 changes: 26 additions & 8 deletions src/lua.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use lazy_static::lazy_static;
use mlua::{Error as LuaError, Function, Lua, Number, Result as LuaResult, Table};
use mlua::{Function, Lua, Number, Result as LuaResult, Table};
use std::time::Duration;
use tokio::runtime::{Builder, Runtime};

use crate::error::ErrorExtLua;
use crate::{call, declare, deploy, invoke, invoke::InvokeCall, logger, transaction};

/// A simple trait to ensure that all
Expand Down Expand Up @@ -154,9 +153,19 @@ pub fn get_account(lua: &Lua) -> LuaResult<(String, String, String)> {

match (url_network, address, privkey) {
(Some(un), Some(a), Some(p)) => Ok((un, a, p)),
_ => Err(LuaError::ExternalError(std::sync::Arc::new(
ErrorExtLua::new("RPC / ACCOUNT_ADDRESS / ACCOUNT_PRIVKEY must be set"),
))),
_ => {
// Without RPC and account info, we can't send tx. Panic here.
panic!(
r#"
RPC, ACCOUNT_ADDRESS and ACCOUNT_PRIVKEY variables were required by a transaction, but one of them (or all) is not provided.
Please consider setting RPC, ACCOUNT_ADDRESS and ACCOUNT_PRIVKEY variables at the top of you Lua script without the local keyword.
RPC = "https://...."
ACCOUNT_ADDRESS = "0x123..."
ACCOUNT_PRIVKEY = "0x987..."
"#,
);
}
}
}

Expand All @@ -170,9 +179,18 @@ pub fn get_provider(lua: &Lua) -> LuaResult<String> {

match url_network {
Some(un) => Ok(un),
_ => Err(LuaError::ExternalError(std::sync::Arc::new(
ErrorExtLua::new("RPC must be set"),
))),
_ => {
// Without RPC, we can't make call. Panic here.
panic!(
r#"
RPC variable was required by a call, but it's not provided.
Please consider setting RPC variable at the top of you Lua script
without the local keyword.
RPC = "https://...."
"#,
);
}
}
}

Expand Down

0 comments on commit 657d100

Please sign in to comment.