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
5d46ef7b
Commit
5d46ef7b
authored
Mar 23, 2021
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/optimize
parents
6296b8a0
10e0876e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
136 additions
and
24 deletions
+136
-24
supported_currency.go
models/supported_currency.go
+1
-1
cron.go
pkg/cron/cron.go
+1
-7
util.go
pkg/util/util.go
+9
-0
fee.go
routers/api/app/fee.go
+1
-1
router.go
routers/router.go
+1
-1
coin_gas.go
service/coin_gas_service/coin_gas.go
+123
-14
No files found.
models/supported_currency.go
View file @
5d46ef7b
...
@@ -61,7 +61,7 @@ func GetSupportedCurrencyTotal(maps interface{}) (int, error) {
...
@@ -61,7 +61,7 @@ func GetSupportedCurrencyTotal(maps interface{}) (int, error) {
func
GetSupportedCurrencies
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
SupportedCurrency
,
error
)
{
func
GetSupportedCurrencies
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
SupportedCurrency
,
error
)
{
var
currencies
[]
*
SupportedCurrency
var
currencies
[]
*
SupportedCurrency
err
:=
db
.
Preload
(
"Currency"
)
.
Where
(
maps
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
currencies
)
.
Error
err
:=
db
.
Preload
(
"Currency"
)
.
Order
(
"sort"
)
.
Where
(
maps
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
currencies
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/cron/cron.go
View file @
5d46ef7b
...
@@ -11,13 +11,7 @@ func Setup(){
...
@@ -11,13 +11,7 @@ func Setup(){
c
=
cron
.
New
()
c
=
cron
.
New
()
c
.
AddFunc
(
"* * * * * *"
,
func
()
{
c
.
AddFunc
(
"* * * * * *"
,
func
()
{
gas_service
:=
coin_gas_service
.
CoinGas
{}
coin_gas_service
.
TokenView
()
gas_service
.
Etherscan
()
})
c
.
AddFunc
(
"* * * * * *"
,
func
()
{
gas_service
:=
coin_gas_service
.
CoinGas
{}
gas_service
.
Btcscan
()
})
})
c
.
Start
()
c
.
Start
()
...
...
pkg/util/util.go
View file @
5d46ef7b
...
@@ -100,3 +100,12 @@ func StringToMd5(str string) string {
...
@@ -100,3 +100,12 @@ func StringToMd5(str string) string {
md5String
:=
hex
.
EncodeToString
(
m5
.
Sum
(
nil
))
md5String
:=
hex
.
EncodeToString
(
m5
.
Sum
(
nil
))
return
md5String
return
md5String
}
}
func
Contains
(
slice
[]
string
,
val
string
)
(
int
,
bool
)
{
for
i
,
item
:=
range
slice
{
if
item
==
val
{
return
i
,
true
}
}
return
-
1
,
false
}
routers/api/app/fee.go
View file @
5d46ef7b
...
@@ -66,7 +66,7 @@ func GetTransactionGas(c *gin.Context) {
...
@@ -66,7 +66,7 @@ func GetTransactionGas(c *gin.Context) {
return
return
}
}
gas
,
err
:=
coin_gas_service
.
Get
Coi
nGas
(
name
)
gas
,
err
:=
coin_gas_service
.
Get
Transactio
nGas
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
...
...
routers/router.go
View file @
5d46ef7b
...
@@ -47,7 +47,7 @@ func InitRouter() *gin.Engine {
...
@@ -47,7 +47,7 @@ func InitRouter() *gin.Engine {
client
.
POST
(
"/live/verify"
,
app
.
VerifyStatus
)
client
.
POST
(
"/live/verify"
,
app
.
VerifyStatus
)
client
.
GET
(
"/live-banners"
,
app
.
GetLiveBanners
)
client
.
GET
(
"/live-banners"
,
app
.
GetLiveBanners
)
client
.
GET
(
"/
coin-gas
"
,
app
.
GetTransactionGas
)
client
.
GET
(
"/
fees/recommended
"
,
app
.
GetTransactionGas
)
api
:=
r
.
Group
(
"/api"
)
api
:=
r
.
Group
(
"/api"
)
...
...
service/coin_gas_service/coin_gas.go
View file @
5d46ef7b
package
coin_gas_service
package
coin_gas_service
import
(
import
(
"bwallet/pkg/errno"
"bwallet/pkg/gredis"
"bwallet/pkg/gredis"
"bwallet/pkg/util"
"bwallet/pkg/util"
"encoding/json"
"encoding/json"
...
@@ -10,24 +11,77 @@ import (
...
@@ -10,24 +11,77 @@ import (
"strings"
"strings"
)
)
type
CoinGas
struct
{
type
Response
struct
{
Id
int
Code
int
`json:"code"`
CoinName
string
Msg
string
`json:"msg"`
Low
float32
Data
[]
Data
`json:"data"`
Average
float32
High
float32
}
}
func
GetCoinGas
(
coin
string
)
(
float32
,
error
)
{
type
Data
struct
{
gas
,
err
:=
gredis
.
HashGet
(
strings
.
ToUpper
(
coin
)
+
"_GAS"
,
"Final"
,
3
)
Network
string
`json:network`
if
err
!=
nil
{
Time
int
`json:time`
return
0.0
,
err
TxFee
string
`json:txFee`
GasPrice
string
`json:gasPrice`
}
func
GetTransactionGas
(
name
string
)
(
map
[
string
]
interface
{},
error
)
{
data
:=
make
(
map
[
string
]
interface
{})
items_fee
:=
[]
string
{
"BTC"
,
"BCH"
,
"LTC"
,
"ZEC"
,
"ZCASH"
,
"DCR"
,
"NEO"
,
"TRX"
,
"ATOM"
,
"BTY"
,
"ETC"
,
"ETH"
,
"HT"
}
_
,
found_fee
:=
util
.
Contains
(
items_fee
,
strings
.
ToUpper
(
name
))
if
!
found_fee
{
return
nil
,
errno
.
ErrCoinNotFound
}
if
"ETC"
==
strings
.
ToUpper
(
name
)
||
"HT"
==
strings
.
ToUpper
(
name
)
{
fee
,
_
:=
gredis
.
HashGet
(
"ETC_GAS"
,
"gasPrice"
,
3
)
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
[
"high"
]
=
high
if
high
>
0.001
{
data
[
"high"
]
=
0.001
}
}
else
if
"ETH"
==
strings
.
ToUpper
(
name
)
{
fee
,
_
:=
gredis
.
HashGet
(
strings
.
ToUpper
(
name
)
+
"_GAS"
,
"gasPrice"
,
3
)
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
[
"high"
]
=
high
if
high
>
0.1
{
data
[
"high"
]
=
0.1
}
}
else
{
fee
,
_
:=
gredis
.
HashGet
(
strings
.
ToUpper
(
name
)
+
"_GAS"
,
"txFee"
,
3
)
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
[
"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
"NEO"
==
strings
.
ToUpper
(
name
)
||
"TRX"
==
strings
.
ToUpper
(
name
)
||
"BTY"
==
strings
.
ToUpper
(
name
)
{
if
high
>
1
{
data
[
"high"
]
=
1
}
}
if
"ATOM"
==
strings
.
ToUpper
(
name
)
{
if
high
>
0.01
{
data
[
"high"
]
=
0.01
}
}
}
}
return
util
.
ToFloat32
(
string
(
gas
)),
nil
return
data
,
nil
}
}
func
(
a
*
CoinGas
)
Etherscan
()
error
{
func
Etherscan
()
error
{
params
:=
make
(
map
[
string
]
string
)
params
:=
make
(
map
[
string
]
string
)
params
[
"module"
]
=
"gastracker"
params
[
"module"
]
=
"gastracker"
params
[
"action"
]
=
"gasoracle"
params
[
"action"
]
=
"gasoracle"
...
@@ -66,7 +120,7 @@ func (a *CoinGas) Etherscan() error {
...
@@ -66,7 +120,7 @@ func (a *CoinGas) Etherscan() error {
return
nil
return
nil
}
}
func
(
a
*
CoinGas
)
Btcscan
()
error
{
func
Btcscan
()
error
{
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"https://btc.com/service/fees/recommended"
,
nil
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"https://btc.com/service/fees/recommended"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -88,8 +142,63 @@ func (a *CoinGas) Btcscan() error {
...
@@ -88,8 +142,63 @@ func (a *CoinGas) Btcscan() error {
gredis
.
HashSet
(
"BTC_GAS"
,
"Average"
,
btc_gas
[
"one_block_fee"
],
3
)
gredis
.
HashSet
(
"BTC_GAS"
,
"Average"
,
btc_gas
[
"one_block_fee"
],
3
)
gredis
.
HashSet
(
"BTC_GAS"
,
"High"
,
btc_gas
[
"one_block_fee"
],
3
)
gredis
.
HashSet
(
"BTC_GAS"
,
"High"
,
btc_gas
[
"one_block_fee"
],
3
)
final
:=
util
.
ToFloat32
(
btc_gas
[
"one_block_fee"
])
*
(
1
+
0.1
)
final
:=
util
.
ToFloat32
(
btc_gas
[
"one_block_fee"
])
*
(
1
+
0.1
)
*
0.00001
gredis
.
HashSet
(
"BTC_GAS"
,
"Final"
,
final
,
3
)
gredis
.
HashSet
(
"BTC_GAS"
,
"Final"
,
final
,
3
)
return
nil
return
nil
}
}
func
TokenView
()
error
{
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"https://tokenview.com/api/block/latest"
,
nil
)
if
err
!=
nil
{
return
err
}
r
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
return
err
}
responseData
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
if
err
!=
nil
{
return
err
}
var
responseObject
Response
json
.
Unmarshal
(
responseData
,
&
responseObject
)
for
_
,
val
:=
range
responseObject
.
Data
{
if
"-"
==
val
.
TxFee
||
"-"
==
val
.
GasPrice
{
continue
}
if
"BTC"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"BTC_GAS"
,
"txFee"
,
val
.
TxFee
,
3
)
gredis
.
HashSet
(
"BTC_GAS"
,
"time"
,
val
.
Time
,
3
)
}
if
"BCH"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"BCH_GAS"
,
"txFee"
,
val
.
TxFee
,
3
)
gredis
.
HashSet
(
"BCH_GAS"
,
"time"
,
val
.
Time
,
3
)
}
if
"LTC"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"LTC_GAS"
,
"txFee"
,
val
.
TxFee
,
3
)
gredis
.
HashSet
(
"LTC_GAS"
,
"time"
,
val
.
Time
,
3
)
}
if
"ZCASH"
==
strings
.
ToUpper
(
val
.
Network
)
||
"ZEC"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"ZEC_GAS"
,
"txFee"
,
val
.
TxFee
,
3
)
gredis
.
HashSet
(
"ZEC_GAS"
,
"time"
,
val
.
Time
,
3
)
}
if
"DCR"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"DCR_GAS"
,
"txFee"
,
val
.
TxFee
,
3
)
gredis
.
HashSet
(
"DCR_GAS"
,
"time"
,
val
.
Time
,
3
)
}
if
"ETC"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"ETC_GAS"
,
"gasPrice"
,
val
.
GasPrice
,
3
)
gredis
.
HashSet
(
"ETC_GAS"
,
"time"
,
val
.
Time
,
3
)
gredis
.
HashSet
(
"HT_GAS"
,
"gasPrice"
,
val
.
GasPrice
,
3
)
gredis
.
HashSet
(
"HT_GAS"
,
"time"
,
val
.
Time
,
3
)
}
if
"ETH"
==
strings
.
ToUpper
(
val
.
Network
)
{
gredis
.
HashSet
(
"ETH_GAS"
,
"gasPrice"
,
val
.
GasPrice
,
3
)
gredis
.
HashSet
(
"ETH_GAS"
,
"time"
,
val
.
Time
,
3
)
}
}
return
nil
}
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