Skip to content

Commit a13d279

Browse files
committed
Initial commit
0 parents  commit a13d279

50 files changed

Lines changed: 3896 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# IDEA Project files
2+
.idea/
3+
*.iml
4+
5+
# Build and Release Folders
6+
target/
7+
bin-debug/
8+
bin-release/
9+
[Oo]bj/
10+
[Bb]in/
11+
12+
# Other files and folders
13+
.settings/
14+
15+
# Executables
16+
*.swf
17+
*.air
18+
*.ipa
19+
*.apk
20+
21+
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
22+
# should NOT be excluded as they contain compiler settings and other important
23+
# information for Eclipse / Flash Builder.

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# LatteCoin
2+
LatteCoin是一个使用Java开发的、基于SpringBoot框架的、基于国密算法与群签名的可溯源区块链模拟系统

pom.xml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.lzw.blockchain</groupId>
8+
<artifactId>LatteCoin</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>LatteCoin</name>
13+
<description>a Traceable and anonymous blockchain system</description>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<parent>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-parent</artifactId>
24+
<version>2.4.2</version>
25+
<relativePath/>
26+
</parent>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-web</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-devtools</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.fasterxml.jackson.core</groupId>
39+
<artifactId>jackson-core</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.fasterxml.jackson.core</groupId>
43+
<artifactId>jackson-databind</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.projectlombok</groupId>
47+
<artifactId>lombok</artifactId>
48+
<optional>true</optional>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-data-jpa</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-starter-logging</artifactId>
57+
</dependency>
58+
<!-- 视图模板 -->
59+
<dependency>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
62+
</dependency>
63+
<!-- 数据库连接驱动 -->
64+
<dependency>
65+
<groupId>mysql</groupId>
66+
<artifactId>mysql-connector-java</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>cn.hutool</groupId>
70+
<artifactId>hutool-all</artifactId>
71+
<version>5.5.9</version>
72+
</dependency>
73+
<!-- 密码学套件 -->
74+
<dependency>
75+
<groupId>org.bouncycastle</groupId>
76+
<artifactId>bcprov-jdk15on</artifactId>
77+
<version>1.68</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>it.unisa.dia.gas</groupId>
81+
<artifactId>jpbc-pbc</artifactId>
82+
<version>2.0.0</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>it.unisa.dia.gas</groupId>
86+
<artifactId>jpbc-api</artifactId>
87+
<version>2.0.0</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>it.unisa.dia.gas</groupId>
91+
<artifactId>jpbc-plaf</artifactId>
92+
<version>2.0.0</version>
93+
</dependency>
94+
</dependencies>
95+
96+
<build>
97+
<plugins>
98+
<plugin>
99+
<groupId>org.springframework.boot</groupId>
100+
<artifactId>spring-boot-maven-plugin</artifactId>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.latte.blockchain;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
7+
/**
8+
* @author float311
9+
* @since 2021/01/31
10+
*/
11+
@SpringBootApplication
12+
public class LatteCoin {
13+
public static void main(String[] args) {
14+
SpringApplication.run(LatteCoin.class, args);
15+
}
16+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.latte.blockchain.controller;
2+
3+
import com.latte.blockchain.service.IUserService;
4+
import com.latte.blockchain.service.IChainService;
5+
import com.latte.blockchain.service.ITransactionService;
6+
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.PostMapping;
12+
import org.springframework.web.bind.annotation.RequestParam;
13+
import org.springframework.ui.Model;
14+
15+
/**
16+
* @author float311
17+
* @since 2021/01/31
18+
*/
19+
@Controller
20+
public class LatteChainController {
21+
22+
@Autowired
23+
private IUserService userService;
24+
25+
@Autowired
26+
private IChainService chainService;
27+
28+
@Autowired
29+
private ITransactionService transactionService;
30+
31+
/**
32+
* 初始化LatteChain区块链系统,初始化预置账户并创建创世块
33+
*/
34+
@GetMapping("/init")
35+
public String initSystem(Model model) {
36+
if (chainService.initChain()) {
37+
return "init";
38+
} else {
39+
model.addAttribute("msg", "初始化失败,已初始化或系统错误!");
40+
return "error";
41+
}
42+
}
43+
44+
/**
45+
* 查看当前所有的账户信息
46+
*/
47+
@GetMapping("/allUsersInfo")
48+
public String getAllUsersInfo(Model model) {
49+
model.addAttribute("usersInfo", userService.getAllUsersInfo());
50+
return "allUsers";
51+
}
52+
53+
/**
54+
* 交易发起接口
55+
*
56+
* @param sender 发起方账户地址
57+
* @param recipient 接受方账户地址
58+
* @param value 交易金额
59+
* @return String
60+
*/
61+
@PostMapping(path = "/trade")
62+
public String sendFunds(@RequestParam(name = "sender") String sender,
63+
@RequestParam(name = "recipient") String recipient,
64+
@RequestParam(name = "value") float value,
65+
Model model) {
66+
model.addAttribute("transactionInfo",
67+
transactionService.createTransaction(sender, recipient, value));
68+
return "transaction";
69+
}
70+
71+
/**
72+
* 对指定的交易进行追踪
73+
*
74+
* @param id 待审计交易
75+
* @return 交易链信息
76+
*/
77+
@PostMapping(path = "/auditTransaction")
78+
public String audit(@RequestParam(name = "transactionId") String id, Model model) {
79+
model.addAttribute("traceResult", transactionService.auditTransaction(id));
80+
return "auditResult";
81+
}
82+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.latte.blockchain.entity;
2+
3+
import it.unisa.dia.gas.jpbc.Element;
4+
import lombok.Getter;
5+
6+
/**
7+
* 管理员群签名打开私钥
8+
*
9+
* @author float311
10+
* @since 2021/04/13
11+
*/
12+
public class AdminGroupOpenKey {
13+
/**
14+
* u
15+
*/
16+
@Getter
17+
private final Element u;
18+
19+
public AdminGroupOpenKey(Element u) {
20+
this.u = u;
21+
}
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.latte.blockchain.entity;
2+
3+
import it.unisa.dia.gas.jpbc.Element;
4+
import lombok.Getter;
5+
6+
/**
7+
* 管理员群私钥
8+
*
9+
* @author float311
10+
* @since 2021/04/13
11+
*/
12+
public class AdminGroupSecretKey {
13+
/**
14+
* d
15+
*/
16+
@Getter
17+
private Element d;
18+
19+
/**
20+
* s
21+
*/
22+
@Getter
23+
private Element s;
24+
25+
public AdminGroupSecretKey(Element d, Element s) {
26+
this.d = d;
27+
this.s = s;
28+
}
29+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.latte.blockchain.entity;
2+
3+
import com.latte.blockchain.enums.LatteChainConfEnum;
4+
import lombok.Data;
5+
6+
import javax.persistence.*;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
/**
11+
* @author float
12+
* @since 2021/1/27
13+
*/
14+
@Data
15+
@Entity
16+
@Table(name = "blocks", schema = "lattechain")
17+
public class Block {
18+
19+
/**
20+
* 区块id
21+
*/
22+
@Id
23+
private long id;
24+
25+
/**
26+
* 区块信息
27+
*/
28+
@Column(name = "message", nullable = false)
29+
private String msg;
30+
31+
/**
32+
* 当前区块哈希值
33+
*/
34+
private String hash;
35+
36+
/**
37+
* 前一区块哈希值
38+
*/
39+
private String previousHash;
40+
41+
/**
42+
* merkle根哈希值
43+
*/
44+
private String merkleRoot;
45+
46+
/**
47+
* 交易信息 {@link Transaction},最多包含MAX_TRANSACTION_AMOUNT个交易信息
48+
*/
49+
@Transient
50+
private List<Transaction> transactions;
51+
52+
/**
53+
* 时间戳
54+
*/
55+
private long timeStamp;
56+
57+
/**
58+
* Nonce值
59+
*/
60+
private int nonce;
61+
62+
protected Block() {
63+
}
64+
65+
public Block(String previousHash, String msg) {
66+
this.previousHash = previousHash;
67+
this.msg = msg;
68+
transactions = new ArrayList<>(LatteChainConfEnum.MAX_TRANSACTION_AMOUNT);
69+
this.timeStamp = System.currentTimeMillis();
70+
this.nonce = 0;
71+
}
72+
}

0 commit comments

Comments
 (0)