Skip to content

Commit 93efa3b

Browse files
committed
Fix bug that parses address errors
1 parent 9a84179 commit 93efa3b

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ public static void setParam(final String[] args, final String confFileName) {
506506
INSTANCE.localWitnesses.setPrivateKeys(localwitness);
507507

508508
if (config.hasPath("localWitnessAccountAddress")) {
509-
String localWitnessAccountAddress = config.getString("localWitnessAccountAddress");
509+
byte[] bytes = Wallet.decodeFromBase58Check(config.getString("localWitnessAccountAddress"));
510510

511-
if (Wallet.addressValid(ByteArray.fromHexString(localWitnessAccountAddress))) {
512-
INSTANCE.localWitnesses.setWitnessAccountAddress(localWitnessAccountAddress);
511+
if (bytes != null) {
512+
INSTANCE.localWitnesses.setWitnessAccountAddress(bytes);
513513
} else {
514514
logger.warn("The localWitnessAccountAddress format is incorrect, ignored");
515515
}

‎src/main/java/org/tron/core/config/args/LocalWitnesses.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class LocalWitnesses {
3131
@Getter
3232
private List<String> privateKeys = Lists.newArrayList();
3333

34-
private String witnessAccountAddress;
34+
private byte[] witnessAccountAddress;
3535

3636
public LocalWitnesses() {
3737
}
@@ -44,15 +44,15 @@ public LocalWitnesses(List<String> privateKeys) {
4444
setPrivateKeys(privateKeys);
4545
}
4646

47-
public void setWitnessAccountAddress(final String localWitnessAccountAddress) {
47+
public void setWitnessAccountAddress(final byte[] localWitnessAccountAddress) {
4848
this.witnessAccountAddress = localWitnessAccountAddress;
4949
}
5050

51-
public String getWitnessAccountAddress() {
51+
public byte[] getWitnessAccountAddress() {
5252
if (witnessAccountAddress == null) {
5353
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
5454
final ECKey ecKey = ECKey.fromPrivate(privateKey);
55-
this.witnessAccountAddress = ByteArray.toHexString(ecKey.getAddress());
55+
this.witnessAccountAddress = ecKey.getAddress();
5656
}
5757
return witnessAccountAddress;
5858
}
@@ -61,7 +61,7 @@ public void initWitnessAccountAddress() {
6161
if (witnessAccountAddress == null) {
6262
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
6363
final ECKey ecKey = ECKey.fromPrivate(privateKey);
64-
this.witnessAccountAddress = ByteArray.toHexString(ecKey.getAddress());
64+
this.witnessAccountAddress = ecKey.getAddress();
6565
}
6666
}
6767

‎src/main/java/org/tron/core/services/WitnessService.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ public void init() {
353353

354354
byte[] privateKey = ByteArray
355355
.fromHexString(Args.getInstance().getLocalWitnesses().getPrivateKey());
356-
byte[] address = ByteArray
357-
.fromHexString(Args.getInstance().getLocalWitnesses().getWitnessAccountAddress());
356+
byte[] address = Args.getInstance().getLocalWitnesses().getWitnessAccountAddress();
358357

359358
WitnessCapsule witnessCapsule = this.tronApp.getDbManager().getWitnessStore()
360359
.get(address);

‎src/main/resources/config-localtest.conf‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ genesis.block = {
246246
// and the localwitness is configured with the private key of the witnessPermissionAddress in the witness account.
247247
// When it is empty,the localwitness is configured with the private key of the witness account.
248248

249-
//localWitnessAccountAddress =
249+
//localWitnessAccountAddress = TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
250250

251251
localwitness = [
252252
f4df789d3210ac881cb900464dd30409453044d2777060a0c391cbdf4c6a4f57

‎src/test/java/org/tron/core/config/args/ArgsTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.After;
2323
import org.junit.Assert;
2424
import org.junit.Test;
25+
import org.tron.common.utils.ByteArray;
2526
import org.tron.core.Constant;
2627

2728
@Slf4j
@@ -79,8 +80,8 @@ public void get() {
7980

8081
Assert.assertEquals("f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62",
8182
args.getLocalWitnesses().getPrivateKey());
82-
Assert.assertEquals("a0299f3db80a24b20a254b89ce639d59132f157f13",
83-
args.getLocalWitnesses().getWitnessAccountAddress());
83+
Assert.assertEquals("41299f3db80a24b20a254b89ce639d59132f157f13",
84+
ByteArray.toHexString(args.getLocalWitnesses().getWitnessAccountAddress()));
8485

8586

8687
}

0 commit comments

Comments
 (0)