1 | import {
|
2 | BinaryWriter,
|
3 | createSerializeWire,
|
4 | InvalidFormatError,
|
5 | SerializableWire,
|
6 | SerializeWire,
|
7 | } from '@neo-one/client-common-esnext-esm';
|
8 | import { BinaryReader, DeserializeWireBaseOptions, DeserializeWireOptions } from '@neo-one/node-core-esnext-esm';
|
9 | export interface FilterLoadPayloadAdd {
|
10 | readonly filter: Buffer;
|
11 | readonly k: number;
|
12 | readonly tweak: number;
|
13 | }
|
14 |
|
15 | export class FilterLoadPayload implements SerializableWire<FilterLoadPayload> {
|
16 | public static deserializeWireBase({ reader }: DeserializeWireBaseOptions): FilterLoadPayload {
|
17 | const filter = reader.readVarBytesLE(36000);
|
18 | const k = reader.readUInt8();
|
19 | const tweak = reader.readUInt32LE();
|
20 | if (k > 50) {
|
21 | throw new InvalidFormatError();
|
22 | }
|
23 |
|
24 | return new this({ filter, k, tweak });
|
25 | }
|
26 |
|
27 | public static deserializeWire(options: DeserializeWireOptions): FilterLoadPayload {
|
28 | return this.deserializeWireBase({
|
29 | context: options.context,
|
30 | reader: new BinaryReader(options.buffer),
|
31 | });
|
32 | }
|
33 |
|
34 | public readonly filter: Buffer;
|
35 | public readonly k: number;
|
36 | public readonly tweak: number;
|
37 | public readonly serializeWire: SerializeWire = createSerializeWire(this.serializeWireBase.bind(this));
|
38 |
|
39 | public constructor({ filter, k, tweak }: FilterLoadPayloadAdd) {
|
40 | this.filter = filter;
|
41 | this.k = k;
|
42 | this.tweak = tweak;
|
43 | }
|
44 |
|
45 | public serializeWireBase(writer: BinaryWriter): void {
|
46 | writer.writeVarBytesLE(this.filter);
|
47 | writer.writeUInt8(this.k);
|
48 | writer.writeUInt32LE(this.tweak);
|
49 | }
|
50 | }
|