自行建设,补充这部分功能,给出具体的表设计和代码实现,同云端服务端一起部署
This commit is contained in:
1 parent
cab8056412
commit
b3419aa389
15 files changed
+1369
-14
No files matched your search
@@ -33,6 +33,13 @@ public class RentalChain {
|
||||
@Value("${rental.history.mainnet:}")
|
||||
private String mainHistory;
|
||||
|
||||
@Value("${rental.history.embedded-enabled:false}")
|
||||
private boolean embeddedHistory;
|
||||
|
||||
// 延迟获取内置历史服务,避免历史采集复用本只读RPC适配器时发生构造循环依赖。
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
private org.springframework.beans.factory.ObjectProvider<RentalHistoryService> historyService;
|
||||
|
||||
@Value("${rental.rpc.api-key:}")
|
||||
private String apiKey;
|
||||
|
||||
@@ -72,7 +79,9 @@ public class RentalChain {
|
||||
json.writeValueAsString(body)))
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
return json.readTree(RentalHttp.body(response));
|
||||
boolean fullBlock = path.endsWith("/getnowblock") || path.endsWith("/getblockbynum");
|
||||
return json.readTree(RentalHttp.body(response,
|
||||
(fullBlock ? 16 : 1) * 1024 * 1024));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException("链上查询失败,保留原业务状态");
|
||||
@@ -168,6 +177,13 @@ public class RentalChain {
|
||||
return total;
|
||||
}
|
||||
|
||||
/** 内置历史模式在派单前建立确认关系基线,RPC失败时继续等待派单,不先广播再补基线。 */
|
||||
public void prepareHistory(String network, String owner, String receiver, String resource) {
|
||||
if (embeddedHistory) {
|
||||
historyService.getObject().anchor(network, owner, receiver, resource);
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回CONFIRMED仅代表交易真实成功;历史资源证据不足时delivery_proven=false。 */
|
||||
public Map<String, Object> verify(
|
||||
Map<String, Object> task, String txId, String owner, String receiver) {
|
||||
@@ -224,9 +240,18 @@ public class RentalChain {
|
||||
"delivery_proven",
|
||||
!delegate);
|
||||
String history = "NILE".equals(network) ? nileHistory : mainHistory;
|
||||
if (delegate && !history.isEmpty()) {
|
||||
JsonNode proof =
|
||||
request(
|
||||
if (delegate && (embeddedHistory || !history.isEmpty())) {
|
||||
JsonNode proof;
|
||||
if (embeddedHistory) {
|
||||
Map<String, Object> archived = historyService.getObject().proof(
|
||||
network, txId, height, owner, receiver, text(task, "resource_type"));
|
||||
if (archived == null) {
|
||||
// 参数漏采或缺少派单前基线:保留原有MANUAL_REVIEW路径,绝不降级为当前快照。
|
||||
return result;
|
||||
}
|
||||
proof = json.valueToTree(archived);
|
||||
} else {
|
||||
proof = request(
|
||||
history,
|
||||
"/rental/resource-proof",
|
||||
map(
|
||||
@@ -242,6 +267,7 @@ public class RentalChain {
|
||||
receiver,
|
||||
"resource_type",
|
||||
text(task, "resource_type")));
|
||||
}
|
||||
require(
|
||||
height == proof.path("block_height").asLong(-1)
|
||||
&& txId.equalsIgnoreCase(proof.path("tx_id").asText())
|
||||
@@ -252,6 +278,8 @@ public class RentalChain {
|
||||
weight = proof.path("total_weight").asLong();
|
||||
result.put("verified_total_limit", limit);
|
||||
result.put("verified_total_weight", weight);
|
||||
// 完整历史证明写入交易evidence JSON,保留区块哈希、基线高度和数据来源供审计。
|
||||
result.put("history_proof", json.convertValue(proof, Map.class));
|
||||
result.put(
|
||||
"verified_resource_quantity",
|
||||
quantity(number(task, "delegate_sun"), limit, weight));
|
||||
|
||||
Reference in new issue
Block a user