1 | import {
|
2 | BinaryWriter,
|
3 | common,
|
4 | createSerializeWire,
|
5 | IOHelper,
|
6 | SerializableWire,
|
7 | SerializeWire,
|
8 | UInt160,
|
9 | UInt160Hex,
|
10 | } from '@neo-one/client-common-esnext-esm';
|
11 | import { Equals, Equatable } from './Equatable';
|
12 | import { DeserializeWireBaseOptions, DeserializeWireOptions } from './Serializable';
|
13 | import { Input } from './transaction';
|
14 | import { BinaryReader, utils } from './utils';
|
15 |
|
16 | export interface AccountInputKey {
|
17 | readonly hash: UInt160;
|
18 | readonly input: Input;
|
19 | }
|
20 |
|
21 | export interface AccountInputsKey {
|
22 | readonly hash: UInt160;
|
23 | }
|
24 |
|
25 | export interface AccountInputAdd {
|
26 | readonly hash: UInt160;
|
27 | readonly input: Input;
|
28 | }
|
29 |
|
30 | export class AccountInput implements Equatable, SerializableWire<AccountInput> {
|
31 | public static deserializeWireBase(options: DeserializeWireBaseOptions): AccountInput {
|
32 | const { reader } = options;
|
33 | const hash = reader.readUInt160();
|
34 | const input = Input.deserializeWireBase(options);
|
35 |
|
36 | return new AccountInput({ hash, input });
|
37 | }
|
38 |
|
39 | public static deserializeWire(options: DeserializeWireOptions): AccountInput {
|
40 | return this.deserializeWireBase({
|
41 | context: options.context,
|
42 | reader: new BinaryReader(options.buffer),
|
43 | });
|
44 | }
|
45 |
|
46 | public readonly hash: UInt160;
|
47 | public readonly hashHex: UInt160Hex;
|
48 | public readonly input: Input;
|
49 | public readonly equals: Equals = utils.equals(
|
50 | AccountInput,
|
51 | this,
|
52 | (other) => common.uInt160Equal(this.hash, other.hash) && this.input.equals(other.input),
|
53 | );
|
54 | public readonly serializeWire: SerializeWire = createSerializeWire(this.serializeWireBase.bind(this));
|
55 | private readonly sizeInternal: () => number;
|
56 |
|
57 | public constructor({ hash, input }: AccountInputAdd) {
|
58 | this.hash = hash;
|
59 | this.hashHex = common.uInt160ToHex(hash);
|
60 | this.input = input;
|
61 | this.sizeInternal = utils.lazy(() => IOHelper.sizeOfUInt160 + this.input.size);
|
62 | }
|
63 |
|
64 | public get size(): number {
|
65 | return this.sizeInternal();
|
66 | }
|
67 |
|
68 | public serializeWireBase(writer: BinaryWriter): void {
|
69 | writer.writeUInt160(this.hash);
|
70 | this.input.serializeWireBase(writer);
|
71 | }
|
72 | }
|