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
b112db03
Commit
b112db03
authored
Jan 21, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
b0650fac
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
34 deletions
+84
-34
coin.go
models/coin.go
+16
-0
supported_chain.go
models/supported_chain.go
+2
-0
supported_chain.go
routers/api/v1/supported_chain.go
+52
-34
coin.go
service/coin_service/coin.go
+10
-0
supported_chain.go
service/supported_chain_service/supported_chain.go
+4
-0
No files found.
models/coin.go
View file @
b112db03
...
...
@@ -82,6 +82,22 @@ func GetCoins(pageNum, pageSize int, maps interface{}) ([]*Coin, error) {
return
coins
,
nil
}
func
Find
(
name
string
,
chain
string
)
(
*
Coin
,
error
)
{
var
coin
Coin
err
:=
db
.
Debug
()
.
Where
(
"name = ? and chain = ?"
,
name
,
chain
)
.
First
(
&
coin
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
coin
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
coin
,
nil
}
/**
* 通过id获取指定币种信息
* @param id
...
...
models/supported_chain.go
View file @
b112db03
...
...
@@ -2,6 +2,7 @@ package models
import
(
"bwallet/pkg/setting"
"fmt"
"github.com/jinzhu/gorm"
)
...
...
@@ -98,6 +99,7 @@ func AddSupportedChain(data map[string]interface{}) (error) {
PlatformId
:
data
[
"platform_id"
]
.
(
int
),
CoinId
:
data
[
"coin_id"
]
.
(
int
),
}
fmt
.
Println
(
chain
)
if
err
:=
db
.
Create
(
&
chain
)
.
Error
;
err
!=
nil
{
return
err
}
...
...
routers/api/v1/supported_chain.go
View file @
b112db03
...
...
@@ -5,6 +5,7 @@ import (
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/auth_service"
"bwallet/service/coin_service"
"bwallet/service/supported_chain_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
...
...
@@ -58,6 +59,16 @@ func GetSupportedChains(c *gin.Context) {
}
func
AddSupportedChain
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
}
chain
:=
validate_service
.
SupportedChain
{}
c
.
ShouldBindJSON
(
&
chain
)
...
...
@@ -68,38 +79,47 @@ func AddSupportedChain(c *gin.Context) {
return
}
}
return
//自定义验证
supportedCurrencyValidate
:=
supported_chain_service
.
SupportedChain
{
PlatformId
:
chain
.
PlatformId
,
CoinId
:
11111
,
coinService
:=
coin_service
.
Coin
{
Name
:
chain
.
CoinName
,
Chain
:
strings
.
ToUpper
(
chain
.
CoinName
),
}
total
,
err
:=
supportedCurrencyValidate
.
Count
()
coin
,
err
:=
coinService
.
Find
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCo
untSupportedChain
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrCo
inNotFound
,
nil
)
return
}
if
(
total
>
0
)
{
handler
.
SendResponse
(
c
,
errno
.
ErrExistSupportedChain
,
nil
)
if
""
==
coin
.
Name
{
coinService
:=
coin_service
.
Coin
{
Name
:
chain
.
CoinName
,
Chain
:
"BTY"
,
}
coin
,
err
=
coinService
.
Find
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
return
}
}
if
""
==
coin
.
Name
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
chainService
:=
supported_chain_service
.
SupportedChain
{
PlatformId
:
chain
.
PlatformId
,
CoinId
:
coin
.
ID
,
}
var
platform_id
int
platform_id
=
auth
.
PlatformId
if
(
"administrator"
==
group
)
{
if
chain
.
PlatformId
!=
0
{
platform_id
=
chain
.
PlatformId
}
total
,
err
:=
chainService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountCoin
,
nil
)
return
}
chainService
:=
supported_chain_service
.
SupportedChain
{
PlatformId
:
platform_id
,
CoinId
:
11111
,
if
0
!=
total
{
handler
.
SendResponse
(
c
,
errno
.
ErrExistCoin
,
nil
)
return
}
if
err
:=
chainService
.
Add
();
err
!=
nil
{
...
...
@@ -111,6 +131,16 @@ func AddSupportedChain(c *gin.Context) {
}
func
DeleteSupportedChain
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
}
valid
:=
validation
.
Validation
{}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
...
...
@@ -133,18 +163,6 @@ func DeleteSupportedChain(c *gin.Context) {
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
chain
,
_
:=
chainService
.
Get
()
if
chain
.
PlatformId
!=
auth
.
PlatformId
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
}
}
err
=
chainService
.
Delete
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteSupportedChain
,
nil
)
...
...
service/coin_service/coin.go
View file @
b112db03
...
...
@@ -72,6 +72,16 @@ func (c *Coin) GetAll() ([]*models.Coin, error) {
return
coins
,
nil
}
func
(
c
*
Coin
)
Find
()
(
*
models
.
Coin
,
error
)
{
var
coin
*
models
.
Coin
coin
,
err
:=
models
.
Find
(
c
.
Name
,
c
.
Chain
)
if
err
!=
nil
{
return
nil
,
err
}
return
coin
,
nil
}
/**
* 添加币种信息
* @param
...
...
service/supported_chain_service/supported_chain.go
View file @
b112db03
...
...
@@ -63,6 +63,10 @@ func (c *SupportedChain) getMaps() (map[string]interface{}) {
maps
[
"id"
]
=
c
.
ID
}
if
c
.
CoinId
!=
0
{
maps
[
"coin_id"
]
=
c
.
CoinId
}
if
c
.
PlatformId
!=
0
{
maps
[
"platform_id"
]
=
c
.
PlatformId
}
...
...
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