1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | 'use strict'
|
8 |
|
9 | import { Bw } from './bw'
|
10 | import { Struct } from './struct'
|
11 |
|
12 | class Inv extends Struct {
|
13 | constructor (typeNum, hashBuf) {
|
14 | super({ typeNum, hashBuf })
|
15 | }
|
16 |
|
17 | fromBr (br) {
|
18 | this.typeNum = br.readUInt32LE()
|
19 | this.hashBuf = br.read(32)
|
20 | return this
|
21 | }
|
22 |
|
23 | toBw (bw) {
|
24 | if (!bw) {
|
25 | bw = new Bw()
|
26 | }
|
27 | bw.writeUInt32LE(this.typeNum)
|
28 | bw.write(this.hashBuf)
|
29 | return bw
|
30 | }
|
31 |
|
32 | isTx () {
|
33 | return this.typeNum === Inv.MSG_TX
|
34 | }
|
35 |
|
36 | isBlock () {
|
37 | return this.typeNum === Inv.MSG_BLOCK
|
38 | }
|
39 |
|
40 | isFilteredBlock () {
|
41 | return this.typeNum === Inv.MSG_FILTERED_BLOCK
|
42 | }
|
43 | }
|
44 |
|
45 | Inv.MSG_TX = 1
|
46 | Inv.MSG_BLOCK = 2
|
47 | Inv.MSG_FILTERED_BLOCK = 3
|
48 |
|
49 | export { Inv }
|