添加日志
This commit is contained in:
1 parent
28d0517294
commit
1e79e836e8
1 file changed
+54
-46
@@ -1,24 +1,25 @@
|
||||
package com.ruoyi.system.rental;
|
||||
|
||||
import static com.ruoyi.system.rental.RentalValues.*;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.tron.trident.core.ApiWrapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.ruoyi.system.rental.RentalValues.*;
|
||||
|
||||
/**
|
||||
* 云端只读链上适配器,不持有私钥且不调用广播接口。 普通TRON RPC不提供任意历史资源状态;确认区块资源证明必须来自配置的受信历史节点。
|
||||
* 缺少历史证据时保留真实交易与资金占位,禁止用当前参数冒充历史交付成功。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RentalChain {
|
||||
@Value("${rental.rpc.nile:https://nile.trongrid.io}")
|
||||
@@ -84,7 +85,8 @@ public class RentalChain {
|
||||
(fullBlock ? 16 : 1) * 1024 * 1024));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException("链上查询失败,保留原业务状态");
|
||||
log.error(ex.getMessage(), ex);
|
||||
throw new IllegalStateException("链上查询失败,保留原业务状态 " + base + path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,16 +103,16 @@ public class RentalChain {
|
||||
map("address", address, "visible", true));
|
||||
long energy =
|
||||
call(
|
||||
network,
|
||||
"/wallet/getcandelegatedmaxsize",
|
||||
map("owner_address", address, "type", 1, "visible", true))
|
||||
network,
|
||||
"/wallet/getcandelegatedmaxsize",
|
||||
map("owner_address", address, "type", 1, "visible", true))
|
||||
.path("max_size")
|
||||
.asLong(-1);
|
||||
long bandwidth =
|
||||
call(
|
||||
network,
|
||||
"/wallet/getcandelegatedmaxsize",
|
||||
map("owner_address", address, "type", 0, "visible", true))
|
||||
network,
|
||||
"/wallet/getcandelegatedmaxsize",
|
||||
map("owner_address", address, "type", 0, "visible", true))
|
||||
.path("max_size")
|
||||
.asLong(-1);
|
||||
long after = block(call(network, "/wallet/getnowblock", map()));
|
||||
@@ -159,9 +161,9 @@ public class RentalChain {
|
||||
public long relation(String network, String owner, String receiver, String resource) {
|
||||
JsonNode rows =
|
||||
call(
|
||||
network,
|
||||
"/wallet/getdelegatedresourcev2",
|
||||
map("fromAddress", owner, "toAddress", receiver, "visible", true))
|
||||
network,
|
||||
"/wallet/getdelegatedresourcev2",
|
||||
map("fromAddress", owner, "toAddress", receiver, "visible", true))
|
||||
.path("delegatedResource");
|
||||
long total = 0;
|
||||
for (JsonNode row : rows) {
|
||||
@@ -177,14 +179,18 @@ public class RentalChain {
|
||||
return total;
|
||||
}
|
||||
|
||||
/** 内置历史模式在派单前建立确认关系基线,RPC失败时继续等待派单,不先广播再补基线。 */
|
||||
/**
|
||||
* 内置历史模式在派单前建立确认关系基线,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。 */
|
||||
/**
|
||||
* 返回CONFIRMED仅代表交易真实成功;历史资源证据不足时delivery_proven=false。
|
||||
*/
|
||||
public Map<String, Object> verify(
|
||||
Map<String, Object> task, String txId, String owner, String receiver) {
|
||||
require(txId.matches("[0-9a-fA-F]{64}"), "交易哈希无效");
|
||||
@@ -212,10 +218,10 @@ public class RentalChain {
|
||||
&& contract.path("Permission_id").asInt(0) == 0
|
||||
&& hexAddress(owner).equalsIgnoreCase(value.path("owner_address").asText())
|
||||
&& hexAddress(receiver)
|
||||
.equalsIgnoreCase(value.path("receiver_address").asText())
|
||||
.equalsIgnoreCase(value.path("receiver_address").asText())
|
||||
&& number(task, "delegate_sun") == value.path("balance").asLong()
|
||||
&& text(task, "resource_type")
|
||||
.equals(value.path("resource").asText("BANDWIDTH")),
|
||||
.equals(value.path("resource").asText("BANDWIDTH")),
|
||||
"链上交易参数与任务意图不符");
|
||||
require(tx.path("ret").size() == 1, "缺少执行回执");
|
||||
if (!"SUCCESS".equals(tx.path("ret").get(0).path("contractRet").asText())) {
|
||||
@@ -252,21 +258,21 @@ public class RentalChain {
|
||||
proof = json.valueToTree(archived);
|
||||
} else {
|
||||
proof = request(
|
||||
history,
|
||||
"/rental/resource-proof",
|
||||
map(
|
||||
"network",
|
||||
network,
|
||||
"tx_id",
|
||||
txId,
|
||||
"block_height",
|
||||
height,
|
||||
"owner",
|
||||
owner,
|
||||
"receiver",
|
||||
receiver,
|
||||
"resource_type",
|
||||
text(task, "resource_type")));
|
||||
history,
|
||||
"/rental/resource-proof",
|
||||
map(
|
||||
"network",
|
||||
network,
|
||||
"tx_id",
|
||||
txId,
|
||||
"block_height",
|
||||
height,
|
||||
"owner",
|
||||
owner,
|
||||
"receiver",
|
||||
receiver,
|
||||
"resource_type",
|
||||
text(task, "resource_type")));
|
||||
}
|
||||
require(
|
||||
height == proof.path("block_height").asLong(-1)
|
||||
@@ -292,7 +298,9 @@ public class RentalChain {
|
||||
return ApiWrapper.toHex(ApiWrapper.parseAddress(address));
|
||||
}
|
||||
|
||||
/** 人工充值/付款依据必须由配置网络的USDT Transfer日志独立核对。 */
|
||||
/**
|
||||
* 人工充值/付款依据必须由配置网络的USDT Transfer日志独立核对。
|
||||
*/
|
||||
public Map<String, Object> transfer(
|
||||
String network, String txId, int index, String to, BigDecimal expected) {
|
||||
network(network);
|
||||
@@ -303,9 +311,9 @@ public class RentalChain {
|
||||
require(
|
||||
receipt.has("blockNumber")
|
||||
&& block(call(network, "/walletsolidity/getnowblock", map()))
|
||||
- receipt.path("blockNumber").asLong()
|
||||
+ 1
|
||||
>= confirmations
|
||||
- receipt.path("blockNumber").asLong()
|
||||
+ 1
|
||||
>= confirmations
|
||||
&& receipt.path("log").size() > index,
|
||||
"付款未确认或日志不存在");
|
||||
JsonNode log = receipt.path("log").get(index);
|
||||
@@ -314,18 +322,18 @@ public class RentalChain {
|
||||
hexAddress(contract).substring(2).equalsIgnoreCase(log.path("address").asText())
|
||||
&& log.path("topics").size() == 3
|
||||
&& "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
|
||||
.equalsIgnoreCase(log.path("topics").get(0).asText())
|
||||
.equalsIgnoreCase(log.path("topics").get(0).asText())
|
||||
&& log.path("topics")
|
||||
.get(2)
|
||||
.asText()
|
||||
.endsWith(hexAddress(to).substring(2).toLowerCase(Locale.ROOT))
|
||||
.get(2)
|
||||
.asText()
|
||||
.endsWith(hexAddress(to).substring(2).toLowerCase(Locale.ROOT))
|
||||
&& new BigDecimal(new java.math.BigInteger(log.path("data").asText(), 16))
|
||||
.movePointLeft(6)
|
||||
.compareTo(expected)
|
||||
== 0
|
||||
.movePointLeft(6)
|
||||
.compareTo(expected)
|
||||
== 0
|
||||
&& !"FAILED".equals(receipt.path("result").asText())
|
||||
&& "SUCCESS"
|
||||
.equals(receipt.path("receipt").path("result").asText("SUCCESS")),
|
||||
.equals(receipt.path("receipt").path("result").asText("SUCCESS")),
|
||||
"USDT付款日志不匹配");
|
||||
return map(
|
||||
"reference",
|
||||
|
||||
Reference in new issue
Block a user