赞
踩
目录: /root/xuperchain/output/
启动区块链网络
bash constrol.sh start
目录: /root/xuperchain/output/
创建tenant, landlord钱包账户,命令如下:
bin/xchain-cli account newkeys --output data/tenant
bin/xchain-cli account newkeys --output data/landlord
目录: /root/xuperchain/output/
通过data/tenant/address,data/landlord/address文件拿到钱包地址
cat data/tenant/address
cat daata/landlord/address
分别给两个地址分别转账,命令如下:
bin/xchain-cli transfer -to (address) --amount 10000000 --keys data/keys/ -H 127.0.0.1:37101
查看账余额,命令如下:
bin/xchain-cli account balance -- keys () -H 127.0.0.1:37101
目录: /root/Desktop
下载路径:http://res.handge.cn:8999/blockchain-6/blockchain-device-Part.3/09/front.zip
wget http://res.handge.cn:8999/blockchain-6/blockchain-devicePart.3/09/front.zip
将下载好的 front.zip 拖到桌面, 解压
unzip front.zip
在项目根目录下运行命令:
安装依赖:
npm install --unsafe-perm
启动:
npm run serve
运行成功弹出项目访问地址
终端输入如下命令,连接 mysql 数据库,密码为 123456
mysql -uroot -p
创建test数据库
create database test;
查看所有数据库
show databases;
使用test数据库
use test;
创建表
CREATE TABLE `house_leasing_contract` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '主键id', `landlord` varchar(255) NOT NULL COMMENT '房东的账户公钥', `tenant` varchar(255) NOT NULL COMMENT '租客的账户公钥', `rent_amount` bigint NOT NULL COMMENT '每月租金金额', `deposit_amount` bigint NOT NULL COMMENT '押金金额', `rent_due_date` int NOT NULL COMMENT '租金到期日', `lease_start_date` datetime NOT NULL COMMENT '租赁开始日期', `lease_end_date` datetime NOT NULL COMMENT '租赁开始日期', `lease_duration` int NOT NULL COMMENT '租赁期限', `contract_hash` varchar(255) NULL COMMENT '租赁协议的哈希值', `property_hash` varchar(255) NULL COMMENT '租赁物业信息的哈希值', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime NOT NULL COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=COMPACT;
打开Intellij IDEA, 点击新建项目,设置项目名为:house-leasing,项目位置:~/Desktop,语言: Java, 构建系统:Maven,JDK: 11, 点击创建。
修改包路径,将[org.example]改为[src],右键选中包名,依次选中【重构】–>【重命名】,重命 名软件包,如下图所示:
修改Maven依赖 文件地址:/root/Desktop/house-leasing/pom.xml 修改内容为:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.11</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.zhonghui</groupId> <artifactId>house-leasing</artifactId> <version>0.0.1-SNAPSHOT</version> <name>house-leasing</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.baidu.xuper</groupId> <artifactId>xuper-java-sdk</artifactId> <version>0.3.0</version> </dependency </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
编辑项目配置文件 /root/Desktop/house-leasing/src/main/resources 目录下创建application.properties文件
编辑配置文件内容:
server.port=8090
spring.datasource.url: jdbc:mysql://localhost:3306/test
spring.datasource.username: root
spring.datasource.password: 123456
spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
mybatis.type-aliases-package: src/entity
mybatis.mapper-locations: classpath:/mapper/*.xml
最后将桌面上的合约和编译文件拖入/root/Desktop/house-leasing/src/main/resources目录下, 如下图所示:
使用solc编译合约,进入 /root/Desktop/houseLeasing/src/main/resources目录下执行如下命令
./solc --abi --bin RentalAgreement.sol -o --output-dir
在/root/Desktop/HouseLeasing/src/main/resources/–output-dir目录下生成的abi和bin文件:
以下代码文件路径均为/root/Desktop/houseLeasing/src/main/的相对路径,完整的项目文件如下图所 示。
代码文件路径:java/src/HouseLeasingApplication.java
新建HouseLeasingApplication.java文件,实现构建xuperchain客户端, 获取账户,解决跨域请求, 时 间格式化等功能。代码如下
package src;
import com.baidu.xuper.api.Account;
import com.baidu.xuper.api.XuperClient;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。