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
4fbd6acd
Commit
4fbd6acd
authored
Apr 22, 2021
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
merge master
parents
f76d3676
ce6b1492
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
100 additions
and
61 deletions
+100
-61
Auth.go
middleware/auth/Auth.go
+0
-39
auth.go
middleware/auth/auth.go
+32
-0
rbac.go
pkg/e/rbac.go
+6
-0
util.go
pkg/util/util.go
+26
-0
coin.go
routers/api/backend/coin.go
+1
-1
wallet_coin_relation.go
routers/api/backend/wallet_coin_relation.go
+5
-1
router.go
routers/router.go
+2
-1
coin_gas.go
service/coin_gas_service/coin_gas.go
+28
-19
No files found.
middleware/auth/Auth.go
deleted
100644 → 0
View file @
f76d3676
package
auth
import
(
"github.com/gin-gonic/gin"
"bwallet/pkg/e"
"bwallet/models"
"net/http"
)
func
AUTH
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
var
code
int
var
data
interface
{}
code
=
e
.
SUCCESS
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
if
token
==
""
{
code
=
e
.
INVALID_PARAMS
}
else
{
_
,
err
:=
models
.
CheckToken
(
token
)
if
err
!=
nil
{
code
=
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
}
}
if
code
!=
e
.
SUCCESS
{
c
.
JSON
(
http
.
StatusUnauthorized
,
gin
.
H
{
"code"
:
code
,
"msg"
:
e
.
GetMsg
(
code
),
"data"
:
data
,
})
c
.
Abort
()
return
}
c
.
Next
()
}
}
middleware/auth/auth.go
0 → 100644
View file @
4fbd6acd
package
auth
import
(
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"github.com/gin-gonic/gin"
"strings"
)
func
AUTH
()
gin
.
HandlerFunc
{
return
func
(
ctx
*
gin
.
Context
)
{
token
:=
ctx
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
if
!
strings
.
Contains
(
strings
.
ToLower
(
user
.
UserInfo
.
Username
),
"kefu"
)
{
return
}
handlerName
:=
strings
.
Split
(
ctx
.
HandlerName
(),
"."
)[
1
]
handleAlowed
:=
[]
string
{
"GetCoinChains"
,
"GetUserChains"
,
"AddOperationLog"
}
_
,
handle
:=
util
.
Contains
(
handleAlowed
,
handlerName
)
if
!
handle
{
handler
.
SendResponse
(
ctx
,
errno
.
PermissionDenied
,
nil
)
ctx
.
Abort
()
return
}
ctx
.
Next
()
}
}
pkg/e/rbac.go
0 → 100644
View file @
4fbd6acd
package
e
type
HandleAllowedDesc
map
[
int32
][]
string
var
HandleAllowed
=
HandleAllowedDesc
{
}
pkg/util/util.go
View file @
4fbd6acd
...
...
@@ -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
}
routers/api/backend/coin.go
View file @
4fbd6acd
...
...
@@ -146,7 +146,7 @@ func AddCoin(c *gin.Context) {
Decimals
:
coin
.
Decimals
,
Address
:
coin
.
Address
,
Treaty
:
coin
.
Treaty
,
PlatformId
:
"[
1
]"
,
PlatformId
:
"[]"
,
}
if
err
:=
coinService
.
Add
();
err
!=
nil
{
...
...
routers/api/backend/wallet_coin_relation.go
View file @
4fbd6acd
...
...
@@ -122,7 +122,11 @@ func AddWalletCoinRelationCoinRelation(c *gin.Context) {
}
}
if
is_exist
==
false
{
coinService
.
PlatformId
=
strings
.
Replace
(
coin_exist
.
PlatformId
,
"]"
,
","
,
-
1
)
+
strconv
.
Itoa
(
coin_relation
.
PlatformId
)
+
"]"
if
"[]"
==
coin_exist
.
PlatformId
{
coinService
.
PlatformId
=
strings
.
Replace
(
coin_exist
.
PlatformId
,
"]"
,
util
.
ToString
(
coin_relation
.
PlatformId
),
-
1
)
+
"]"
}
else
{
coinService
.
PlatformId
=
strings
.
Replace
(
coin_exist
.
PlatformId
,
"]"
,
","
,
-
1
)
+
strconv
.
Itoa
(
coin_relation
.
PlatformId
)
+
"]"
}
coinService
.
UpdateCoinRelation
()
}
}
...
...
routers/router.go
View file @
4fbd6acd
package
routers
import
(
"bwallet/middleware/auth"
"bwallet/middleware/jwt"
"bwallet/middleware/log"
"bwallet/pkg/e"
...
...
@@ -52,7 +53,7 @@ func InitRouter() *gin.Engine {
api
:=
r
.
Group
(
"/api"
)
api
.
Use
(
jwt
.
JWT
())
//.Use(auth.Casbin
())
api
.
Use
(
jwt
.
JWT
())
.
Use
(
auth
.
AUTH
())
api
.
POST
(
"/log"
,
backend
.
AddOperationLog
)
api
.
GET
(
"/logs"
,
backend
.
GetOperationLogs
)
api
.
Use
(
log
.
LogMiddleware
(
e
.
HandleTableName
))
...
...
service/coin_gas_service/coin_gas.go
View file @
4fbd6acd
...
...
@@ -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