MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / toBeArray

Function toBeArray

src.ts/utils/maths.ts:211–226  ·  view source on GitHub ↗
(_value: BigNumberish)

Source from the content-addressed store, hash-verified

209 * Converts %%value%% to a Big Endian Uint8Array.
210 */
211export function toBeArray(_value: BigNumberish): Uint8Array {
212 const value = getUint(_value, "value");
213
214 if (value === BN_0) { return new Uint8Array([ ]); }
215
216 let hex = value.toString(16);
217 if (hex.length % 2) { hex = "0" + hex; }
218
219 const result = new Uint8Array(hex.length / 2);
220 for (let i = 0; i < result.length; i++) {
221 const offset = i * 2;
222 result[i] = parseInt(hex.substring(offset, offset + 2), 16);
223 }
224
225 return result;
226}
227
228/**
229 * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//.

Callers 1

toQuantityFunction · 0.70

Calls 2

getUintFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected