去掉依赖

This commit is contained in:
lu7213 committed 2026-11-15 09:45:14 -05:00
1 parent 79183ee0d9
commit 7cb16bc84d
12 files changed
+183 -75

No files matched your search

+2
View File
@@ -1,5 +1,7 @@
## 平台简介 ## 平台简介
TRON 密钥生成、地址校验和离线签名恢复通过现有 Trident 与 `TronKey` 适配实现,不再依赖 `tron-wallet-cli`;钱包派生路径、地址编码和投票交易行为保持兼容。后端请使用 JDK 8 编译。
归集、代付支持可选的[双平台资源租赁](docs/resource-rental.md):人工确认租赁后等待链上资源到账,再输入密码广播;独立执行器自动异步准备资源。默认关闭,启用前执行增量SQL并配置加密的平台凭据。 归集、代付支持可选的[双平台资源租赁](docs/resource-rental.md):人工确认租赁后等待链上资源到账,再输入密码广播;独立执行器自动异步准备资源。默认关闭,启用前执行增量SQL并配置加密的平台凭据。
新增可选的独立[内网链上执行服务](docs/chain-executor.md):默认关闭,保留原配置密码方式;启用前执行 `sql/chain_executor.sql`,并按文档配置仅内网监听、来源白名单、TLS、服务凭据及执行器环境密码。 新增可选的独立[内网链上执行服务](docs/chain-executor.md):默认关闭,保留原配置密码方式;启用前执行 `sql/chain_executor.sql`,并按文档配置仅内网监听、来源白名单、TLS、服务凭据及执行器环境密码。
+2 -2
View File
@@ -35,11 +35,11 @@
<distributionManagement> <distributionManagement>
<repository> <repository>
<id>maven-releases</id> <id>maven-releases</id>
<url>http://gitlab.chatshop.com.cn:8081/repository/maven-releases/</url> <url>http://192.168.3.243:8081/repository/maven-releases/</url>
</repository> </repository>
<snapshotRepository> <snapshotRepository>
<id>snapshots</id> <id>snapshots</id>
<url>http://gitlab.chatshop.com.cn:8081/repository/maven-snapshots/</url> <url>http://192.168.3.243:8081/repository/maven-snapshots/</url>
</snapshotRepository> </snapshotRepository>
</distributionManagement> </distributionManagement>
<!-- 依赖声明 --> <!-- 依赖声明 -->
-5
View File
@@ -47,11 +47,6 @@
<version>4.13.2</version> <version>4.13.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.tronprotocol</groupId>
<artifactId>tron-wallet-cli</artifactId>
<version>1.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.grpc/grpc-stub --> <!-- https://mvnrepository.com/artifact/io.grpc/grpc-stub -->
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
@@ -0,0 +1,75 @@
package com.ruoyi.system.chain;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Base64;
import org.bouncycastle.util.encoders.Hex;
import org.tron.trident.core.key.KeyPair;
import org.tron.trident.crypto.SECP256K1;
import org.tron.trident.crypto.tuwenitypes.Bytes32;
/**
* 基于现有 Trident 的 TRON 密钥适配,避免依赖钱包 CLI。
* 保持 32 字节私钥、0x41 地址前缀和旧版 compact 签名恢复格式。
* 本类不记录或在异常中拼接私钥、签名和消息内容。
*/
public final class TronKey {
private final KeyPair keyPair;
/** 使用调用方的安全随机源生成合法的 secp256k1 私钥。 */
public TronKey(SecureRandom random) {
BigInteger value;
do {
value = new BigInteger(256, random);
} while (value.signum() == 0 || value.compareTo(SECP256K1.CURVE.getN()) >= 0);
keyPair = pair(value);
}
private TronKey(BigInteger privateKey) {
keyPair = pair(privateKey);
}
private static KeyPair pair(BigInteger value) {
if (value == null || value.signum() <= 0 || value.compareTo(SECP256K1.CURVE.getN()) >= 0) {
throw new IllegalArgumentException("无效的 TRON 私钥");
}
return new KeyPair(String.format("%064x", value));
}
public static TronKey fromPrivate(BigInteger value) {
return new TronKey(value);
}
public byte[] getPrivKeyBytes() {
return Hex.decode(keyPair.toPrivateKey());
}
public byte[] getAddress() {
return KeyPair.publicKeyToAddress(keyPair.getRawPair().getPublicKey());
}
/**
* 恢复旧接口的 Base64(header || r || s) 签名。
* header 为 27..34,其中 31..34 表示压缩公钥;地址始终由完整公钥计算。
* 传入值已经是消息摘要,此处不得再次哈希。
*/
public static byte[] signatureToAddress(byte[] hash, String signature) {
byte[] compact = Base64.getDecoder().decode(signature);
if (compact.length != 65) {
throw new IllegalArgumentException("无效的 TRON 签名长度");
}
int header = compact[0] & 255;
if (header < 27 || header > 34) {
throw new IllegalArgumentException("无效的 TRON 签名恢复标记");
}
byte recoveryId = (byte) ((header - 27) & 3);
SECP256K1.Signature decoded = SECP256K1.Signature.create(
new BigInteger(1, Arrays.copyOfRange(compact, 1, 33)),
new BigInteger(1, Arrays.copyOfRange(compact, 33, 65)), recoveryId);
SECP256K1.PublicKey publicKey = SECP256K1.PublicKey.recoverFromSignature(
Bytes32.wrap(hash), decoded).orElseThrow(
() -> new IllegalArgumentException("无法恢复 TRON 签名地址"));
return KeyPair.publicKeyToAddress(publicKey);
}
}
@@ -6,7 +6,7 @@ import org.bitcoinj.crypto.HDPath;
import org.bitcoinj.crypto.MnemonicCode; import org.bitcoinj.crypto.MnemonicCode;
import org.bitcoinj.wallet.DeterministicKeyChain; import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed; import org.bitcoinj.wallet.DeterministicSeed;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.trident.core.ApiWrapper; import org.tron.trident.core.ApiWrapper;
import org.tron.trident.proto.Chain; import org.tron.trident.proto.Chain;
import org.tron.trident.proto.Response; import org.tron.trident.proto.Response;
@@ -77,7 +77,7 @@ public final class WalletEnvelopeTronTransferDemo {
new ChildNumber(0, true), ChildNumber.ZERO); new ChildNumber(0, true), ChildNumber.ZERO);
DeterministicKey key = chain.getKeyByPath(base.extend(new ChildNumber(index, false)), true); DeterministicKey key = chain.getKeyByPath(base.extend(new ChildNumber(index, false)), true);
byte[] privateKey = key.getPrivKeyBytes(); byte[] privateKey = key.getPrivKeyBytes();
String address = Base58Check.bytesToBase58(ECKey.fromPrivate(new BigInteger(1, privateKey)).getAddress()); String address = Base58Check.bytesToBase58(TronKey.fromPrivate(new BigInteger(1, privateKey)).getAddress());
return new DerivedPrivateKey(privateKey, address); return new DerivedPrivateKey(privateKey, address);
} }
@@ -5,7 +5,7 @@ import static com.ruoyi.system.rental.RentalValues.*;
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.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.trident.crypto.Hash; import org.tron.trident.crypto.Hash;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -295,7 +295,7 @@ public class RentalProvisioning {
compact[0] = (byte) v; compact[0] = (byte) v;
System.arraycopy(sig, 0, compact, 1, 64); System.arraycopy(sig, 0, compact, 1, 64);
byte[] address = byte[] address =
ECKey.signatureToAddress( TronKey.signatureToAddress(
Hash.sha3(plain), Hash.sha3(plain),
java.util.Base64.getEncoder().encodeToString(compact)); java.util.Base64.getEncoder().encodeToString(compact));
String recovered = org.tron.trident.utils.Base58Check.bytesToBase58(address); String recovered = org.tron.trident.utils.Base58Check.bytesToBase58(address);
@@ -15,7 +15,7 @@ import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed; import org.bitcoinj.wallet.DeterministicSeed;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.trident.core.ApiWrapper; import org.tron.trident.core.ApiWrapper;
import org.tron.trident.utils.Base58Check; import org.tron.trident.utils.Base58Check;
@@ -153,7 +153,7 @@ public class WalletSigningService {
new ChildNumber(0, true), ChildNumber.ZERO); new ChildNumber(0, true), ChildNumber.ZERO);
DeterministicKey key = chain.getKeyByPath(base.extend(new ChildNumber(index, false)), true); DeterministicKey key = chain.getKeyByPath(base.extend(new ChildNumber(index, false)), true);
byte[] bytes = key.getPrivKeyBytes(); byte[] bytes = key.getPrivKeyBytes();
String address = Base58Check.bytesToBase58(ECKey.fromPrivate(new BigInteger(1, bytes)).getAddress()); String address = Base58Check.bytesToBase58(TronKey.fromPrivate(new BigInteger(1, bytes)).getAddress());
return new DerivedKey(bytes, address); return new DerivedKey(bytes, address);
} }
@@ -24,9 +24,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI;
import org.tron.api.WalletGrpc; import org.tron.api.WalletGrpc;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.common.utils.Base58;
import org.tron.common.utils.ByteArray;
import org.tron.protos.Protocol; import org.tron.protos.Protocol;
import org.tron.trident.abi.FunctionEncoder; import org.tron.trident.abi.FunctionEncoder;
import org.tron.trident.abi.datatypes.Address; import org.tron.trident.abi.datatypes.Address;
@@ -288,7 +286,7 @@ public class TronNileServiceImpl implements ITronService {
BigDecimal result = new BigDecimal(0); BigDecimal result = new BigDecimal(0);
for (ByteString byteString : list) { for (ByteString byteString : list) {
String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray()); String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray());
String address = encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); String address = encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(address, ownerAddr); Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(address, ownerAddr);
int count = delegatedResourceList.getDelegatedResourceCount(); int count = delegatedResourceList.getDelegatedResourceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@@ -318,15 +316,15 @@ public class TronNileServiceImpl implements ITronService {
BigDecimal result = new BigDecimal(0); BigDecimal result = new BigDecimal(0);
for (ByteString byteString : list) { for (ByteString byteString : list) {
String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray()); String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray());
String address = encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); String address = encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(ownerAddr,address); Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(ownerAddr,address);
int count = delegatedResourceList.getDelegatedResourceCount(); int count = delegatedResourceList.getDelegatedResourceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i); Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i);
String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray()); String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray());
String fromAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(fromHexAddress)); String fromAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(fromHexAddress));
String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray()); String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray());
String toAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(toHexAddress)); String toAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(toHexAddress));
if (resourceCode == 0) { if (resourceCode == 0) {
BigDecimal divisor = new BigDecimal("1000000"); BigDecimal divisor = new BigDecimal("1000000");
BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP); BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP);
@@ -411,19 +409,19 @@ public class TronNileServiceImpl implements ITronService {
boolean needRevote = currentVotes.keySet().stream() boolean needRevote = currentVotes.keySet().stream()
.anyMatch(sr -> !top27.contains(sr)); .anyMatch(sr -> !top27.contains(sr));
Iterator<String> iterator = currentVotes.keySet().iterator(); Iterator<String> iterator = currentVotes.keySet().iterator();
org.tron.protos.Contract.VoteWitnessContract.Builder builder = org.tron.protos.Contract.VoteWitnessContract.newBuilder() org.tron.trident.proto.Contract.VoteWitnessContract.Builder builder = org.tron.trident.proto.Contract.VoteWitnessContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(ownerAddress)); .setOwnerAddress(ApiWrapper.parseAddress(ownerAddress));
boolean cancle = false; boolean cancle = false;
while (iterator.hasNext()) { while (iterator.hasNext()) {
String address = iterator.next(); String address = iterator.next();
if (!top27.contains(address)) { if (!top27.contains(address)) {
builder.addVotes(org.tron.protos.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(address)) builder.addVotes(org.tron.trident.proto.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(address))
.setVoteCount(1)); .setVoteCount(1));
cancle = true; cancle = true;
} }
} }
if (cancle) { if (cancle) {
org.tron.protos.Contract.VoteWitnessContract voteWitnessContract = builder.build(); org.tron.trident.proto.Contract.VoteWitnessContract voteWitnessContract = builder.build();
Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract, Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract,
Chain.Transaction.Contract.ContractType.VoteWitnessContract); Chain.Transaction.Contract.ContractType.VoteWitnessContract);
Chain.Transaction signedTx = api.signTransaction(tx); Chain.Transaction signedTx = api.signTransaction(tx);
@@ -438,12 +436,12 @@ public class TronNileServiceImpl implements ITronService {
// 5. 构建新投票(平均投到备用 SR) // 5. 构建新投票(平均投到备用 SR)
backupSRs.addAll(top27.stream().sorted().collect(Collectors.toList()).subList(0, size)); backupSRs.addAll(top27.stream().sorted().collect(Collectors.toList()).subList(0, size));
long perSRVotes = totalVotes / backupSRs.size(); long perSRVotes = totalVotes / backupSRs.size();
builder = org.tron.protos.Contract.VoteWitnessContract.newBuilder() builder = org.tron.trident.proto.Contract.VoteWitnessContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(ownerAddress)); .setOwnerAddress(ApiWrapper.parseAddress(ownerAddress));
for (String sr : backupSRs) { for (String sr : backupSRs) {
builder.addVotes(org.tron.protos.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(sr)).setVoteCount(perSRVotes)); builder.addVotes(org.tron.trident.proto.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(sr)).setVoteCount(perSRVotes));
} }
org.tron.protos.Contract.VoteWitnessContract voteWitnessContract = builder.build(); org.tron.trident.proto.Contract.VoteWitnessContract voteWitnessContract = builder.build();
Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract, Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract,
Chain.Transaction.Contract.ContractType.VoteWitnessContract); Chain.Transaction.Contract.ContractType.VoteWitnessContract);
Chain.Transaction signedTx = api.signTransaction(tx); Chain.Transaction signedTx = api.signTransaction(tx);
@@ -543,10 +541,10 @@ public class TronNileServiceImpl implements ITronService {
@Override @Override
public TronAccountItem createTronAddress() { public TronAccountItem createTronAddress() {
ECKey eCkey = new ECKey(random); TronKey eCkey = new TronKey(random);
String privateKey = ByteArray.toHexString(eCkey.getPrivKeyBytes()); String privateKey = org.bouncycastle.util.encoders.Hex.toHexString(eCkey.getPrivKeyBytes());
byte[] addressBytes = eCkey.getAddress(); byte[] addressBytes = eCkey.getAddress();
String hexAddress = ByteArray.toHexString(addressBytes); String hexAddress = org.bouncycastle.util.encoders.Hex.toHexString(addressBytes);
TronAccountItem tronAccount = new TronAccountItem(); TronAccountItem tronAccount = new TronAccountItem();
tronAccount.setAddress(toViewAddress(hexAddress)); tronAccount.setAddress(toViewAddress(hexAddress));
tronAccount.setHexAddress(hexAddress); tronAccount.setHexAddress(hexAddress);
@@ -656,7 +654,7 @@ public class TronNileServiceImpl implements ITronService {
item.setPubKeyCompressed(Hex.toHexString(pubKeyCompressed)); item.setPubKeyCompressed(Hex.toHexString(pubKeyCompressed));
item.setPubKeyUnCompressed(Hex.toHexString(pubKeyUnCompressed)); item.setPubKeyUnCompressed(Hex.toHexString(pubKeyUnCompressed));
item.setPath(pathStr); item.setPath(pathStr);
String hexAddress = ByteArray.toHexString(addressBytes); String hexAddress = org.bouncycastle.util.encoders.Hex.toHexString(addressBytes);
item.setHexAddress(hexAddress); item.setHexAddress(hexAddress);
String privateKeyBase58 = encode58Check(privateKey); String privateKeyBase58 = encode58Check(privateKey);
item.setPrivateKeyBase58(privateKeyBase58); item.setPrivateKeyBase58(privateKeyBase58);
@@ -756,7 +754,7 @@ public class TronNileServiceImpl implements ITronService {
* @return * @return
*/ */
private String toViewAddress(String hexAddress) { private String toViewAddress(String hexAddress) {
return encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); return encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
} }
/** /**
@@ -798,7 +796,7 @@ public class TronNileServiceImpl implements ITronService {
byte[] inputCheck = new byte[input.length + 4]; byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length); System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4); System.arraycopy(hash1, 0, inputCheck, input.length, 4);
return Base58.encode(inputCheck); return encode(inputCheck);
} catch (Throwable t) { } catch (Throwable t) {
log.error(String.format("data error:%s", Hex.toHexString(input)), t); log.error(String.format("data error:%s", Hex.toHexString(input)), t);
} }
@@ -22,9 +22,7 @@ import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.util.encoders.Hex; import org.bouncycastle.util.encoders.Hex;
import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI;
import org.tron.api.WalletGrpc; import org.tron.api.WalletGrpc;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.common.utils.Base58;
import org.tron.common.utils.ByteArray;
import org.tron.protos.Protocol; import org.tron.protos.Protocol;
import org.tron.trident.abi.FunctionEncoder; import org.tron.trident.abi.FunctionEncoder;
import org.tron.trident.abi.datatypes.Address; import org.tron.trident.abi.datatypes.Address;
@@ -333,15 +331,15 @@ public class TronProServiceImpl implements ITronService {
BigDecimal result = new BigDecimal(0); BigDecimal result = new BigDecimal(0);
for (ByteString byteString : list) { for (ByteString byteString : list) {
String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray()); String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray());
String address = encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); String address = encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(ownerAddr, address); Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(ownerAddr, address);
int count = delegatedResourceList.getDelegatedResourceCount(); int count = delegatedResourceList.getDelegatedResourceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i); Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i);
String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray()); String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray());
String fromAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(fromHexAddress)); String fromAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(fromHexAddress));
String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray()); String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray());
String toAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(toHexAddress)); String toAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(toHexAddress));
if (resourceCode == 0) { if (resourceCode == 0) {
BigDecimal divisor = new BigDecimal("1000000"); BigDecimal divisor = new BigDecimal("1000000");
BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP); BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP);
@@ -368,15 +366,15 @@ public class TronProServiceImpl implements ITronService {
BigDecimal result = new BigDecimal(0); BigDecimal result = new BigDecimal(0);
for (ByteString byteString : list) { for (ByteString byteString : list) {
String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray()); String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray());
String address = encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); String address = encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(address, ownerAddr); Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(address, ownerAddr);
int count = delegatedResourceList.getDelegatedResourceCount(); int count = delegatedResourceList.getDelegatedResourceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i); Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i);
String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray()); String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray());
String fromAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(fromHexAddress)); String fromAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(fromHexAddress));
String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray()); String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray());
String toAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(toHexAddress)); String toAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(toHexAddress));
if (resourceCode == 0) { if (resourceCode == 0) {
BigDecimal divisor = new BigDecimal("1000000"); BigDecimal divisor = new BigDecimal("1000000");
BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP); BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP);
@@ -495,19 +493,19 @@ public class TronProServiceImpl implements ITronService {
boolean needRevote = currentVotes.keySet().stream() boolean needRevote = currentVotes.keySet().stream()
.anyMatch(sr -> !top27.contains(sr)); .anyMatch(sr -> !top27.contains(sr));
Iterator<String> iterator = currentVotes.keySet().iterator(); Iterator<String> iterator = currentVotes.keySet().iterator();
org.tron.protos.Contract.VoteWitnessContract.Builder builder = org.tron.protos.Contract.VoteWitnessContract.newBuilder() org.tron.trident.proto.Contract.VoteWitnessContract.Builder builder = org.tron.trident.proto.Contract.VoteWitnessContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(ownerAddress)); .setOwnerAddress(ApiWrapper.parseAddress(ownerAddress));
boolean cancle = false; boolean cancle = false;
while (iterator.hasNext()) { while (iterator.hasNext()) {
String address = iterator.next(); String address = iterator.next();
if (!top27.contains(address)) { if (!top27.contains(address)) {
builder.addVotes(org.tron.protos.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(address)) builder.addVotes(org.tron.trident.proto.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(address))
.setVoteCount(1)); .setVoteCount(1));
cancle = true; cancle = true;
} }
} }
if (cancle) { if (cancle) {
org.tron.protos.Contract.VoteWitnessContract voteWitnessContract = builder.build(); org.tron.trident.proto.Contract.VoteWitnessContract voteWitnessContract = builder.build();
Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract, Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract,
Chain.Transaction.Contract.ContractType.VoteWitnessContract); Chain.Transaction.Contract.ContractType.VoteWitnessContract);
Chain.Transaction signedTx = api.signTransaction(tx); Chain.Transaction signedTx = api.signTransaction(tx);
@@ -522,12 +520,12 @@ public class TronProServiceImpl implements ITronService {
// 5. 构建新投票(平均投到备用 SR) // 5. 构建新投票(平均投到备用 SR)
backupSRs.addAll(top27.stream().sorted().collect(Collectors.toList()).subList(0, size)); backupSRs.addAll(top27.stream().sorted().collect(Collectors.toList()).subList(0, size));
long perSRVotes = totalVotes / backupSRs.size(); long perSRVotes = totalVotes / backupSRs.size();
builder = org.tron.protos.Contract.VoteWitnessContract.newBuilder() builder = org.tron.trident.proto.Contract.VoteWitnessContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(ownerAddress)); .setOwnerAddress(ApiWrapper.parseAddress(ownerAddress));
for (String sr : backupSRs) { for (String sr : backupSRs) {
builder.addVotes(org.tron.protos.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(sr)).setVoteCount(perSRVotes)); builder.addVotes(org.tron.trident.proto.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(sr)).setVoteCount(perSRVotes));
} }
org.tron.protos.Contract.VoteWitnessContract voteWitnessContract = builder.build(); org.tron.trident.proto.Contract.VoteWitnessContract voteWitnessContract = builder.build();
Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract, Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract,
Chain.Transaction.Contract.ContractType.VoteWitnessContract); Chain.Transaction.Contract.ContractType.VoteWitnessContract);
Chain.Transaction signedTx = api.signTransaction(tx); Chain.Transaction signedTx = api.signTransaction(tx);
@@ -627,10 +625,10 @@ public class TronProServiceImpl implements ITronService {
@Override @Override
public TronAccountItem createTronAddress() { public TronAccountItem createTronAddress() {
ECKey eCkey = new ECKey(random); TronKey eCkey = new TronKey(random);
String privateKey = ByteArray.toHexString(eCkey.getPrivKeyBytes()); String privateKey = org.bouncycastle.util.encoders.Hex.toHexString(eCkey.getPrivKeyBytes());
byte[] addressBytes = eCkey.getAddress(); byte[] addressBytes = eCkey.getAddress();
String hexAddress = ByteArray.toHexString(addressBytes); String hexAddress = org.bouncycastle.util.encoders.Hex.toHexString(addressBytes);
TronAccountItem tronAccount = new TronAccountItem(); TronAccountItem tronAccount = new TronAccountItem();
tronAccount.setAddress(toViewAddress(hexAddress)); tronAccount.setAddress(toViewAddress(hexAddress));
tronAccount.setHexAddress(hexAddress); tronAccount.setHexAddress(hexAddress);
@@ -759,7 +757,7 @@ public class TronProServiceImpl implements ITronService {
* @return * @return
*/ */
private String toViewAddress(String hexAddress) { private String toViewAddress(String hexAddress) {
return encode58Check(ByteArray.fromHexString(hexAddress)); return encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
} }
/** /**
@@ -801,7 +799,7 @@ public class TronProServiceImpl implements ITronService {
byte[] inputCheck = new byte[input.length + 4]; byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length); System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4); System.arraycopy(hash1, 0, inputCheck, input.length, 4);
return Base58.encode(inputCheck); return encode(inputCheck);
} catch (Throwable t) { } catch (Throwable t) {
log.error(String.format("data error:%s", Hex.toHexString(input)), t); log.error(String.format("data error:%s", Hex.toHexString(input)), t);
} }
@@ -25,9 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI;
import org.tron.api.WalletGrpc; import org.tron.api.WalletGrpc;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.common.utils.Base58;
import org.tron.common.utils.ByteArray;
import org.tron.protos.Protocol; import org.tron.protos.Protocol;
import org.tron.trident.abi.FunctionEncoder; import org.tron.trident.abi.FunctionEncoder;
import org.tron.trident.abi.datatypes.Address; import org.tron.trident.abi.datatypes.Address;
@@ -105,15 +103,15 @@ public class TronShastaServiceImpl implements ITronService {
BigDecimal result = new BigDecimal(0); BigDecimal result = new BigDecimal(0);
for (ByteString byteString : list) { for (ByteString byteString : list) {
String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray()); String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray());
String address = encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); String address = encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(ownerAddr,address); Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(ownerAddr,address);
int count = delegatedResourceList.getDelegatedResourceCount(); int count = delegatedResourceList.getDelegatedResourceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i); Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i);
String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray()); String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray());
String fromAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(fromHexAddress)); String fromAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(fromHexAddress));
String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray()); String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray());
String toAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(toHexAddress)); String toAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(toHexAddress));
if (resourceCode == 0) { if (resourceCode == 0) {
BigDecimal divisor = new BigDecimal("1000000"); BigDecimal divisor = new BigDecimal("1000000");
BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP); BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP);
@@ -139,15 +137,15 @@ public class TronShastaServiceImpl implements ITronService {
BigDecimal result = new BigDecimal(0); BigDecimal result = new BigDecimal(0);
for (ByteString byteString : list) { for (ByteString byteString : list) {
String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray()); String hexAddress = org.spongycastle.util.encoders.Hex.toHexString(byteString.toByteArray());
String address = encode58Check(org.tron.common.utils.ByteArray.fromHexString(hexAddress)); String address = encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(address, ownerAddr); Response.DelegatedResourceList delegatedResourceList = api.getDelegatedResourceV2(address, ownerAddr);
int count = delegatedResourceList.getDelegatedResourceCount(); int count = delegatedResourceList.getDelegatedResourceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i); Response.DelegatedResource delegatedResource = delegatedResourceList.getDelegatedResource(i);
String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray()); String fromHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getFrom().toByteArray());
String fromAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(fromHexAddress)); String fromAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(fromHexAddress));
String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray()); String toHexAddress = org.spongycastle.util.encoders.Hex.toHexString(delegatedResource.getTo().toByteArray());
String toAddress = encode58Check(org.tron.common.utils.ByteArray.fromHexString(toHexAddress)); String toAddress = encode58Check(org.bouncycastle.util.encoders.Hex.decode(toHexAddress));
if(resourceCode == 0){ if(resourceCode == 0){
BigDecimal divisor = new BigDecimal("1000000"); BigDecimal divisor = new BigDecimal("1000000");
BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP); BigDecimal divide = new BigDecimal(delegatedResource.getFrozenBalanceForBandwidth()).divide(divisor, 4, RoundingMode.HALF_UP);
@@ -437,19 +435,19 @@ public class TronShastaServiceImpl implements ITronService {
boolean needRevote = currentVotes.keySet().stream() boolean needRevote = currentVotes.keySet().stream()
.anyMatch(sr -> !top27.contains(sr)); .anyMatch(sr -> !top27.contains(sr));
Iterator<String> iterator = currentVotes.keySet().iterator(); Iterator<String> iterator = currentVotes.keySet().iterator();
org.tron.protos.Contract.VoteWitnessContract.Builder builder = org.tron.protos.Contract.VoteWitnessContract.newBuilder() org.tron.trident.proto.Contract.VoteWitnessContract.Builder builder = org.tron.trident.proto.Contract.VoteWitnessContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(ownerAddress)); .setOwnerAddress(ApiWrapper.parseAddress(ownerAddress));
boolean cancle = false; boolean cancle = false;
while (iterator.hasNext()) { while (iterator.hasNext()) {
String address = iterator.next(); String address = iterator.next();
if (!top27.contains(address)) { if (!top27.contains(address)) {
builder.addVotes(org.tron.protos.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(address)) builder.addVotes(org.tron.trident.proto.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(address))
.setVoteCount(1)); .setVoteCount(1));
cancle = true; cancle = true;
} }
} }
if (cancle) { if (cancle) {
org.tron.protos.Contract.VoteWitnessContract voteWitnessContract = builder.build(); org.tron.trident.proto.Contract.VoteWitnessContract voteWitnessContract = builder.build();
Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract, Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract,
Chain.Transaction.Contract.ContractType.VoteWitnessContract); Chain.Transaction.Contract.ContractType.VoteWitnessContract);
Chain.Transaction signedTx = api.signTransaction(tx); Chain.Transaction signedTx = api.signTransaction(tx);
@@ -464,12 +462,12 @@ public class TronShastaServiceImpl implements ITronService {
// 5. 构建新投票(平均投到备用 SR) // 5. 构建新投票(平均投到备用 SR)
backupSRs.addAll(top27.stream().sorted().collect(Collectors.toList()).subList(0, size)); backupSRs.addAll(top27.stream().sorted().collect(Collectors.toList()).subList(0, size));
long perSRVotes = totalVotes / backupSRs.size(); long perSRVotes = totalVotes / backupSRs.size();
builder = org.tron.protos.Contract.VoteWitnessContract.newBuilder() builder = org.tron.trident.proto.Contract.VoteWitnessContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(ownerAddress)); .setOwnerAddress(ApiWrapper.parseAddress(ownerAddress));
for (String sr : backupSRs) { for (String sr : backupSRs) {
builder.addVotes(org.tron.protos.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(sr)).setVoteCount(perSRVotes)); builder.addVotes(org.tron.trident.proto.Contract.VoteWitnessContract.Vote.newBuilder().setVoteAddress(ApiWrapper.parseAddress(sr)).setVoteCount(perSRVotes));
} }
org.tron.protos.Contract.VoteWitnessContract voteWitnessContract = builder.build(); org.tron.trident.proto.Contract.VoteWitnessContract voteWitnessContract = builder.build();
Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract, Response.TransactionExtention tx = api.createTransactionExtention(voteWitnessContract,
Chain.Transaction.Contract.ContractType.VoteWitnessContract); Chain.Transaction.Contract.ContractType.VoteWitnessContract);
Chain.Transaction signedTx = api.signTransaction(tx); Chain.Transaction signedTx = api.signTransaction(tx);
@@ -569,10 +567,10 @@ public class TronShastaServiceImpl implements ITronService {
@Override @Override
public TronAccountItem createTronAddress() { public TronAccountItem createTronAddress() {
ECKey eCkey = new ECKey(random); TronKey eCkey = new TronKey(random);
String privateKey = ByteArray.toHexString(eCkey.getPrivKeyBytes()); String privateKey = org.bouncycastle.util.encoders.Hex.toHexString(eCkey.getPrivKeyBytes());
byte[] addressBytes = eCkey.getAddress(); byte[] addressBytes = eCkey.getAddress();
String hexAddress = ByteArray.toHexString(addressBytes); String hexAddress = org.bouncycastle.util.encoders.Hex.toHexString(addressBytes);
TronAccountItem tronAccount = new TronAccountItem(); TronAccountItem tronAccount = new TronAccountItem();
tronAccount.setAddress(toViewAddress(hexAddress)); tronAccount.setAddress(toViewAddress(hexAddress));
tronAccount.setHexAddress(hexAddress); tronAccount.setHexAddress(hexAddress);
@@ -680,7 +678,7 @@ public class TronShastaServiceImpl implements ITronService {
item.setPubKeyCompressed(Hex.toHexString(pubKeyCompressed)); item.setPubKeyCompressed(Hex.toHexString(pubKeyCompressed));
item.setPubKeyUnCompressed(Hex.toHexString(pubKeyUnCompressed)); item.setPubKeyUnCompressed(Hex.toHexString(pubKeyUnCompressed));
item.setPath(pathStr); item.setPath(pathStr);
String hexAddress = ByteArray.toHexString(addressBytes); String hexAddress = org.bouncycastle.util.encoders.Hex.toHexString(addressBytes);
item.setHexAddress(hexAddress); item.setHexAddress(hexAddress);
String privateKeyBase58 = encode58Check(privateKey); String privateKeyBase58 = encode58Check(privateKey);
item.setPrivateKeyBase58(privateKeyBase58); item.setPrivateKeyBase58(privateKeyBase58);
@@ -749,7 +747,7 @@ public class TronShastaServiceImpl implements ITronService {
* @return * @return
*/ */
private String toViewAddress(String hexAddress) { private String toViewAddress(String hexAddress) {
return encode58Check(ByteArray.fromHexString(hexAddress)); return encode58Check(org.bouncycastle.util.encoders.Hex.decode(hexAddress));
} }
/** /**
@@ -791,7 +789,7 @@ public class TronShastaServiceImpl implements ITronService {
byte[] inputCheck = new byte[input.length + 4]; byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length); System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4); System.arraycopy(hash1, 0, inputCheck, input.length, 4);
return Base58.encode(inputCheck); return encode(inputCheck);
} catch (Throwable t) { } catch (Throwable t) {
log.error(String.format("data error:%s", Hex.toHexString(input)), t); log.error(String.format("data error:%s", Hex.toHexString(input)), t);
} }
@@ -0,0 +1,42 @@
package com.ruoyi.system.chain;
import java.math.BigInteger;
import java.security.SecureRandom;
import org.junit.Test;
import org.tron.trident.utils.Base58Check;
import static org.junit.Assert.*;
/** 固定公开测试密钥验证地址格式,所有测试均离线执行。 */
public class TronKeyTest {
@Test
public void privateKeyOneKeepsKnownAddressAndLeadingZeros() {
TronKey key = TronKey.fromPrivate(BigInteger.ONE);
byte[] bytes = key.getPrivKeyBytes();
assertEquals(32, bytes.length);
assertEquals(1, bytes[31]);
for (int i = 0; i < 31; i++) {
assertEquals(0, bytes[i]);
}
assertEquals("TMVQGm1qAQYVdetCeGRRkTWYYrLXuHK2HC",
Base58Check.bytesToBase58(key.getAddress()));
assertEquals(21, key.getAddress().length);
assertEquals(0x41, key.getAddress()[0]);
}
@Test
public void generatedKeyCanBeRestored() {
TronKey key = new TronKey(new SecureRandom());
assertArrayEquals(key.getAddress(),
TronKey.fromPrivate(new BigInteger(1, key.getPrivKeyBytes())).getAddress());
}
@Test(expected = IllegalArgumentException.class)
public void zeroPrivateKeyIsRejected() {
TronKey.fromPrivate(BigInteger.ZERO);
}
@Test(expected = IllegalArgumentException.class)
public void truncatedSignatureIsRejected() {
TronKey.signatureToAddress(new byte[32], "AA==");
}
}
@@ -5,7 +5,7 @@ import org.junit.Assume;
import org.junit.Test; import org.junit.Test;
import org.tron.trident.core.ApiWrapper; import org.tron.trident.core.ApiWrapper;
import org.tron.trident.utils.Base58Check; import org.tron.trident.utils.Base58Check;
import org.tron.common.crypto.ECKey; import com.ruoyi.system.chain.TronKey;
import org.tron.trident.proto.Chain; import org.tron.trident.proto.Chain;
import org.tron.trident.proto.Response; import org.tron.trident.proto.Response;
@@ -166,7 +166,7 @@ public class WalletEnvelopeEncryptionDemoTest {
Assume.assumeTrue("未配置 TRON_TEST_*,跳过链上转账测试", Assume.assumeTrue("未配置 TRON_TEST_*,跳过链上转账测试",
privateKey != null && targetAddress != null && amountText != null); privateKey != null && targetAddress != null && amountText != null);
ECKey key = ECKey.fromPrivate(new java.math.BigInteger(privateKey.trim(), 16)); TronKey key = TronKey.fromPrivate(new java.math.BigInteger(privateKey.trim(), 16));
String fromAddress = Base58Check.bytesToBase58(key.getAddress()); String fromAddress = Base58Check.bytesToBase58(key.getAddress());
long sunAmount = new BigDecimal(amountText).movePointRight(6).longValueExact(); long sunAmount = new BigDecimal(amountText).movePointRight(6).longValueExact();
ApiWrapper api = ApiWrapper.ofNile(privateKey.trim()); ApiWrapper api = ApiWrapper.ofNile(privateKey.trim());