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