MCPcopy Create free account
hub / github.com/ccxt/ccxt / encode

Method encode

ts/src/static_dependencies/ethers/coders/number.ts:35–51  ·  view source on GitHub ↗
(writer: Writer, _value: BigNumberish | Typed)

Source from the content-addressed store, hash-verified

33 }
34
35 encode(writer: Writer, _value: BigNumberish | Typed): number {
36 let value = getBigInt(Typed.dereference(_value, this.type));
37
38 // Check bounds are safe for encoding
39 let maxUintValue = mask(BN_MAX_UINT256, WordSize * 8);
40 if (this.signed) {
41 let bounds = mask(maxUintValue, (this.size * 8) - 1);
42 if (value > bounds || value < -(bounds + BN_1)) {
43 this._throwError("value out-of-bounds", _value);
44 }
45 value = toTwos(value, 8 * WordSize);
46 } else if (value < BN_0 || value > mask(maxUintValue, this.size * 8)) {
47 this._throwError("value out-of-bounds", _value);
48 }
49
50 return writer.writeValue(value);
51 }
52
53 decode(reader: Reader): any {
54 let value = mask(reader.readValue(), this.size * 8);

Callers

nothing calls this directly

Calls 6

getBigIntFunction · 0.90
maskFunction · 0.90
toTwosFunction · 0.90
_throwErrorMethod · 0.80
dereferenceMethod · 0.45
writeValueMethod · 0.45

Tested by

no test coverage detected