@@ -16,6 +16,8 @@ func (d *DosNode) startRESTServer() (err error) {
1616 mux := http .NewServeMux ()
1717 mux .HandleFunc ("/" , d .status )
1818 mux .HandleFunc ("/balance" , d .balance )
19+ mux .HandleFunc ("/setGasPrice" , d .setGasPrice )
20+ mux .HandleFunc ("/setGasLimit" , d .setGasLimit )
1921 mux .HandleFunc ("/enableAdmin" , d .enableAdmin )
2022 mux .HandleFunc ("/disableAdmin" , d .disableAdmin )
2123 mux .HandleFunc ("/enableGuardian" , d .enableGuardian )
@@ -51,13 +53,13 @@ func (d *DosNode) status(w http.ResponseWriter, r *http.Request) {
5153 html = html + "TotalQuery : " + strconv .Itoa (d .totalQuery ) + "\n |"
5254 html = html + "FulfilledQuery : " + strconv .Itoa (d .fulfilledQuery ) + "\n |"
5355 html = html + "Group Number : " + strconv .Itoa (d .numOfworkingGroup ) + "\n |"
54- html = html + "=================================================" + "\n |"
55- // result := d.dkg.GetGroupNumber()
56+ html = html + "gasPrice : " + strconv . FormatUint ( d . chain . GetGasPrice (), 10 ) + "\n |"
57+ html = html + "gasLimit : " + strconv . FormatUint ( d . chain . GetGasLimit (), 10 ) + " \n |"
5658 balance , err := d .chain .Balance ()
5759 if err != nil {
58- html = html + "Balance : " + err .Error () + "\n |"
60+ html = html + "Balance : " + err .Error () + "\n |"
5961 } else {
60- html = html + "Balance : " + balance .String () + "\n |"
62+ html = html + "Balance : " + balance .String () + "\n |"
6163 }
6264 workingGroupNum , err := d .chain .GetWorkingGroupSize ()
6365 if err != nil {
@@ -83,7 +85,6 @@ func (d *DosNode) status(w http.ResponseWriter, r *http.Request) {
8385 } else {
8486 html = html + "PendingNodeSize : " + strconv .FormatUint (pendingNodeNum , 10 ) + "\n |"
8587 }
86-
8788 curBlk , err := d .chain .CurrentBlock ()
8889 if err != nil {
8990 html = html + "CurrentBlock : " + err .Error () + "\n "
@@ -105,6 +106,39 @@ func (d *DosNode) balance(w http.ResponseWriter, r *http.Request) {
105106 w .Write ([]byte (html ))
106107}
107108
109+ func (d * DosNode ) setGasLimit (w http.ResponseWriter , r * http.Request ) {
110+ gasLimits , ok := r .URL .Query ()["gasLimit" ]
111+ if ! ok || len (gasLimits ) == 0 {
112+ return
113+ }
114+ g , ok := new (big.Int ).SetString (gasLimits [0 ], 10 )
115+ if ! ok {
116+ d .logger .Error (fmt .Errorf ("GasLimit SetString error" ))
117+ return
118+ }
119+ if g .Cmp (big .NewInt (0 )) == 0 {
120+ d .logger .Error (fmt .Errorf ("GasLimit cannot be set to 0" ))
121+ return
122+ }
123+ d .logger .Info (fmt .Sprintf ("Set GasLimit to %v" , g ))
124+ d .chain .SetGasLimit (g )
125+ }
126+
127+ func (d * DosNode ) setGasPrice (w http.ResponseWriter , r * http.Request ) {
128+ gasPrices , ok := r .URL .Query ()["gasPrice" ]
129+ if ! ok || len (gasPrices ) == 0 {
130+ return
131+ }
132+ g , ok := new (big.Int ).SetString (gasPrices [0 ], 10 )
133+ if ! ok {
134+ d .logger .Error (fmt .Errorf ("GasPrice SetString error" ))
135+ return
136+ }
137+ // Set to 0 means using estimate gas price by default
138+ d .logger .Info (fmt .Sprintf ("Set GasPrice to %v wei" , g ))
139+ d .chain .SetGasPrice (g )
140+ }
141+
108142func (d * DosNode ) enableAdmin (w http.ResponseWriter , r * http.Request ) {
109143 d .logger .Info ("isAdmin" )
110144 d .isAdmin = true
0 commit comments