ccxt
Version:
35 lines (32 loc) • 1.08 kB
JavaScript
// ----------------------------------------------------------------------------
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
// EDIT THE CORRESPONDENT .ts FILE INSTEAD
import { getAddress } from "../address/index.js";
import { toBeHex } from "../utils/maths.js";
import { Typed } from "../typed.js";
import { Coder } from "./abstract-coder.js";
/**
* @_ignore
*/
export class AddressCoder extends Coder {
constructor(localName) {
super("address", "address", localName, false);
}
defaultValue() {
return "0x0000000000000000000000000000000000000000";
}
encode(writer, _value) {
let value = Typed.dereference(_value, "string");
try {
value = getAddress(value);
}
catch (error) {
return this._throwError(error.message, _value);
}
return writer.writeValue(value);
}
decode(reader) {
return getAddress(toBeHex(reader.readValue(), 20));
}
}