Line data Source code
1 : /*
2 : * Package : Ethereum
3 : * Author : S. Hamblett <steve.hamblett@linux.com>
4 : * Date : 18/01/2018
5 : * Copyright : S.Hamblett
6 : *
7 : * The Ethereum client package
8 : */
9 :
10 : part of ethereum;
11 :
12 : /// The Default Block parameter.
13 : /// The parameter selections are mutually exclusive.
14 : /// Note that the setters ignore the passed state value and simply set the property to true.
15 : class EthereumDefaultBlock {
16 : /// Constants
17 : static const String ethEarliest = "earliest";
18 : static const String ethLatest = "latest";
19 : static const String ethPending = "pending";
20 :
21 : /// Latest indicator. Default
22 : bool _latest = true;
23 :
24 1 : bool get latest => _latest;
25 :
26 : set latest(bool state) {
27 2 : _latest = true;
28 2 : _earliest = false;
29 2 : _pending = false;
30 2 : _number = null;
31 : }
32 :
33 : /// Earliest indicator
34 : bool _earliest = false;
35 :
36 1 : bool get earliest => _earliest;
37 :
38 : set earliest(bool state) {
39 2 : _earliest = true;
40 2 : _latest = false;
41 2 : _pending = false;
42 2 : _number = null;
43 : }
44 :
45 : /// Pending indicator
46 : bool _pending = false;
47 :
48 1 : bool get pending => _pending;
49 :
50 : set pending(bool state) {
51 2 : _pending = true;
52 2 : _earliest = false;
53 2 : _latest = false;
54 2 : _number = null;
55 : }
56 :
57 : /// Block number
58 : int _number;
59 :
60 1 : int get number => _number;
61 :
62 : set number(int value) {
63 2 : _number = value;
64 2 : _earliest = false;
65 2 : _latest = false;
66 2 : _pending = false;
67 : }
68 :
69 : /// Get the selected parameter as a string
70 : String getSelection() {
71 2 : if (_latest) {
72 : return ethLatest;
73 : }
74 2 : if (_earliest) {
75 : return ethEarliest;
76 : }
77 2 : if (_pending) {
78 : return ethPending;
79 : }
80 2 : if (_number != null) {
81 4 : return EthereumUtilities.intToHex(_number);
82 : }
83 : return null;
84 : }
85 : }
|