From a536e8e11f1c835b44a81693fd5ef6215b76be54 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Tue, 7 Dec 2021 17:00:03 +0800 Subject: [PATCH] add readme --- README.md | 15 ++++++++------ backend/.gitignore | 2 ++ backend/build.gradle | 16 ++++++++------- .../org/bdware/sc/contractexample/Hello.java | 20 ++++++++++++++++--- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f277c14..7fcf942 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ idea开发合约的示例。 #### 软件架构 软件架构说明 +#### 配置cp 的lib +做一个软链接,将cp-bundle的build/output 软链接到 +backend/cplibs。 + + #### 前端sdk说明 1. 如何使用javascript sdk @@ -19,11 +24,9 @@ idea开发合约的示例。 #### 后端常用方法说明 -##### 配置cp 的lib - ##### 调用相同CP的yjs代码 - +参考: +Hello.callYJSInSameCP ##### 调用其他CP的yjs代码 - -##### 分片 - +参考: +Hello.callYJSInOtherCP diff --git a/backend/.gitignore b/backend/.gitignore index eb736a4..2643730 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,5 +1,7 @@ /.DS_Store/ /build/ +/cplibs/ +cplibs # Compiled class file *.class diff --git a/backend/build.gradle b/backend/build.gradle index 8f66307..ac97704 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -36,6 +36,8 @@ sourceSets { dependencies { api 'org.apache.logging.log4j:log4j-core:2.14.1' api 'org.apache.logging.log4j:log4j-api:2.14.1' + implementation fileTree(dir: 'cplibs', include: '*.jar') + implementation fileTree(dir: 'cplibs/lib/', include: '*.jar') testImplementation 'junit:junit:4.13.2' } @@ -49,15 +51,15 @@ task copyYJS(type: Copy) { into "./build/output/" } -task sourcesJar(type:Jar) { +task sourcesJar(type: Jar) { from sourceSets.main.allJava archiveClassifier = 'sources' } -task copyAssets(type: Copy){ +task copyAssets(type: Copy) { from "../front" into "./build/output/assets/" } -task mergeJar(dependsOn: ["sourcesJar", "jar"]){ +task mergeJar(dependsOn: ["sourcesJar", "jar"]) { doLast { org.bdware.datanet.YPKPacker.mergeJar("./backend/build/libs/$project.name-${project.version}.jar", "./backend/build/libs/$project.name-${project.version}-sources.jar", @@ -68,21 +70,21 @@ task mergeJar(dependsOn: ["sourcesJar", "jar"]){ task copyJar(type: Copy, dependsOn: ["mergeJar", ":backend:copyLibs"]) { from "./build/libs/$project.name-${project.version}-all.jar" into "./build/output" - rename { String fileName -> "gateway.jar" } + rename { String fileName -> "sc-example.jar" } doFirst { println "copyJar start" } } -task buildZip(type: Zip, dependsOn: ["copyAssets","copyJar", "copyYJS"]) { +task buildZip(type: Zip, dependsOn: ["copyAssets", "copyJar", "copyYJS"]) { from './build/output/' duplicatesStrategy = DuplicatesStrategy.INCLUDE archiveFileName = 'contractexample.zip' destinationDirectory = file('build/') } -task buildYPK (dependsOn:["buildZip"]){ +task buildYPK(dependsOn: ["buildZip"]) { doLast { - org.bdware.datanet.YPKPacker.staticPack("./backend/build/contractexample.zip","./backend/build/contractexample.ypk") + org.bdware.datanet.YPKPacker.staticPack("./backend/build/contractexample.zip", "./backend/build/contractexample.ypk") } } diff --git a/backend/src/main/java/org/bdware/sc/contractexample/Hello.java b/backend/src/main/java/org/bdware/sc/contractexample/Hello.java index 06e6227..eca9a29 100644 --- a/backend/src/main/java/org/bdware/sc/contractexample/Hello.java +++ b/backend/src/main/java/org/bdware/sc/contractexample/Hello.java @@ -1,12 +1,26 @@ package org.bdware.sc.contractexample; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.bdware.sc.ContractProcess; +import org.bdware.sc.boundry.JavaScriptEntry; -public class Hello{ +public class Hello { private static final Logger LOGGER = LogManager.getLogger(Hello.class); - public static void main(String[]args){ + public static void main(String[] args) { LOGGER.info("abc"); } - public static String call(){return "hello..dafdskf";} + + public static String call() { + return "hello..dafdskf"; + } + + public static String callYJSInSameCP() { + return ContractProcess.instance.executeContract("{\"action\":\"getOwner\"\",\"arg\":\"\"}"); + } + + public static Object callYJSInOtherCP() { + return JavaScriptEntry.executeContract("cid", "action", "arg"); + } } \ No newline at end of file