UNPKG

752 BJavaScriptView Raw
1/**
2 * Inv
3 * ===
4 *
5 * Inventory - used in p2p messages.
6 */
7'use strict'
8
9import { Bw } from './bw'
10import { Struct } from './struct'
11
12class 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
45Inv.MSG_TX = 1
46Inv.MSG_BLOCK = 2
47Inv.MSG_FILTERED_BLOCK = 3
48
49export { Inv }