@@ -956,59 +956,85 @@ func (c *RcLimitCommand) Execute(ctx context.Context, ee *ExecutionEnvironment)
956
956
// If no limit given, display current
957
957
if c .limit == nil {
958
958
if ee .rcLimit .absolute {
959
- result .AddMessage (fmt .Sprintf ("Current rc limit: %f" , ee .rcLimit .value ))
959
+ decAmount , err := util .SatoshiToDecimal (ee .rcLimit .value , cliutil .KoinPrecision )
960
+ if err != nil {
961
+ return nil , err
962
+ }
963
+ result .AddMessage (fmt .Sprintf ("Current rc limit: %v" , decAmount ))
960
964
return result , nil
961
965
}
962
966
963
967
// Otherwise its relative
964
968
if ! ee .IsOnline () || ! ee .IsWalletOpen () {
965
- result .AddMessage (fmt .Sprintf ("Current rc limit: %f%%" , ee .rcLimit .value * 100 ))
969
+ decAmount , err := util .SatoshiToDecimal (ee .rcLimit .value , cliutil .KoinPrecision )
970
+ resultVal := decimal .NewFromFloat (100 ).Mul (* decAmount )
971
+ if err != nil {
972
+ return nil , err
973
+ }
974
+ result .AddMessage (fmt .Sprintf ("Current rc limit: %v%%" , resultVal ))
966
975
return result , nil
967
976
}
968
977
969
- limit , err := ee .RPCClient .GetAccountRc (ctx , ee .Key .AddressBytes ())
978
+ amount , err := ee .GetRcLimit (ctx )
979
+ if err != nil {
980
+ return nil , err
981
+ }
982
+
983
+ decAmount , err := util .SatoshiToDecimal (amount , cliutil .KoinPrecision )
970
984
if err != nil {
971
985
return nil , err
972
986
}
973
987
974
- dAmount , err := util .SatoshiToDecimal (limit , cliutil .KoinPrecision )
988
+ decLimit , err := util .SatoshiToDecimal (ee . rcLimit . value , cliutil .KoinPrecision )
975
989
if err != nil {
976
990
return nil , err
977
991
}
978
992
979
- f , _ := dAmount .Mul (decimal .NewFromFloat (ee .rcLimit .value )).Float64 ()
980
- result .AddMessage (fmt .Sprintf ("Current rc limit: %f%% (%f)" , ee .rcLimit .value * 100 , f ))
993
+ result .AddMessage (fmt .Sprintf ("Current rc limit: %v%% (%v)" , decLimit .Mul (decimal .NewFromInt (100 )), decAmount ))
981
994
return result , nil
982
995
}
983
996
984
997
// Otherwise we are setting the limit
985
998
s := * c .limit
986
999
if s [len (s )- 1 ] == '%' {
987
- res , err := strconv . ParseFloat (s [:len (s )- 1 ], 64 )
1000
+ res , err := decimal . NewFromString (s [:len (s )- 1 ])
988
1001
if err != nil {
989
1002
return nil , err
990
1003
}
991
1004
992
1005
// Check bounds
993
- if res < 0 || res > 100 {
1006
+ if res . LessThan ( decimal . NewFromInt ( 0 )) || res . GreaterThan ( decimal . NewFromInt ( 100 )) {
994
1007
return nil , fmt .Errorf ("%w: percentage rc limit must be between 0%% and 100%%" , cliutil .ErrInvalidParam )
995
1008
}
996
1009
997
- ee .rcLimit .value = res / 100.0
1010
+ // Convert to decimal
1011
+ resFrac := res .Div (decimal .NewFromInt (100 ))
1012
+ val , err := util .DecimalToSatoshi (& resFrac , cliutil .KoinPrecision )
1013
+ if err != nil {
1014
+ return nil , err
1015
+ }
1016
+
1017
+ ee .rcLimit .value = val
998
1018
ee .rcLimit .absolute = false
999
- result .AddMessage (fmt .Sprintf ("Set rc limit to %f %%" , res ))
1019
+ result .AddMessage (fmt .Sprintf ("Set rc limit to %v %%" , res ))
1000
1020
return result , nil
1001
1021
}
1002
1022
1003
1023
// Otherwise we are setting the absolute limit
1004
- res , err := strconv .ParseFloat (s , 64 )
1024
+ res , err := decimal .NewFromString (s )
1025
+ if err != nil {
1026
+ return nil , err
1027
+ }
1028
+
1029
+ // Convert to satoshi
1030
+ val , err := util .DecimalToSatoshi (& res , cliutil .KoinPrecision )
1005
1031
if err != nil {
1006
1032
return nil , err
1007
1033
}
1008
1034
1009
- ee .rcLimit .value = res
1035
+ ee .rcLimit .value = val
1010
1036
ee .rcLimit .absolute = true
1011
- result .AddMessage (fmt .Sprintf ("Set rc limit to %f " , res ))
1037
+ result .AddMessage (fmt .Sprintf ("Set rc limit to %v " , res ))
1012
1038
1013
1039
return result , nil
1014
1040
}
0 commit comments