add readme

add bdserver-docker
add yjs plugin
This commit is contained in:
CaiHQ 2022-05-20 23:31:40 +08:00
parent f372e358a1
commit 0ffd44aef7
14 changed files with 245 additions and 33 deletions

View File

@ -1,17 +1,69 @@
# contract-java-example
#### 介绍
idea开发合约的示例。
#### 配置cp 的lib
做一个软链接将cp-bundle的build/output 软链接到
backend/cplibs。
#### 测试环境配置
#### 配置grepcp.list
用于手动指定不打包的jar。 格式为每行一个jar名。
1. 在本地准备docker测试环境。
```bash
cd bdserver-docker-compose
docker-compose up -d
cat bdcontract/manager.keypair
#并复制这组{"publickey".."privateKey"}
```
2. 打开浏览器`http://127.0.0.1:21030/NodePortal.html`。点击右上角`欢迎04xx`按钮将步骤1中的keyPair复制并点`导入密钥`。
### 开发环境配置
可安装idea插件`ideaplugin/yjs-formater-1.0-SNAPSHOT-1653060411648.zip`
用于格式化yjs文件和自动补全。
#### 调试运行
1修改debugconf.json,将cpHost改为从docker可访问的域名或ip。
```
在MAC/Linux环境下可使用ifconfig | grep inet ,查看本地局域网ip并配置到cpHost字段。
在Windows环境下可使用"cpHost":"host.docker.internal"。
其中host.docker.internal是docker中内置的一个域名可用于访问host。
https://docs.docker.com/desktop/windows/networking/
```
示例的debugconf.json配置
```json
{
"agentAddress": "127.0.0.1:21030",
"publicKey": "04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610",
"privateKey": "1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b",
"ypkPath": "./backend/build/contractexample-1.3.0.ypk",
"killBeforeStart": "ContractExample",
"createParam": {
},
"cpHost": "host.docker.internal"
}
```
2.启动测试用例:
```
test/java/HelloTest.run
```
注意run方法中的`for (;;);`用于防止测试用例退出。
在windows中可能影响其他测试用例运行。可独立写个`public static void main(String[] args)`去运行合约。
#### 部署运行
部署至远程服务端执行":backend:deploy"任务:
即执行./backend/build.gradle 中的 deploy。
#### 前端sdk说明
1. 如何使用javascript sdk
2. 如何使用typescript sdk
3. 示例使用vite/vue/...等框架
@ -20,12 +72,14 @@ backend/cplibs。
##### 模拟后端数据
#### 后端常用方法说明
##### 调用相同CP的yjs代码
参考:
Hello.callYJSInSameCP
##### 调用其他CP的yjs代码
参考:
Hello.callYJSInOtherCP

1
backend/.gitignore vendored
View File

@ -1,4 +1,5 @@
/.DS_Store/
ContractDB
/build/
/cplibs/
cplibs

View File

