Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
568f0617
Commit
568f0617
authored
Apr 20, 2021
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/optimize' into 'master'
optimize See merge request
!37
parents
9a119911
e89cefca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
19 deletions
+54
-19
util.go
pkg/util/util.go
+26
-0
coin_gas.go
service/coin_gas_service/coin_gas.go
+28
-19
No files found.
pkg/util/util.go
View file @
568f0617
...
...
@@ -3,6 +3,7 @@ package util
import
(
"bwallet/pkg/setting"
"crypto/md5"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
...
...
@@ -109,3 +110,28 @@ func Contains(slice []string, val string) (int, bool) {
}
return
-
1
,
false
}
func
FormatFloat
(
num
float64
,
decimal
int
)
string
{
// 默认乘1
d
:=
float64
(
1
)
if
decimal
>
0
{
// 10的N次方
d
=
math
.
Pow10
(
decimal
)
}
// math.trunc作用就是返回浮点数的整数部分
// 再除回去,小数点后无效的0也就不存在了
return
strconv
.
FormatFloat
(
math
.
Trunc
(
num
*
d
)
/
d
,
'f'
,
-
1
,
64
)
}
func
Float64FromBytes
(
bytes
[]
byte
)
float64
{
bits
:=
binary
.
LittleEndian
.
Uint64
(
bytes
)
float
:=
math
.
Float64frombits
(
bits
)
return
float
}
func
Float64Bytes
(
float
float64
)
[]
byte
{
bits
:=
math
.
Float64bits
(
float
)
bytes
:=
make
([]
byte
,
8
)
binary
.
LittleEndian
.
PutUint64
(
bytes
,
bits
)
return
bytes
}
service/coin_gas_service/coin_gas.go
View file @
568f0617
...
...
@@ -36,44 +36,53 @@ func GetTransactionGas(name string) (map[string]interface{}, error) {
if
"ETC"
==
strings
.
ToUpper
(
name
)
||
"HT"
==
strings
.
ToUpper
(
name
)
{
fee
,
_
:=
gredis
.
HashGet
(
"ETC_GAS"
,
"gasPrice"
,
3
)
low
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
30
*
1.1
,
8
)
average
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
30
*
1.2
,
8
)
high
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
30
*
1.3
,
8
)
data
[
"name"
]
=
strings
.
ToUpper
(
name
)
data
[
"low"
]
=
util
.
ToFloat32
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
30
*
(
1
+
0.1
)
data
[
"average"
]
=
util
.
ToFloat32
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
30
*
(
1
+
0.2
)
high
:=
util
.
ToFloat32
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
30
*
(
1
+
0.3
)
data
[
"low"
]
=
low
data
[
"average"
]
=
average
data
[
"high"
]
=
high
if
high
>
0.001
{
data
[
"high"
]
=
0.001
if
util
.
ToFloat64
(
high
)
>
0.001
{
data
[
"high"
]
=
"0.001"
}
}
else
if
"ETH"
==
strings
.
ToUpper
(
name
)
{
fee
,
_
:=
gredis
.
HashGet
(
strings
.
ToUpper
(
name
)
+
"_GAS"
,
"gasPrice"
,
3
)
low
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
1.1
,
8
)
average
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
1.2
,
8
)
high
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
1.3
,
8
)
data
[
"name"
]
=
strings
.
ToUpper
(
name
)
data
[
"low"
]
=
util
.
ToFloat32
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
(
1
+
0.1
)
data
[
"average"
]
=
util
.
ToFloat32
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
(
1
+
0.2
)
high
:=
util
.
ToFloat32
(
string
(
fee
))
/
1000000000
*
30000
*
0.000000001
*
(
1
+
0.3
)
data
[
"low"
]
=
low
data
[
"average"
]
=
average
data
[
"high"
]
=
high
if
high
>
0.1
{
data
[
"high"
]
=
0.1
if
util
.
ToFloat64
(
high
)
>
0.1
{
data
[
"high"
]
=
"0.1"
}
}
else
{
fee
,
_
:=
gredis
.
HashGet
(
strings
.
ToUpper
(
name
)
+
"_GAS"
,
"txFee"
,
3
)
low
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
*
1.1
,
8
)
average
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
*
1.2
,
8
)
high
:=
util
.
FormatFloat
(
util
.
ToFloat64
(
string
(
fee
))
*
1.3
,
8
)
data
[
"name"
]
=
strings
.
ToUpper
(
name
)
data
[
"low"
]
=
util
.
ToFloat32
(
string
(
fee
))
*
(
1
+
0.1
)
data
[
"average"
]
=
util
.
ToFloat32
(
string
(
fee
))
*
(
1
+
0.2
)
high
:=
util
.
ToFloat32
(
string
(
fee
))
*
(
1
+
0.3
)
data
[
"low"
]
=
low
data
[
"average"
]
=
average
data
[
"high"
]
=
high
if
"BTC"
==
strings
.
ToUpper
(
name
)
||
"BCH"
==
strings
.
ToUpper
(
name
)
||
"LTC"
==
strings
.
ToUpper
(
name
)
||
"ZEC"
==
strings
.
ToUpper
(
name
)
||
"DCR"
==
strings
.
ToUpper
(
name
)
{
if
high
>
0.001
{
data
[
"high"
]
=
0.001
if
util
.
ToFloat64
(
high
)
>
0.001
{
data
[
"high"
]
=
"0.001"
}
}
if
"NEO"
==
strings
.
ToUpper
(
name
)
||
"TRX"
==
strings
.
ToUpper
(
name
)
||
"BTY"
==
strings
.
ToUpper
(
name
)
{
if
high
>
1
{
data
[
"high"
]
=
1
if
util
.
ToFloat64
(
high
)
>
1
{
data
[
"high"
]
=
"1"
}
}
if
"ATOM"
==
strings
.
ToUpper
(
name
)
{
if
high
>
0.01
{
data
[
"high"
]
=
0.01
if
util
.
ToFloat64
(
high
)
>
0.01
{
data
[
"high"
]
=
"0.01"
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment