1
- import { Address , ThorId , UInt , Units , VTHO } from '@vechain/sdk-core' ;
1
+ import { Address , BlockId , ThorId , UInt , Units , VTHO } from '@vechain/sdk-core' ;
2
2
3
- class RegularBlockResponse {
3
+ interface CommmonBlockResponseJSON {
4
+ number : number ;
5
+ id : string ;
6
+ size : number ;
7
+ parentID : string ;
8
+ timestamp : number ;
9
+ gasLimit : number ;
10
+ beneficiary : string ;
11
+ gasUsed : number ;
12
+ totalScore : number ;
13
+ txsRoot : string ;
14
+ txsFeatures : number ;
15
+ stateRoot : string ;
16
+ receiptsRoot : string ;
17
+ com : boolean ;
18
+ signer : string ;
19
+ isTrunk : boolean ;
20
+ isFinalized : boolean ;
21
+ }
22
+
23
+ class CommmonBlockResponse {
4
24
readonly number : UInt ;
5
- readonly id : ThorId ;
25
+ readonly id : BlockId ;
6
26
readonly size : UInt ;
7
- readonly parentID : ThorId ;
8
- readonly timestamp : bigint ;
27
+ readonly parentID : BlockId ;
28
+ readonly timestamp : UInt ;
29
+ // to do: use the Gas unit class when it will be available
9
30
readonly gasLimit : VTHO ;
10
31
readonly beneficiary : Address ;
11
32
readonly gasUsed : VTHO ;
@@ -18,14 +39,13 @@ class RegularBlockResponse {
18
39
readonly signer : Address ;
19
40
readonly isTrunk : boolean ;
20
41
readonly isFinalized : boolean ;
21
- readonly transactions : ThorId [ ] ;
22
42
23
- constructor ( json : RegularBlockResponseJSON ) {
43
+ constructor ( json : CommmonBlockResponseJSON ) {
24
44
this . number = UInt . of ( json . number ) ;
25
- this . id = ThorId . of ( json . id ) ;
45
+ this . id = BlockId . of ( json . id ) ;
26
46
this . size = UInt . of ( json . size ) ;
27
- this . parentID = ThorId . of ( json . parentID ) ;
28
- this . timestamp = json . timestamp ;
47
+ this . parentID = BlockId . of ( json . parentID ) ;
48
+ this . timestamp = UInt . of ( json . timestamp ) ;
29
49
this . gasLimit = VTHO . of ( json . gasLimit , Units . wei ) ;
30
50
this . beneficiary = Address . of ( json . beneficiary ) ;
31
51
this . gasUsed = VTHO . of ( json . gasUsed , Units . wei ) ;
@@ -38,18 +58,15 @@ class RegularBlockResponse {
38
58
this . signer = Address . of ( json . signer ) ;
39
59
this . isTrunk = json . isTrunk ;
40
60
this . isFinalized = json . isFinalized ;
41
- this . transactions = json . transactions . map (
42
- ( txId : string ) : ThorId => ThorId . of ( txId )
43
- ) ;
44
61
}
45
62
46
- toJSON ( ) : RegularBlockResponseJSON {
63
+ toJSON ( ) : CommmonBlockResponseJSON {
47
64
return {
48
65
number : this . number . valueOf ( ) ,
49
66
id : this . id . toString ( ) ,
50
67
size : this . size . valueOf ( ) ,
51
68
parentID : this . parentID . toString ( ) ,
52
- timestamp : this . timestamp ,
69
+ timestamp : this . timestamp . valueOf ( ) ,
53
70
gasLimit : Number ( this . gasLimit . wei ) ,
54
71
beneficiary : this . beneficiary . toString ( ) ,
55
72
gasUsed : Number ( this . gasUsed . wei ) ,
@@ -61,33 +78,9 @@ class RegularBlockResponse {
61
78
com : this . com ,
62
79
signer : this . signer . toString ( ) ,
63
80
isTrunk : this . isTrunk ,
64
- isFinalized : this . isFinalized ,
65
- transactions : this . transactions . map ( ( txId : ThorId ) =>
66
- txId . toString ( )
67
- )
68
- } satisfies RegularBlockResponseJSON ;
81
+ isFinalized : this . isFinalized
82
+ } satisfies CommmonBlockResponseJSON ;
69
83
}
70
84
}
71
85
72
- interface RegularBlockResponseJSON {
73
- number : number ;
74
- id : string ;
75
- size : number ;
76
- parentID : string ;
77
- timestamp : bigint ;
78
- gasLimit : number ;
79
- beneficiary : string ;
80
- gasUsed : number ;
81
- totalScore : number ;
82
- txsRoot : string ;
83
- txsFeatures : number ;
84
- stateRoot : string ;
85
- receiptsRoot : string ;
86
- com : boolean ;
87
- signer : string ;
88
- isTrunk : boolean ;
89
- isFinalized : boolean ;
90
- transactions : string [ ] ;
91
- }
92
-
93
- export { RegularBlockResponse , type RegularBlockResponseJSON } ;
86
+ export { type CommmonBlockResponseJSON , CommmonBlockResponse } ;
0 commit comments