mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-19 13:45:48 +00:00
Minor refactorings in VersionedChecksummedBytes.
This commit is contained in:
parent
e91cc443e9
commit
f7e982cee1
@ -33,14 +33,15 @@ public class VersionedChecksummedBytes {
|
|||||||
protected byte[] bytes;
|
protected byte[] bytes;
|
||||||
|
|
||||||
protected VersionedChecksummedBytes(String encoded) throws AddressFormatException {
|
protected VersionedChecksummedBytes(String encoded) throws AddressFormatException {
|
||||||
byte[] tmp = Base58.decodeChecked(encoded);
|
byte[] versionAndDataBytes = Base58.decodeChecked(encoded);
|
||||||
version = tmp[0] & 0xFF;
|
byte versionByte = versionAndDataBytes[0];
|
||||||
bytes = new byte[tmp.length - 1];
|
version = versionByte & 0xFF;
|
||||||
System.arraycopy(tmp, 1, bytes, 0, tmp.length - 1);
|
bytes = new byte[versionAndDataBytes.length - 1];
|
||||||
|
System.arraycopy(versionAndDataBytes, 1, bytes, 0, versionAndDataBytes.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VersionedChecksummedBytes(int version, byte[] bytes) {
|
protected VersionedChecksummedBytes(int version, byte[] bytes) {
|
||||||
checkArgument(version < 256 && version >= 0);
|
checkArgument(version >= 0 && version < 256);
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
}
|
}
|
||||||
@ -52,8 +53,8 @@ public class VersionedChecksummedBytes {
|
|||||||
byte[] addressBytes = new byte[1 + bytes.length + 4];
|
byte[] addressBytes = new byte[1 + bytes.length + 4];
|
||||||
addressBytes[0] = (byte) version;
|
addressBytes[0] = (byte) version;
|
||||||
System.arraycopy(bytes, 0, addressBytes, 1, bytes.length);
|
System.arraycopy(bytes, 0, addressBytes, 1, bytes.length);
|
||||||
byte[] check = Utils.doubleDigest(addressBytes, 0, bytes.length + 1);
|
byte[] checksum = Utils.doubleDigest(addressBytes, 0, bytes.length + 1);
|
||||||
System.arraycopy(check, 0, addressBytes, bytes.length + 1, 4);
|
System.arraycopy(checksum, 0, addressBytes, bytes.length + 1, 4);
|
||||||
return Base58.encode(addressBytes);
|
return Base58.encode(addressBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user