Skip to content

Commit

Permalink
hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Oct 4, 2023
1 parent fdd7146 commit 759cd03
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions bindings/nodejs/lib/types/block/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class RestrictedAddress extends Address {
/**
* The allowed capabilities bitflags.
*/
allowed_capabilities: Uint8Array = new Uint8Array();
private allowed_capabilities: HexEncodedString = '00';
/**
* @param address An address.
*/
Expand All @@ -174,26 +174,33 @@ class RestrictedAddress extends Address {
this.address = address;
}

setAllowedCapabilities(allowed_capabilities: Uint8Array) {
if (allowed_capabilities.some((c) => c != 0)) {
this.allowed_capabilities =
allowed_capabilities.length.toString(16) +
Buffer.from(
allowed_capabilities.buffer,
allowed_capabilities.byteOffset,
allowed_capabilities.byteLength,
).toString('hex');
} else {
this.allowed_capabilities = '00';
}
}

withAllowedCapabilities(
allowed_capabilities: Uint8Array,
): RestrictedAddress {
this.allowed_capabilities = allowed_capabilities;
this.setAllowedCapabilities(allowed_capabilities);
return this;
}

getAllowedCapabilities(): Uint8Array {
return Uint8Array.from(Buffer.from(this.allowed_capabilities, 'hex'));
}

toString(): string {
let hex = this.address.toString();
if (this.allowed_capabilities.some((c) => c != 0)) {
const cap = Buffer.from(
this.allowed_capabilities.buffer,
this.allowed_capabilities.byteOffset,
this.allowed_capabilities.byteLength,
).toString('hex');
hex += this.allowed_capabilities.length.toString(16) + cap;
} else {
hex += '00';
}
return hex;
return this.address.toString() + this.allowed_capabilities;
}
}

Expand Down

0 comments on commit 759cd03

Please sign in to comment.