@ -5,7 +5,7 @@ buildscript {
}
dependencies {
classpath "org.bdware.bdcontract:simple-ypk-packer:0.5.0"
classpath "org.bdware.bdcontract:ypk-deploy-tool:0.5.0"
classpath "org.bdware.bdcontract:ypk-deploy-tool:0.5.2"
}
}
plugins {
@ -40,7 +40,7 @@ sourceSets {
dependencies {
api 'org.apache.logging.log4j:log4j-core:2.17.2'
api 'org.apache.logging.log4j:log4j-api:2.17.2'
implementation 'org.bdware.sc:cp:1.5.4'
implementation 'org.bdware.sc:cp:1.5.7'
testImplementation 'junit:junit:4.13.2'
}
@ -73,7 +73,7 @@ task copyJar(type: Copy, dependsOn: [":backend:jar", ":backend:copyLibs"]) {
}
def reltivePath = "./backend"
//reltivePath="."
def currVersion = "1.2.0"
def currVersion = "1.3.0"
task grepCP(dependsOn: ["copyJar"]) {
doLast {
org.bdware.datanet.YPKPacker.grepJarByCPVersion("${reltivePath}/build/output/libs", org.bdware.datanet.CPVersion.cp_1_5_3)
@ -94,6 +94,6 @@ task buildYPK(dependsOn: ["buildZip"]) {
}
task deploy(dependsOn: ["buildYPK"]) {
doLast {
org.bdware.ypkdeploy.HTTPTool.deployWithYpk("./backend/deployconfig.json", "${reltivePath}/build/contractexample-${currVersion}.ypk")
org.bdware.ypkdeploy.HTTPTool.deployWithYpk("${reltivePath}/debugconf.json", "${reltivePath}/build/contractexample-${currVersion}.ypk")
}
}

10
backend/debugconf.json Normal file
View File

@ -0,0 +1,10 @@
{
"agentAddress": "127.0.0.1:21030",
"publicKey": "04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610",
"privateKey": "1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b",
"ypkPath": "./build/contractexample-1.3.0.ypk",
"killBeforeStart": "ContractExample",
"createParam": {
},
"cpHost": "host.docker.internal"
}

View File

@ -1,9 +0,0 @@
{
"agentAddress": "ip:port",
"privateKey": "e85ce2f4d8...",
"publicKey": "04da01345770b7e09d4774bf6cd67bf90b32eaa09f517c79b2d1f9b8a926",
"ypkPath": "./backend/build/contractexample-1.2.0.ypk",
"killBeforeStart": "ContractID/ContractName",
"createParam": {
}
}

View File

@ -0,0 +1,10 @@
import org.bdware.sc.debugger.DebugMain;
import org.junit.Test;
public class HelloTest {
@Test
public void run() {
DebugMain.runWithConf("./debugconf.json");
for (; ; ) ;
}
}

View File

@ -1,10 +1,9 @@
oracle ContractExample {
function onCreate() {
Global.owner = requester;
}
export function callHello(arg) {
return Hello.call()+requester;
return org.bdware.sc.contractexample.Hello.call()+requester;
}
export function getOwner() {
return Global.owner;

View File

@ -0,0 +1,32 @@
# 镜像准备
请提前熟悉docker常用命令主要包括`docker ps`、`docker image xx`、`docker kill`等。
1. 下载或导入镜像:
```bash
#下载镜像
docker pull bdware/bdcontract:latest
#导入镜像bdcontract-x.x.x.tar为待导入镜像文件。
docker load -i bdcontract-x.x.x.tar
```
2. 检查是否有"bdware/bdcontract:latest"镜像。
```bash
docker image ls | grep bdcontract
```
如果没有名为"bdware/bdcontract latest"的镜像,就将其中的最新版本打上。
docker image tag bdware/bdcontract:x.y.z bdware/bdcontract:latest
# 修改配置
1. 生成管理员密钥对。 将公钥配置到manager.key中。 格式为单行130个字符。类似于
```
04dad765858...
```
也可利用cp目录下的jar包自己生成:
```bash
#本操作需要依赖java 1.8以上环境。
java -cp cp/libs:cp/yjs.jar org.bdware.sc.SM2Helper generateKeyToFile
```
生成的文件请妥善保存。
2. 修改配置文件cmconfig.json如果需要配置文件参数详见配置说明`cmconfig.readme.md`。
3. 执行脚本`sh start.sh`

View File

@ -0,0 +1,23 @@
{
"cmi": "_1650424170416",
"debug": "",
"disableDoRepo": false,
"disableLocalLhs": false,
"doipCertPath": "",
"doipLhsAddress": "",
"doipPort": 21032,
"doipUserHandle": "",
"enableEventPersistence": false,
"enableSsl": "./ssl/chained.pem:./ssl/domain.pem",
"ip": "127.0.0.1",
"isLAN": true,
"overwrite": false,
"servicePort": 21030,
"textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv",
"withBdledgerClient": "./runnable/bdledger_mac",
"withBdledgerServer": false,
"consistencyPlugins": "/bdcontract/nosuchlib/custom-plugin.jar",
"startContract": [
],
"datachainConf": "bdledger:18021"
}

View File

@ -0,0 +1 @@
04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610

View File

@ -0,0 +1,2 @@
{ "publicKey": "04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610",
"privateKey": "1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b"}

View File

@ -0,0 +1,42 @@
node:
id: acb1cc2a7013ec8a7ea7eee0ec6f835851dd8e91
api:
grpc:
addr: :18021
http:
enabled: true
datastore:
source: /data/block
p2p:
identity:
peerId: QmeG9PE8NQ7q8M6xiovVp9u1UjZZWc8Wom1K5MomJgLuWs
privKey: CAASqQkwggSlAgEAAoIBAQDAb0X3U2HjgoUniXH8EMs6L8FHGU63BahbY+/7GjnVFXe0bSuPlpaUC2Twmhulvad/1nSCuF178UYoYQ6Qz1AwBl4IiZmQxhSXdZPEXrN3WnC70rrkMMQxz7sjevyEXm9EIUo4Hepxlvd6PlTHUaYOW4TXSsv5JqoZW4+itxane/tOCCpFM/ppftpz3N5RxO181mczm6cljHcShZXkHSxo0nn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OPi6+DstLFxtDEyPEQmsUl45NAu3QK+O3DWk6w9tUyF86cf2mBh3zypZTQ+uOmKErvww+pPuaVlPkbGHyItjLbJyi87Y6sQ8BANICb4D5ooQKBgQDHC6rQTaGIaOgAQzBzFPdi2foFEXTr9zpp0iVYdTFJr68OhROEkzQetHdk5MYR6SWjf3wQk34GDUqtVXNzoIhUkD6P83QCZKmsrkvYiQH0aXjAmjLpcDvSgUFCxS8NcaHKeDNLHw3SH8zh0zDFE1vlXdYzittDjmnYPGEEJzrUlg==
addresses:
swarm:
- /ip4/0.0.0.0/tcp/18026
- /ip4/0.0.0.0/udp/18026/quic
bootstrap:
- /ip4/127.0.0.1/tcp/18026/p2p/QmeG9PE8NQ7q8M6xiovVp9u1UjZZWc8Wom1K5MomJgLuWs
pubsub:
router: gossipsub
heartbeatInterval: 10000
query:
maxDuration: 3600 # seconds
maxRequestLifetime: 3.0 # seconds
waitReservedTime: 1.0 # seconds
nrw:
numWitness: 0
numBackup: 0
txsPerBlock: 1000
blockGenCycle: 30000
requestTimeout: 16
messageTimeout: 5
log:
format: text
level: INFO

View File

@ -0,0 +1,34 @@
version: "3"
services:
bdledger:
image: bdware/bdledger:dev-210909.874f034d
command: "-c /etc/bdledger/config.yml"
restart: unless-stopped
volumes:
- ./bdledger/config.yml:/etc/bdledger/config.yml:ro
- ./bdledger/data:/data
ports:
- "2416:2416" # P2P
- "2401:2401" # API
bdcontract:
image: bdware/bdcontract:1.7.9
command: "-Dfile.encoding=UTF-8 -Djava.library.path='./dynamicLibrary' -Dlog4j.configurationFile=./log4j2.properties -cp ./libs/*:bdagent.jar org.bdware.server.CMHttpServer"
restart: unless-stopped
depends_on:
- bdledger
volumes:
- ./bdcontract/rocksdb:/bdcontract/rocksdb
- ./bdcontract/ContractDB:/bdcontract/ContractDB
- ./bdcontract/ContractManagerDB:/bdcontract/ContractManagerDB
- ./bdcontract/BDWareProjectDir:/bdcontract/BDWareProjectDir
- ./bdcontract/cmconfig.json:/bdcontract/cmconfig.json:ro
# - ./bdcontract/cp:/bdcontract/cp
- ./bdcontract/tls:/bdcontract/tls:ro
- ./bdcontract/manager.key:/bdcontract/manager.key:ro
ports:
- "21030:21030" # Contract manager API
- "21031:21031" # Contract manager master
- "21032:21032" # DOA
- "21033:21033" # Prometheus exporter
- "21050-21100:21050-21100"

View File

@ -0,0 +1,13 @@
#!/bin/bash
docker-compose up -d
#export CURDIR=`pwd`/data
#
#docker run -p 21030-21033:21030-21033 -p 2641:2641 -p 2041:2041 -v $CURDIR/BDWareProjectDir:/bdcontract/BDWareProjectDir \
# -v $CURDIR/ContractDB:/bdcontract/ContractDB \
# -v $CURDIR/ContractManagerDB:/bdcontract/ContractManagerDB \
# -v $CURDIR/cmconfig.json:/bdcontract/cmconfig.json \
# -v $CURDIR/log:/bdcontract/log \
# -v $CURDIR/manager.key:/bdcontract/manager.key: \
# bdware/bdcontract:1.7.9
# -v $CURDIR/cp:/bdcontract/cp: \
# -v $CURDIR/keys:/bdcontract/keys: \