mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
fix: unset hash128 fields using AccountSet (#2156)
This commit is contained in:
@@ -9,8 +9,25 @@ class Hash128 extends Hash {
|
||||
static readonly ZERO_128: Hash128 = new Hash128(Buffer.alloc(Hash128.width))
|
||||
|
||||
constructor(bytes: Buffer) {
|
||||
if (bytes && bytes.byteLength === 0) {
|
||||
bytes = Hash128.ZERO_128.bytes
|
||||
}
|
||||
|
||||
super(bytes ?? Hash128.ZERO_128.bytes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hex representation of a hash-128 bytes, allowing unset
|
||||
*
|
||||
* @returns hex String of this.bytes
|
||||
*/
|
||||
toHex(): string {
|
||||
const hex = this.toBytes().toString('hex').toUpperCase()
|
||||
if (/^0+$/.exec(hex)) {
|
||||
return ''
|
||||
}
|
||||
return hex
|
||||
}
|
||||
}
|
||||
|
||||
export { Hash128 }
|
||||
|
||||
Reference in New Issue
Block a user