From c5d61e199a6f458aa5e70a9459b0481c420b7981 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:33:50 +0800 Subject: [PATCH 1/4] (console): add bcos3 wasm type support. (#184) * (console): add bcos3 wasm type support. * (console): add deploy wasm feature. --- build.gradle | 4 +- release_note.txt | 2 +- .../wecross/console/common/ConsoleUtils.java | 15 ++++- .../wecross/console/common/HelpInfo.java | 29 ++++++--- .../wecross/console/common/Version.java | 2 +- .../wecross/console/custom/BCOSCommand.java | 60 ++++++++++------- .../contracts/liquid/hello_world/.gitignore | 10 +++ .../hello_world/.liquid/abi_gen/Cargo.toml | 27 ++++++++ .../hello_world/.liquid/abi_gen/main.rs | 39 +++++++++++ .../contracts/liquid/hello_world/Cargo.toml | 61 ++++++++++++++++++ .../liquid/hello_world/hello_world.abi | 1 + .../liquid/hello_world/hello_world.wasm | Bin 0 -> 11778 bytes .../liquid/hello_world/hello_world_gm.wasm | Bin 0 -> 11778 bytes .../contracts/liquid/hello_world/src/lib.rs | 49 ++++++++++++++ 14 files changed, 263 insertions(+), 36 deletions(-) create mode 100755 src/main/resources/contracts/liquid/hello_world/.gitignore create mode 100755 src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/Cargo.toml create mode 100755 src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/main.rs create mode 100755 src/main/resources/contracts/liquid/hello_world/Cargo.toml create mode 100644 src/main/resources/contracts/liquid/hello_world/hello_world.abi create mode 100644 src/main/resources/contracts/liquid/hello_world/hello_world.wasm create mode 100644 src/main/resources/contracts/liquid/hello_world/hello_world_gm.wasm create mode 100755 src/main/resources/contracts/liquid/hello_world/src/lib.rs diff --git a/build.gradle b/build.gradle index d2e89c9..bb43144 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'java' apply plugin: 'jacoco' group = 'com.webank' -version = '1.3.0' +version = '1.3.1' sourceCompatibility = '1.8' repositories { @@ -47,7 +47,7 @@ dependencies { compile logger compile 'org.jline:jline:3.15.0' compile 'org.codehaus.groovy:groovy-all:3.0.10' - compile 'com.webank:wecross-java-sdk:1.3.0' + compile 'com.webank:wecross-java-sdk:1.3.1-SNAPSHOT' compile 'org.apache.commons:commons-compress:1.21' compile 'commons-io:commons-io:2.8.0' compile 'com.moandjiezana.toml:toml4j:0.7.2' diff --git a/release_note.txt b/release_note.txt index 8b3a022..23c38c2 100644 --- a/release_note.txt +++ b/release_note.txt @@ -1 +1 @@ -v1.3.0 \ No newline at end of file +v1.3.1 \ No newline at end of file diff --git a/src/main/java/com/webank/wecross/console/common/ConsoleUtils.java b/src/main/java/com/webank/wecross/console/common/ConsoleUtils.java index 8b14ca1..a0a9fe9 100644 --- a/src/main/java/com/webank/wecross/console/common/ConsoleUtils.java +++ b/src/main/java/com/webank/wecross/console/common/ConsoleUtils.java @@ -22,10 +22,21 @@ public class ConsoleUtils { public static final String BCOSGMType = "GM_BCOS2.0"; public static final String BCOSType3 = "BCOS3_ECDSA_EVM"; public static final String BCOSGMType3 = "BCOS3_GM_EVM"; + public static final String BCOSWASMType3 = "BCOS3_ECDSA_WASM"; + public static final String BCOSWASMGMType3 = "BCOS3_GM_WASM"; public static final List bcosChainList = - Arrays.asList(BCOSType, BCOSGMType, BCOSType3, BCOSGMType3); + Arrays.asList( + BCOSType, BCOSGMType, BCOSType3, BCOSGMType3, BCOSWASMType3, BCOSWASMGMType3); public static final List supportChainList = - Arrays.asList(fabricType, BCOSType, BCOSGMType, fabricType2, BCOSType3, BCOSGMType3); + Arrays.asList( + fabricType, + BCOSType, + BCOSGMType, + fabricType2, + BCOSType3, + BCOSGMType3, + BCOSWASMType3, + BCOSWASMGMType3); private static final Logger logger = LoggerFactory.getLogger(ConsoleUtils.class); public static boolean isValidPath(String path) { diff --git a/src/main/java/com/webank/wecross/console/common/HelpInfo.java b/src/main/java/com/webank/wecross/console/common/HelpInfo.java index 14bd815..245393a 100644 --- a/src/main/java/com/webank/wecross/console/common/HelpInfo.java +++ b/src/main/java/com/webank/wecross/console/common/HelpInfo.java @@ -350,17 +350,30 @@ public static void getCurrentTransactionIDHelp() { public static void BCOSDeployHelp() { ConsoleUtils.singleLine(); - System.out.println("Deploy contract and register contract info to CNS in BCOS chain "); - System.out.println("Usage: bcosDeploy [Path] [Source file path] [Class name] [Version]"); - System.out.println("Path -- e.g: [zone.chain.res], specify which the path to be deployed"); + System.out.println("Deploy contract and register contract info to CNS/BFS in BCOS chain "); + System.out.println("If you deploy Solidity contract:"); + System.out.println("\tUsage: bcosDeploy [Path] [Source file path] [Class name] [Version]"); System.out.println( - "Source file path from conf/ -- The solidity source code file path, e.g: HelloWorld.sol"); - System.out.println("Contract name -- The contract to be deploy"); - System.out.println("Version -- The contract version"); - System.out.println("Example:"); + "\tPath -- e.g: [zone.chain.res], specify which the path to be deployed"); System.out.println( - " bcosDeploy payment.bcos.HelloWorld contracts/solidity/HelloWorld.sol HelloWorld 1.0"); + "\tSource file path from conf/ -- The solidity source code file path, e.g: HelloWorld.sol"); + System.out.println("\tContract name -- The contract to be deploy"); + System.out.println("\tVersion -- The contract version"); + System.out.println("\tExample:"); + System.out.println( + " \tbcosDeploy payment.bcos.HelloWorld contracts/solidity/HelloWorld.sol HelloWorld 1.0"); ConsoleUtils.singleLine(); + System.out.println("If you deploy WASM contract:"); + System.out.println("\tUsage: bcosDeploy [Path] [BIN file path] [ABI file path]"); + System.out.println( + "\tPath -- e.g: [zone.chain.res], specify which the path to be deployed"); + System.out.println( + "\tBIN file path from conf/ -- The binary file after contract being compiled via cargo-liquid, e.g: hello_world.wasm"); + System.out.println( + "\tABI file path from conf/ -- The ABI file after contract being compiled via cargo-liquid, e.g: hello_world.abi"); + System.out.println("\tExample:"); + System.out.println( + " \tbcosDeploy payment.bcos3.HelloWorld contracts/liquid/hello_world.wasm contracts/liquid/hello_world.abi"); } public static void BCOSRegisterHelp() { diff --git a/src/main/java/com/webank/wecross/console/common/Version.java b/src/main/java/com/webank/wecross/console/common/Version.java index 69dd893..d93e36d 100644 --- a/src/main/java/com/webank/wecross/console/common/Version.java +++ b/src/main/java/com/webank/wecross/console/common/Version.java @@ -2,5 +2,5 @@ public class Version { - public static final String Version = "v1.3.0"; + public static final String Version = "v1.3.1"; } diff --git a/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java b/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java index 00b8719..1f2b855 100644 --- a/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java +++ b/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java @@ -8,6 +8,7 @@ import com.webank.wecross.console.exception.WeCrossConsoleException; import com.webank.wecrosssdk.rpc.WeCrossRPC; import com.webank.wecrosssdk.rpc.methods.response.CommandResponse; +import com.webank.wecrosssdk.rpc.methods.response.ResourceDetailResponse; import com.webank.wecrosssdk.utils.RPCUtils; import java.io.File; import java.util.*; @@ -36,40 +37,55 @@ public void deploy(String[] params) throws Exception { HelpInfo.BCOSDeployHelp(); return; } - if (params.length < 5) { + if (params.length < 4) { throw new WeCrossConsoleException(ErrorCode.PARAM_MISSING, "bcosDeploy"); } String path = params[1]; RPCUtils.checkPath(path); - String cnsName = path.split("\\.")[2]; - String sourcePath = params[2]; - String contractName = params[3]; - String version = params[4]; - + ResourceDetailResponse detail = weCrossRPC.detail(path).send(); + String stubType = detail.getResourceDetail().getStubType(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - org.springframework.core.io.Resource resource = resolver.getResource("file:" + sourcePath); - if (!resource.exists()) { - resource = resolver.getResource("classpath:" + sourcePath); + List args = new ArrayList<>(); + // BCOSDeployWasm [path] [abi] [bin] + if (stubType.contains("WASM")) { + String name = path.split("\\.")[2]; + String binContent = FileUtils.readFileContent(params[2]); + String abiContent = FileUtils.readFileContent(params[3]); + args.addAll(Arrays.asList(name, abiContent, binContent)); + for (int i = 4; i < params.length; i++) { + // for constructor + args.add(ConsoleUtils.parseString(params[i])); + } + } else { + String cnsName = path.split("\\.")[2]; + String sourcePath = params[2]; + String contractName = params[3]; + String version = params[4]; + + org.springframework.core.io.Resource resource = + resolver.getResource("file:" + sourcePath); if (!resource.exists()) { - logger.error("Source file: {} not exists", sourcePath); - throw new Exception("Source file: " + sourcePath + " not exists"); + resource = resolver.getResource("classpath:" + sourcePath); + if (!resource.exists()) { + logger.error("Source file: {} not exists", sourcePath); + throw new Exception("Source file: " + sourcePath + " not exists"); + } } - } - String filename = resource.getFilename(); - String realPath = resource.getFile().getAbsolutePath(); - String dir = realPath.substring(0, realPath.lastIndexOf(File.separator)) + File.separator; + String filename = resource.getFilename(); + String realPath = resource.getFile().getAbsolutePath(); + String dir = + realPath.substring(0, realPath.lastIndexOf(File.separator)) + File.separator; - String sourceContent = FileUtils.mergeSource(dir, filename, resolver, new HashSet<>()); + String sourceContent = FileUtils.mergeSource(dir, filename, resolver, new HashSet<>()); - List args = - new ArrayList<>(Arrays.asList(cnsName, sourceContent, contractName, version)); - for (int i = 5; i < params.length; i++) { - // for constructor - args.add(ConsoleUtils.parseString(params[i])); + args.addAll(Arrays.asList(cnsName, sourceContent, contractName, version)); + for (int i = 5; i < params.length; i++) { + // for constructor + args.add(ConsoleUtils.parseString(params[i])); + } } - CommandResponse response = weCrossRPC.customCommand("deploy", path, args.toArray()).send(); PrintUtils.printCommandResponse(response); } diff --git a/src/main/resources/contracts/liquid/hello_world/.gitignore b/src/main/resources/contracts/liquid/hello_world/.gitignore new file mode 100755 index 0000000..088ba6b --- /dev/null +++ b/src/main/resources/contracts/liquid/hello_world/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk diff --git a/src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/Cargo.toml b/src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/Cargo.toml new file mode 100755 index 0000000..84506b7 --- /dev/null +++ b/src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "abi-gen" +version = "1.0.0-rc2" +authors = ["vita-dounai "] +edition = "2018" +publish = false + +[[bin]] +name = "abi-gen" +path = "main.rs" + +[dependencies.contract] +path = "../../" +package = "hello_world" +default-features = false +features = ["liquid-abi-gen"] + +[dependencies.liquid_lang] +git = "https://github.com/WeBankBlockchain/liquid" +branch = "dev" +package = "liquid_lang" +default-features = false +features = ["contract-abi-gen"] + +[dependencies] +serde = "1.0" +serde_json = "1.0" \ No newline at end of file diff --git a/src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/main.rs b/src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/main.rs new file mode 100755 index 0000000..e09f403 --- /dev/null +++ b/src/main/resources/contracts/liquid/hello_world/.liquid/abi_gen/main.rs @@ -0,0 +1,39 @@ +use std::{collections::HashMap, env}; + +fn main() -> Result<(), std::io::Error> { + let mut abi = HashMap::new(); + + let contract_abi = ::generate_abi(); + + let mut local_abi = + Vec::with_capacity(contract_abi.event_abis.len() + contract_abi.fn_abis.len() + 1); + local_abi.extend( + contract_abi + .event_abis + .iter() + .map(|event_abi| liquid_lang::AbiKind::Event(event_abi.clone())), + ); + local_abi.push(liquid_lang::AbiKind::Constructor( + contract_abi.constructor_abi, + )); + local_abi.extend( + contract_abi + .fn_abis + .iter() + .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())), + ); + abi.insert(String::from("$local"), local_abi); + + for (iface_name, fn_abis) in contract_abi.iface_abis { + let fn_abis = fn_abis + .iter() + .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())) + .collect::>(); + abi.insert(iface_name, fn_abis); + } + + let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".into()); + std::fs::create_dir(&target_dir).ok(); + std::fs::write("hello_world.abi", serde_json::to_string(&abi).unwrap())?; + Ok(()) +} diff --git a/src/main/resources/contracts/liquid/hello_world/Cargo.toml b/src/main/resources/contracts/liquid/hello_world/Cargo.toml new file mode 100755 index 0000000..e82010a --- /dev/null +++ b/src/main/resources/contracts/liquid/hello_world/Cargo.toml @@ -0,0 +1,61 @@ +[package] +name = "hello_world" +version = "0.1.0" +authors = ["[your_name] "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +scale = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive", "full"] } + +liquid_lang = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_lang", default-features = false, features = ["contract"] } +liquid_primitives = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_primitives", default-features = false } +liquid_prelude = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_prelude", default-features = false } +liquid_macro = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_macro", default-features = false } +liquid_abi_gen = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_abi_gen", default-features = false, optional = true } + +[dev-dependencies] +predicates = "1.0.5" + +[lib] +name = "hello_world" +crate-type = [ + # Used for normal contract Wasm blobs. + "cdylib", + # Used for ABI generation. + "rlib", +] + +[features] +default = ["std"] +std = [ + "liquid_lang/std", + "scale/std", + "liquid_primitives/std", + "liquid_prelude/std", + "liquid_macro/std", +] +liquid-abi-gen = [ + "std", + "liquid_abi_gen", + "liquid_lang/contract-abi-gen", +] +gm = [ + "liquid_lang/gm", + "liquid_primitives/gm", +] + +[profile.release] +panic = "abort" +lto = true +opt-level = "z" +overflow-checks = true + +[workspace] +members = [ + ".liquid/abi_gen", +] +exclude = [ + ".liquid", +] diff --git a/src/main/resources/contracts/liquid/hello_world/hello_world.abi b/src/main/resources/contracts/liquid/hello_world/hello_world.abi new file mode 100644 index 0000000..f722f16 --- /dev/null +++ b/src/main/resources/contracts/liquid/hello_world/hello_world.abi @@ -0,0 +1 @@ +[{"inputs":[],"type":"constructor"},{"constant":true,"inputs":[],"name":"get","outputs":[{"internalType":"string","type":"string"}],"type":"function"},{"conflictFields":[{"kind":0,"path":[],"read_only":false,"slot":0}],"constant":false,"inputs":[{"internalType":"string","name":"name","type":"string"}],"name":"set","outputs":[],"type":"function"}] \ No newline at end of file diff --git a/src/main/resources/contracts/liquid/hello_world/hello_world.wasm b/src/main/resources/contracts/liquid/hello_world/hello_world.wasm new file mode 100644 index 0000000000000000000000000000000000000000..c4630677ed83c2e785a5ee13c697c1e67b87ea23 GIT binary patch literal 11778 zcmds-PmEpHUB}Nk_rAaPJGNBv|5UGHLwA ze==joBq(@n*Fu3Jkwq7&#KHy9E-FL?q7oZApe!O5s7sc!s6-ZNWuZ!RQBgkM-?{J2 z^Pf}*ijbJm%suy<-}#;2|KIPNbKS~?v)(!9PYzFIo12?{^HkW}bfdhz9p=Qmcqyy~3wv|l@Y?(~J%olkEY ztCv!k#^;#-+{&3VzqxX8<>k}Ax9T$ME@rx2o;~|ap8Hn2owq|Lc;9XZ zAM$PpJ@32y!nZx0zQ_jN=lQ_5bDw+1uWxq>m&1Q6^X{H@58CT1SGHWyc_43}T|Ik# zI=l8)weH?S4H!yK?%RJJSEB-+JaL?>D0>J7GDxdhhtK zb9H!O==3@t%8{QB?)jmMzU){><%{U+LD?;e2bh__TF8b>hQhgGx*$_vC1?4tzJHVn zL)NUp>M@%SUFM6F3@P}Hh0qn&0YY&xXc4CS1+iBYU(d4+Ce?;{7HHL*<54HJ#10I1 zM_oFqUTo>D9QD^m1%uT7}2fJl{7+=AxezR)ctQzMKN_&{a!BAZVYpVQp=%X#OGwg$zsif8QP`3JPkSX@1bvq#gt|DEGeI` zC4U=lPD^@7_mE!aM!Jj|Bs>OHhB@pV*I~&q{b;@j#n6)Yk(_lso+keOytr~b3C!?Wy6Up$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liquid/hello_world/src/lib.rs b/src/main/resources/contracts/liquid/hello_world/src/lib.rs new file mode 100755 index 0000000..71d5170 --- /dev/null +++ b/src/main/resources/contracts/liquid/hello_world/src/lib.rs @@ -0,0 +1,49 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use liquid::storage; +use liquid_lang as liquid; + +#[liquid::contract] +mod hello_world { + use super::*; + + #[liquid(storage)] + struct HelloWorld { + name: storage::Value, + } + + #[liquid(methods)] + impl HelloWorld { + pub fn new(&mut self) { + self.name.initialize(String::from("Alice")); + } + + pub fn get(&self) -> String { + self.name.clone() + } + + pub fn set(&mut self, name: String) { + self.name.set(name) + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[test] + fn get_works() { + let contract = HelloWorld::new(); + assert_eq!(contract.get(), "Alice"); + } + + #[test] + fn set_works() { + let mut contract = HelloWorld::new(); + + let new_name = String::from("Bob"); + contract.set(new_name.clone()); + assert_eq!(contract.get(), "Bob"); + } + } +} From d3e3d64e9d7740d72b0a510227ce742e572a3490 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Tue, 18 Jul 2023 21:31:04 +0800 Subject: [PATCH 2/4] (bcosCommand): fix wasm deploy bug. (#185) * (bcosCommand): fix wasm deploy bug. * (custom): fix bcos deploy wasm bug. --- .../com/webank/wecross/console/Shell.java | 2 +- .../wecross/console/common/FileUtils.java | 22 +++++++++++ .../wecross/console/common/HelpInfo.java | 3 +- .../wecross/console/common/PrintUtils.java | 1 + .../wecross/console/custom/BCOSCommand.java | 38 ++++++++++++++----- 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/webank/wecross/console/Shell.java b/src/main/java/com/webank/wecross/console/Shell.java index 0c5f343..ccdeaad 100644 --- a/src/main/java/com/webank/wecross/console/Shell.java +++ b/src/main/java/com/webank/wecross/console/Shell.java @@ -279,7 +279,7 @@ public static void main(String[] args) { case "bcosDeploy": { bcosCommand.deploy(params); - if (params.length >= 6 && isPath(params[1])) { + if (params.length >= 4 && isPath(params[1])) { JlineUtils.addPathCompleters(completers, params[1]); } break; diff --git a/src/main/java/com/webank/wecross/console/common/FileUtils.java b/src/main/java/com/webank/wecross/console/common/FileUtils.java index da0c2f3..07dabb4 100644 --- a/src/main/java/com/webank/wecross/console/common/FileUtils.java +++ b/src/main/java/com/webank/wecross/console/common/FileUtils.java @@ -19,6 +19,7 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.bouncycastle.util.encoders.Hex; import org.jline.reader.Completer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,6 +126,27 @@ public static String readFileContent(String fileName) throws IOException { } } + public static String readFileContentToHexString(String fileName) throws IOException { + try { + // to avoid path manipulation + fileName = fileName.replace("..", ""); + Path path; + + if (fileName.indexOf("classpath:") != 0) { + path = Paths.get(fileName); + } else { + // Start with "classpath:" + PathMatchingResourcePatternResolver resolver = + new PathMatchingResourcePatternResolver(); + path = Paths.get(resolver.getResource(fileName).getURI()); + } + return Hex.toHexString(Files.readAllBytes(path)); + } catch (Exception e) { + logger.error("Read file error: ", e); + throw new IOException("Read file error: " + e); + } + } + public static String readFileToBytesString(String filePath) throws Exception { String content = readFileContent(filePath); return Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8)); diff --git a/src/main/java/com/webank/wecross/console/common/HelpInfo.java b/src/main/java/com/webank/wecross/console/common/HelpInfo.java index 245393a..6d84383 100644 --- a/src/main/java/com/webank/wecross/console/common/HelpInfo.java +++ b/src/main/java/com/webank/wecross/console/common/HelpInfo.java @@ -358,7 +358,8 @@ public static void BCOSDeployHelp() { System.out.println( "\tSource file path from conf/ -- The solidity source code file path, e.g: HelloWorld.sol"); System.out.println("\tContract name -- The contract to be deploy"); - System.out.println("\tVersion -- The contract version"); + System.out.println( + "\tVersion -- The contract version, if chain version is BCOS3.0, should not use version"); System.out.println("\tExample:"); System.out.println( " \tbcosDeploy payment.bcos.HelloWorld contracts/solidity/HelloWorld.sol HelloWorld 1.0"); diff --git a/src/main/java/com/webank/wecross/console/common/PrintUtils.java b/src/main/java/com/webank/wecross/console/common/PrintUtils.java index a548803..a447012 100644 --- a/src/main/java/com/webank/wecross/console/common/PrintUtils.java +++ b/src/main/java/com/webank/wecross/console/common/PrintUtils.java @@ -163,6 +163,7 @@ public static void printRoutineIDResponse(XATransactionListResponse response) th public static void printCommandResponse(CommandResponse response) throws WeCrossConsoleException { + logger.debug("response: {}", response.getResult()); if (response == null) { throw new WeCrossConsoleException(ErrorCode.NO_RESPONSE, "Error: no response"); } else if (response.getErrorCode() != StatusCode.SUCCESS) { diff --git a/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java b/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java index 1f2b855..3decaca 100644 --- a/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java +++ b/src/main/java/com/webank/wecross/console/custom/BCOSCommand.java @@ -7,8 +7,9 @@ import com.webank.wecross.console.exception.ErrorCode; import com.webank.wecross.console.exception.WeCrossConsoleException; import com.webank.wecrosssdk.rpc.WeCrossRPC; +import com.webank.wecrosssdk.rpc.common.ResourceDetail; import com.webank.wecrosssdk.rpc.methods.response.CommandResponse; -import com.webank.wecrosssdk.rpc.methods.response.ResourceDetailResponse; +import com.webank.wecrosssdk.rpc.methods.response.ResourceResponse; import com.webank.wecrosssdk.utils.RPCUtils; import java.io.File; import java.util.*; @@ -42,15 +43,25 @@ public void deploy(String[] params) throws Exception { } String path = params[1]; + String chain = path.substring(0, path.lastIndexOf('.') + 1); RPCUtils.checkPath(path); - ResourceDetailResponse detail = weCrossRPC.detail(path).send(); - String stubType = detail.getResourceDetail().getStubType(); + String stubType = ""; + ResourceResponse resources = weCrossRPC.listResources(false).send(); + for (ResourceDetail resourceDetail : resources.getResources().getResourceDetails()) { + if (resourceDetail.getPath().startsWith(chain)) { + stubType = resourceDetail.getStubType(); + break; + } + } + if (stubType.equals("")) { + throw new WeCrossConsoleException(ErrorCode.INVALID_PATH, path); + } PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); List args = new ArrayList<>(); // BCOSDeployWasm [path] [abi] [bin] if (stubType.contains("WASM")) { String name = path.split("\\.")[2]; - String binContent = FileUtils.readFileContent(params[2]); + String binContent = FileUtils.readFileContentToHexString(params[2]); String abiContent = FileUtils.readFileContent(params[3]); args.addAll(Arrays.asList(name, abiContent, binContent)); for (int i = 4; i < params.length; i++) { @@ -58,10 +69,10 @@ public void deploy(String[] params) throws Exception { args.add(ConsoleUtils.parseString(params[i])); } } else { + // Solidity String cnsName = path.split("\\.")[2]; String sourcePath = params[2]; String contractName = params[3]; - String version = params[4]; org.springframework.core.io.Resource resource = resolver.getResource("file:" + sourcePath); @@ -80,10 +91,19 @@ public void deploy(String[] params) throws Exception { String sourceContent = FileUtils.mergeSource(dir, filename, resolver, new HashSet<>()); - args.addAll(Arrays.asList(cnsName, sourceContent, contractName, version)); - for (int i = 5; i < params.length; i++) { - // for constructor - args.add(ConsoleUtils.parseString(params[i])); + if (stubType.contains("BCOS3")) { + args.addAll(Arrays.asList(cnsName, sourceContent, contractName)); + for (int i = 4; i < params.length; i++) { + // for constructor + args.add(ConsoleUtils.parseString(params[i])); + } + } else { + String version = params[4]; + args.addAll(Arrays.asList(cnsName, sourceContent, contractName, version)); + for (int i = 5; i < params.length; i++) { + // for constructor + args.add(ConsoleUtils.parseString(params[i])); + } } } CommandResponse response = weCrossRPC.customCommand("deploy", path, args.toArray()).send(); From 90def9b635ff9d08ec7cdf0e313069c24ac0f371 Mon Sep 17 00:00:00 2001 From: kyonRay Date: Tue, 25 Jul 2023 10:52:46 +0800 Subject: [PATCH 3/4] (project): update version to 1.3.1. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index bb43144..55cb973 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ dependencies { compile logger compile 'org.jline:jline:3.15.0' compile 'org.codehaus.groovy:groovy-all:3.0.10' - compile 'com.webank:wecross-java-sdk:1.3.1-SNAPSHOT' + compile 'com.webank:wecross-java-sdk:1.3.1' compile 'org.apache.commons:commons-compress:1.21' compile 'commons-io:commons-io:2.8.0' compile 'com.moandjiezana.toml:toml4j:0.7.2' From 62259552da586e5127e333874cf3e2b5882bcde9 Mon Sep 17 00:00:00 2001 From: kyonRay Date: Mon, 31 Jul 2023 18:51:36 +0800 Subject: [PATCH 4/4] (changelog): add change log of 1.3.1. --- Changelog.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Changelog.md b/Changelog.md index 985efbf..10f7913 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,12 @@ +### v1.3.1 + +(2023-07-31) + +**新增** + +* 支持FISCO BCOS 3.+ WASM执行版本,支持WASM合约部署、调用等功能。 + + ### v1.3.0 (2023-03-15)