Skip to content

Commit dfba842

Browse files
committed
更新
1 parent f984c4d commit dfba842

File tree

7 files changed

+150
-1
lines changed

7 files changed

+150
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ gradle方式
113113
# 以下介绍的项目不开源,并与本项目无关
114114
### 区块链java wallet介绍:
115115
- #### 业务后台是依据该数字货币的功能组件所构建出来的更强大的业务系统,可以随时获取不同公链区块链地址,并支持(BTC,OMNI,ETH,ERC20,TRX,TRC20,BCH,BSV,DOGE,DASH,LTC)的充归提功能
116+
注:程序员对接时主要对接api接口就行了
116117

117118
- ###### 后台管理演示
118119
![](https://i.ibb.co/zb8LtyH/test.gif)

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ buildscript {
2525
}
2626

2727
dependencies {
28+
compile fileTree(dir:'lib',includes:['*jar'])
2829
compile 'io.github.qyvlik:io.eblock.eos-eos4j:1.0.1'
2930
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
3031
compile 'org.bitcoinj:bitcoinj-core:0.14.7'
@@ -38,3 +39,9 @@ dependencies {
3839
implementation fileTree(dir: 'libs', include: ['*.jar'])
3940
testImplementation 'junit:junit:4.12'
4041
}
42+
43+
processResources {
44+
from('src/main/java/resources') {
45+
include '**'
46+
}
47+
}

lib/wallet-cli-4.1.0.1.jar

45.5 MB
Binary file not shown.

logs/tron.log

Whitespace-only changes.

src/main/java/org/consenlabs/tokencore/wallet/WalletManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public static void scanWallets() {
431431
keystoreMap.put(keystore.getId(), keystore);
432432
}
433433
} catch (Exception ex) {
434-
log.info(LOG_TAG, "Can't loaded " + file.getName() + " file", ex);
434+
// log.info(LOG_TAG, "Can't loaded " + file.getName() + " file", ex);
435435
}
436436
}
437437
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.consenlabs.tokencore.wallet.transaction;
2+
3+
import com.google.protobuf.Any;
4+
import com.google.protobuf.ByteString;
5+
import org.consenlabs.tokencore.wallet.Wallet;
6+
import org.tron.common.crypto.ECKey;
7+
import org.tron.common.crypto.Sha256Sm3Hash;
8+
import org.tron.common.utils.ByteArray;
9+
import org.tron.common.utils.TransactionUtils;
10+
import org.tron.protos.Protocol;
11+
import org.tron.protos.contract.BalanceContract;
12+
import org.tron.walletserver.WalletApi;
13+
14+
public class TronTransaction implements TransactionSigner {
15+
16+
private final String from;
17+
18+
private final String to;
19+
20+
private final Long amount;
21+
22+
23+
24+
public TronTransaction(String from, String to, Long amount) {
25+
this.from = from;
26+
this.to = to;
27+
this.amount = amount;
28+
}
29+
30+
public static Protocol.Transaction setReference(Protocol.Transaction transaction,Protocol.Block newestBlock) {
31+
long blockHeight = newestBlock.getBlockHeader().getRawData().getNumber();
32+
33+
byte[] blockHash = getBlockHash(newestBlock).getBytes();
34+
byte[] refBlockNum = ByteArray.fromLong(blockHeight);
35+
Protocol.Transaction.raw rawData = transaction.getRawData().toBuilder()
36+
.setRefBlockHash(ByteString.copyFrom(ByteArray.subArray(blockHash, 8, 16)))
37+
.setRefBlockBytes(ByteString.copyFrom(ByteArray.subArray(refBlockNum, 6, 8)))
38+
.build();
39+
return transaction.toBuilder().setRawData(rawData).build();
40+
}
41+
42+
public static Sha256Sm3Hash getBlockHash(Protocol.Block block) {
43+
return Sha256Sm3Hash.of(block.getBlockHeader().getRawData().toByteArray());
44+
}
45+
46+
public String getTransactionHash(Protocol.Transaction transaction) {
47+
return ByteArray.toHexString(Sha256Sm3Hash.hash(transaction.getRawData().toByteArray()));
48+
}
49+
50+
public static Protocol.Transaction createTransaction(byte[] from, byte[] to, long amount) {
51+
Protocol.Block newestBlock=WalletApi.getBlock(-1);
52+
Protocol.Transaction.Builder transactionBuilder = Protocol.Transaction.newBuilder();
53+
Protocol.Transaction.Contract.Builder contractBuilder = Protocol.Transaction.Contract.newBuilder();
54+
BalanceContract.TransferContract.Builder transferContractBuilder = BalanceContract.TransferContract.newBuilder();
55+
transferContractBuilder.setAmount(amount);
56+
ByteString bsTo = ByteString.copyFrom(to);
57+
ByteString bsOwner = ByteString.copyFrom(from);
58+
transferContractBuilder.setToAddress(bsTo);
59+
transferContractBuilder.setOwnerAddress(bsOwner);
60+
try {
61+
Any any = Any.pack(transferContractBuilder.build());
62+
contractBuilder.setParameter(any);
63+
} catch (Exception e) {
64+
return null;
65+
}
66+
contractBuilder.setType(Protocol.Transaction.Contract.ContractType.TransferContract);
67+
transactionBuilder.getRawDataBuilder().addContract(contractBuilder)
68+
.setTimestamp(System.currentTimeMillis())
69+
.setExpiration(newestBlock.getBlockHeader().getRawData().getTimestamp() + 10 * 60 * 60 * 1000);
70+
Protocol.Transaction transaction = transactionBuilder.build();
71+
return setReference(transaction, newestBlock);
72+
}
73+
74+
75+
@Override
76+
public TxSignResult signTransaction(String chainId, String password, Wallet wallet) {
77+
String privateStr = wallet.exportPrivateKey(password);
78+
byte[] privateBytes = ByteArray.fromHexString(privateStr);
79+
ECKey ecKey = ECKey.fromPrivate(privateBytes);
80+
Protocol.Transaction transaction = createTransaction(WalletApi.decodeFromBase58Check(from), WalletApi.decodeFromBase58Check(to), amount);
81+
assert transaction != null;
82+
transaction = TransactionUtils.sign(transaction, ecKey);
83+
String txHash=getTransactionHash(transaction);
84+
return new TxSignResult(ByteArray.toHexString(transaction.toByteArray()), txHash);
85+
}
86+
87+
public static void main(String[] args) {
88+
89+
String from="TGA1KxMbBvYWL2C4iirBPMz3Lt1BFoHB1D";
90+
String to="TGA1KxMbBvYWL2C4iirBPMz3Lt1BFoHB1D";
91+
long amount=0L;
92+
Protocol.Transaction transaction = createTransaction(WalletApi.decodeFromBase58Check(from), WalletApi.decodeFromBase58Check(to), amount);
93+
assert transaction != null;
94+
System.out.println(ByteArray.toHexString(transaction.toByteArray()));
95+
96+
97+
}
98+
}
99+

