mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 19:25:51 +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 VersionedChecksummedBytes(String encoded) throws AddressFormatException {
|
||||
byte[] tmp = Base58.decodeChecked(encoded);
|
||||
version = tmp[0] & 0xFF;
|
||||
bytes = new byte[tmp.length - 1];
|
||||
System.arraycopy(tmp, 1, bytes, 0, tmp.length - 1);
|
||||
byte[] versionAndDataBytes = Base58.decodeChecked(encoded);
|
||||
byte versionByte = versionAndDataBytes[0];
|
||||
version = versionByte & 0xFF;
|
||||
bytes = new byte[versionAndDataBytes.length - 1];
|
||||
System.arraycopy(versionAndDataBytes, 1, bytes, 0, versionAndDataBytes.length - 1);
|
||||
}
|
||||
|
||||
protected VersionedChecksummedBytes(int version, byte[] bytes) {
|
||||
checkArgument(version < 256 && version >= 0);
|
||||
checkArgument(version >= 0 && version < 256);
|
||||
this.version = version;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
@ -52,8 +53,8 @@ public class VersionedChecksummedBytes {
|
||||
byte[] addressBytes = new byte[1 + bytes.length + 4];
|
||||
addressBytes[0] = (byte) version;
|
||||
System.arraycopy(bytes, 0, addressBytes, 1, bytes.length);
|
||||
byte[] check = Utils.doubleDigest(addressBytes, 0, bytes.length + 1);
|
||||
System.arraycopy(check, 0, addressBytes, bytes.length + 1, 4);
|
||||
byte[] checksum = Utils.doubleDigest(addressBytes, 0, bytes.length + 1);
|
||||
System.arraycopy(checksum, 0, addressBytes, bytes.length + 1, 4);
|
||||
return Base58.encode(addressBytes);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user