-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransaction.js
106 lines (101 loc) · 2.39 KB
/
transaction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { INVALID_ARGUMENT_WITH_CS } from './errors.js'
export default class Transaction {
#id
#block_id
#height
#identifier
#version
#typ
#sender_addr
#recipient_addr
#data
#sign
#fee
#hash
#inserted_at
constructor({
id,
block_id,
height,
identifier,
version,
typ,
sender_addr,
recipient_addr,
data,
sign,
fee,
hash,
inserted_at,
}) {
this.#id = id
this.#block_id = block_id
this.#height = height
this.#identifier = identifier
this.#version = version
this.#typ = typ
this.#sender_addr = sender_addr
this.#recipient_addr = recipient_addr
this.#data = data
this.#sign = sign
this.#fee = fee
this.#hash = hash
this.#inserted_at = inserted_at
}
ToJSONString() {
this.#validate()
return JSON.stringify({
id: this.#id,
block_id: this.#block_id,
height: this.#height,
identifier: this.#identifier,
version: this.#version,
typ: this.#typ,
sender_addr: this.#sender_addr,
recipient_addr: this.#recipient_addr,
data: this.#data,
sign: this.#sign,
fee: this.#fee,
hash: this.#hash,
inserted_at: this.#inserted_at,
})
}
#validate() {
if (typeof this.#id !== 'number') {
throw INVALID_ARGUMENT_WITH_CS('id')
}
if (typeof this.#block_id !== 'number') {
throw INVALID_ARGUMENT_WITH_CS('blockID')
}
if (typeof this.#height !== 'number') {
throw INVALID_ARGUMENT_WITH_CS('height')
}
if (typeof this.#identifier !== 'string') {
throw INVALID_ARGUMENT_WITH_CS('identifier')
}
if (typeof this.#version !== 'number') {
throw INVALID_ARGUMENT_WITH_CS('version')
}
if (typeof this.#typ !== 'string') {
throw INVALID_ARGUMENT_WITH_CS('typ')
}
if (typeof this.#sender_addr !== 'string') {
throw INVALID_ARGUMENT_WITH_CS('senderAddr')
}
if (typeof this.#recipient_addr !== 'string') {
throw INVALID_ARGUMENT_WITH_CS('recipientAddr')
}
if (typeof this.#data !== 'object') {
throw INVALID_ARGUMENT_WITH_CS('data')
}
if (typeof this.#sign !== 'object') {
throw INVALID_ARGUMENT_WITH_CS('sign')
}
if (typeof this.#fee !== 'number') {
throw INVALID_ARGUMENT_WITH_CS('fee')
}
if (typeof this.#inserted_at !== 'string') {
throw INVALID_ARGUMENT_WITH_CS('insertedAt')
}
}
}