src/main/resources/config.conf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
net {
2+
type = mainnet
3+
}
4+
#波场全节点配置
5+
fullnode = {
6+
ip.list = [
7+
"3.225.171.164:50051"
8+
"52.53.189.99:50051"
9+
"18.196.99.16:50051"
10+
"34.253.187.192:50051"
11+
"18.133.82.227:50051"
12+
"35.180.51.163:50051"
13+
"54.252.224.209:50051"
14+
"18.228.15.36:50051"
15+
"52.15.93.92:50051"
16+
"34.220.77.106:50051"
17+
"13.127.47.162:50051"
18+
"13.124.62.58:50051"
19+
"35.182.229.162:50051"
20+
"18.209.42.127:50051"
21+
"3.218.137.187:50051"
22+
"34.237.210.82:50051"
23+
]
24+
}
25+
26+
#soliditynode = {
27+
# // the IPs in this list can only be totally set to solidity or pBFT.
28+
# ip.list = [
29+
# "127.0.0.1:50052" // default solidity
30+
# ]
31+
# ip.list = [
32+
# "127.0.0.1:50071" // or pBFT
33+
# ]
34+
#}
35+
36+
RPC_version = 2
37+
38+
# This field used in shielded transaction. It is recommended that this field is set to the block
39+
# number in which the earliest relevant shielded contract was created. If the exact number is not
40+
# known, this field can be set as follows. If used in mainnet, please set 22690588. If used in Nile
41+
# testnet, please set 6380000. Otherwise, please set 0.
42+
blockNumberStartToScan = 22690588

0 commit comments

Comments
 (0)