fix: unset hash128 fields using AccountSet (#2156)

This commit is contained in:
pdp2121
2023-02-01 12:27:02 -05:00
committed by GitHub
parent bbc9bd9e4a
commit c74ffddf59
2 changed files with 44 additions and 1 deletions

View File

@@ -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 }