This repository was archived by the owner on Feb 7, 2025. It is now read-only.
File tree 2 files changed +30
-6
lines changed
2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,25 @@ import 'package:web3dart/src/crypto/formatting.dart';
2
2
import 'package:web3dart/web3dart.dart' ;
3
3
4
4
class BlockInformation {
5
- EtherAmount ? baseFeePerGas;
5
+ final EtherAmount ? baseFeePerGas;
6
+ final DateTime timestamp;
6
7
7
- BlockInformation ({this .baseFeePerGas});
8
+ BlockInformation ({
9
+ required this .baseFeePerGas,
10
+ required this .timestamp,
11
+ });
8
12
9
13
factory BlockInformation .fromJson (Map <String , dynamic > json) {
10
14
return BlockInformation (
11
- baseFeePerGas: json.containsKey ('baseFeePerGas' )
12
- ? EtherAmount .fromUnitAndValue (
13
- EtherUnit .wei, hexToInt (json['baseFeePerGas' ] as String ))
14
- : null );
15
+ baseFeePerGas: json.containsKey ('baseFeePerGas' )
16
+ ? EtherAmount .fromUnitAndValue (
17
+ EtherUnit .wei, hexToInt (json['baseFeePerGas' ] as String ))
18
+ : null ,
19
+ timestamp: DateTime .fromMillisecondsSinceEpoch (
20
+ hexToDartInt (json['timestamp' ] as String ) * 1000 ,
21
+ isUtc: true ,
22
+ ),
23
+ );
15
24
}
16
25
17
26
bool get isSupportEIP1559 => baseFeePerGas != null ;
Original file line number Diff line number Diff line change @@ -35,6 +35,21 @@ void main() {
35
35
expect (balance >= BigInt .parse ('410243042034234643784017156276017' ),
36
36
isTrue);
37
37
});
38
+
39
+ test ('Web3Client.getBlockInformation' , () async {
40
+ final blockInfo = await client.getBlockInformation (
41
+ blockNumber: const BlockNum .exact (14074702 ).toBlockParam (),
42
+ );
43
+
44
+ expect (
45
+ blockInfo.timestamp.millisecondsSinceEpoch == 1643113026000 ,
46
+ isTrue,
47
+ );
48
+ expect (
49
+ blockInfo.timestamp.isUtc == true ,
50
+ isTrue,
51
+ );
52
+ });
38
53
},
39
54
skip: infuraProjectId == null || infuraProjectId.length < 32
40
55
? 'Tests require the INFURA_ID environment variable'
You can’t perform that action at this time.
0 commit comments