diff --git a/common/collections.ts b/common/collections.ts index 7151bdc..9184bcd 100644 --- a/common/collections.ts +++ b/common/collections.ts @@ -18,6 +18,10 @@ export class ByteArray extends Uint8Array { return self } + static empty(): ByteArray { + return ByteArray.fromI32(0) + } + /** * Input length must be even. */ @@ -146,6 +150,10 @@ export class Bytes extends ByteArray { static fromUint8Array(uint8Array: Uint8Array): Bytes { return changetype(uint8Array) } + + static empty(): Bytes { + return changetype(ByteArray.empty()) + } } /** diff --git a/common/numbers.ts b/common/numbers.ts index debe5b8..4bdd98a 100644 --- a/common/numbers.ts +++ b/common/numbers.ts @@ -34,6 +34,16 @@ export class Address extends Bytes { static fromString(s: string): Address { return changetype
(typeConversion.stringToH160(s)) } + + static zero(): Address { + let self = new ByteArray(20) + + for (let i = 0; i < 20; i++) { + self[i] = 0 + } + + return changetype
(self) + } } /** An arbitrary size integer represented as an array of bytes. */ @@ -43,6 +53,10 @@ export class BigInt extends Uint8Array { return BigInt.fromByteArray(byteArray) } + static zero(): BigInt { + return BigInt.fromI32(0) + } + /** * `bytes` assumed to be little-endian. If your input is big-endian, call `.reverse()` first. */ @@ -280,6 +294,10 @@ export class BigDecimal { return bigDecimal.fromString(s) } + static zero(): BigDecimal { + return new BigDecimal(BigInt.zero()) + } + toString(): string { return bigDecimal.toString(this) }