diff --git a/Cargo.lock b/Cargo.lock index e6e4806..5b65603 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,7 +1071,7 @@ dependencies = [ [[package]] name = "kipt" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "async-trait", diff --git a/README.md b/README.md index 1dcabe7..f6cb810 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,14 @@ If you prefer a short cheatsheet, go [here](https://devhints.io/lua) or [here](h To test Kipt, the easiest way is: 1. Install Kipt + ```bash # 1. Install curl https://raw.githubusercontent.com/glihm/kipt/main/kiptup/install | sh source ~/.bashrc kiptup ``` + 2. Create a simple "demo.lua" script copying the example below, replacing with the name of your contract. 3. Spin up katana in an other terminal. 4. Run `kipt --lua ./demo.lua`. @@ -37,7 +39,7 @@ kiptup ```lua RPC = "KATANA" -ACCOUNT_ADDRESS = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973" +ACCOUNT_ADDRESS = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03" ACCOUNT_PRIVKEY = "0x1800000000300000180000000000030000000000003006001800006600" -- No args -> kipt.out diff --git a/book/src/globals_variables.md b/book/src/globals_variables.md index 8d09eb2..6a8976e 100644 --- a/book/src/globals_variables.md +++ b/book/src/globals_variables.md @@ -12,6 +12,9 @@ RPC = "GOERLI-1" ACCOUNT_ADDRESS = "0x1234...." ACCOUNT_PRIVKEY = "0x8888...." +-- If you're using a cairo 0 account, you will need legacy encoding. +-- ACCOUNT_IS_LEGACY = true + -- You can re-defined anywhere in the script a new value RPC = "http://0.0.0.0:5050" ``` @@ -27,6 +30,7 @@ As shown, some global variables are expected by Kipt: - `ACCOUNT_ADDRESS`: The address of the account to use to send transactions. - `ACCOUNT_PRIVKEY`: The private key of the account to use to send transactions. +- `ACCOUNT_IS_LEGACY`: Specifies if the account is a cairo 0 account. > ℹ️ **Note** > diff --git a/scripts/demo.lua b/scripts/demo.lua index e43f10e..c49632d 100644 --- a/scripts/demo.lua +++ b/scripts/demo.lua @@ -1,6 +1,6 @@ --- RPC = "KATANA" --- ACCOUNT_ADDRESS = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973" --- ACCOUNT_PRIVKEY = "0x1800000000300000180000000000030000000000003006001800006600" +RPC = "KATANA" +ACCOUNT_ADDRESS = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03" +ACCOUNT_PRIVKEY = "0x1800000000300000180000000000030000000000003006001800006600" -- No args -> kipt.out, or the output filename. -- If called several time, only the first one counts. diff --git a/src/account.rs b/src/account.rs index 93e2160..162f33d 100644 --- a/src/account.rs +++ b/src/account.rs @@ -38,6 +38,7 @@ pub async fn setup_account( url_network: &str, account_address: &str, account_privkey: &str, + is_legacy: bool, ) -> KiptResult> { let provider = if url_network.starts_with("http") { provider_from_url(url_network)? @@ -52,8 +53,11 @@ pub async fn setup_account( let signer = LocalWallet::from(SigningKey::from_secret_scalar(key)); - let account = - SingleOwnerAccount::new(provider, signer, addr, chain_id, ExecutionEncoding::Legacy); + let account = if is_legacy { + SingleOwnerAccount::new(provider, signer, addr, chain_id, ExecutionEncoding::Legacy) + } else { + SingleOwnerAccount::new(provider, signer, addr, chain_id, ExecutionEncoding::New) + }; Ok(account) } diff --git a/src/declare.rs b/src/declare.rs index 7e6a3fd..4e7e225 100644 --- a/src/declare.rs +++ b/src/declare.rs @@ -49,7 +49,7 @@ pub fn lua_declare<'lua>( contract_name: String, options: Table<'lua>, ) -> LuaResult> { - let (url_network, address, privkey) = lua::get_account(lua)?; + let (url_network, address, privkey, is_legacy) = lua::get_account(lua)?; let artifacts_path: Option = options.get("artifacts_path")?; let is_recursive: bool = options.get("artifacts_recursively")?; let skip_if_declared: bool = options.get("skip_if_declared")?; @@ -59,15 +59,16 @@ pub fn lua_declare<'lua>( let data = futures::executor::block_on(async move { RT.spawn(async move { - let account = match account::setup_account(&url_network, &address, &privkey).await { - Ok(a) => a, - Err(e) => { - return LuaOutput { - data: None, - error: format!("{:?}", e), + let account = + match account::setup_account(&url_network, &address, &privkey, is_legacy).await { + Ok(a) => a, + Err(e) => { + return LuaOutput { + data: None, + error: format!("{:?}", e), + } } - } - }; + }; let (sierra_path, casm_path) = match locate_artifacts( &contract_name, diff --git a/src/deploy.rs b/src/deploy.rs index 9734f16..b40a4ff 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -43,7 +43,7 @@ pub fn lua_deploy<'lua>( args: Vec, options: Table<'lua>, ) -> LuaResult> { - let (url_network, address, privkey) = lua::get_account(lua)?; + let (url_network, address, privkey, is_legacy) = lua::get_account(lua)?; let watch_interval = lua::get_watch_from_options(&options)?; let salt: Option = options.get("salt")?; @@ -52,15 +52,16 @@ pub fn lua_deploy<'lua>( let data = futures::executor::block_on(async move { RT.spawn(async move { - let account = match account::setup_account(&url_network, &address, &privkey).await { - Ok(a) => a, - Err(e) => { - return LuaOutput { - data: None, - error: format!("{:?}", e), + let account = + match account::setup_account(&url_network, &address, &privkey, is_legacy).await { + Ok(a) => a, + Err(e) => { + return LuaOutput { + data: None, + error: format!("{:?}", e), + } } - } - }; + }; match deploy_tx(account, &sierra_class_hash, &args, salt, watch_interval).await { Ok((deployed_address, depl_res)) => LuaOutput { diff --git a/src/error.rs b/src/error.rs index cb50f50..594e5e8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,13 +29,13 @@ pub enum Error { #[error(transparent)] ContractJson(#[from] JsonError), #[error(transparent)] - AccountError(#[from] AccountError>), + Account(#[from] AccountError>), #[error(transparent)] Anyhow(#[from] anyhow::Error), #[error("Contract artifacts is missing: {0}")] ArtifactsMissing(String), #[error(transparent)] - NonAsciiNameError(#[from] NonAsciiNameError), + NonAsciiName(#[from] NonAsciiNameError), } impl From for LuaError { diff --git a/src/invoke.rs b/src/invoke.rs index 338fdaf..a8a811e 100644 --- a/src/invoke.rs +++ b/src/invoke.rs @@ -63,7 +63,7 @@ pub fn lua_invoke<'lua>( calls: Vec, options: Table<'lua>, ) -> LuaResult> { - let (url_network, address, privkey) = lua::get_account(lua)?; + let (url_network, address, privkey, is_legacy) = lua::get_account(lua)?; let watch_interval = lua::get_watch_from_options(&options)?; @@ -74,15 +74,16 @@ pub fn lua_invoke<'lua>( let data = futures::executor::block_on(async move { RT.spawn(async move { - let account = match account::setup_account(&url_network, &address, &privkey).await { - Ok(a) => a, - Err(e) => { - return LuaOutput { - data: None, - error: format!("{:?}", e), + let account = + match account::setup_account(&url_network, &address, &privkey, is_legacy).await { + Ok(a) => a, + Err(e) => { + return LuaOutput { + data: None, + error: format!("{:?}", e), + } } - } - }; + }; match invoke_tx(account, calls, watch_interval).await { Ok(invk_res) => LuaOutput { diff --git a/src/lua.rs b/src/lua.rs index 5d70725..349d001 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -146,13 +146,20 @@ fn setup_starknet_funcs(lua: &Lua) -> LuaResult<()> { /// # Arguments /// /// * `lua` - Lua VM instance. -pub fn get_account(lua: &Lua) -> LuaResult<(String, String, String)> { +pub fn get_account(lua: &Lua) -> LuaResult<(String, String, String, bool)> { let url_network: Option = lua.globals().get("RPC")?; let address: Option = lua.globals().get("ACCOUNT_ADDRESS")?; let privkey: Option = lua.globals().get("ACCOUNT_PRIVKEY")?; + let is_legacy: Option = lua.globals().get("ACCOUNT_IS_LEGACY")?; match (url_network, address, privkey) { - (Some(un), Some(a), Some(p)) => Ok((un, a, p)), + (Some(un), Some(a), Some(p)) => { + if let Some(true) = is_legacy { + Ok((un, a, p, true)) + } else { + Ok((un, a, p, false)) + } + } _ => { // Without RPC and account info, we can't send tx. Panic here. panic!(