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) {
...
@@ -82,6 +82,22 @@ func GetCoins(pageNum, pageSize int, maps interface{}) ([]*Coin, error) {
return
coins
,
nil
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获取指定币种信息
* 通过id获取指定币种信息
* @param id
* @param id
...
...
models/supported_chain.go
View file @
b112db03
...
@@ -2,6 +2,7 @@ package models
...
@@ -2,6 +2,7 @@ package models
import
(
import
(
"bwallet/pkg/setting"
"bwallet/pkg/setting"
"fmt"
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm"
)
)
...
@@ -98,6 +99,7 @@ func AddSupportedChain(data map[string]interface{}) (error) {
...
@@ -98,6 +99,7 @@ func AddSupportedChain(data map[string]interface{}) (error) {
PlatformId
:
data
[
"platform_id"
]
.
(
int
),
PlatformId
:
data
[
"platform_id"
]
.
(
int
),
CoinId
:
data
[
"coin_id"
]
.
(
int
),
CoinId
:
data
[
"coin_id"
]
.
(
int
),
}
}
fmt
.
Println
(
chain
)
if
err
:=
db
.
Create
(
&
chain
)
.
Error
;
err
!=
nil
{
if
err
:=
db
.
Create
(
&
chain
)
.
Error
;
err
!=
nil
{
return
err
return
err
}
}
...
...
routers/api/v1/supported_chain.go
View file @
b112db03
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"bwallet/pkg/handler"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/pkg/util"
"bwallet/service/auth_service"
"bwallet/service/auth_service"
"bwallet/service/coin_service"
"bwallet/service/supported_chain_service"
"bwallet/service/supported_chain_service"
"bwallet/validate_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/Unknwon/com"
...
@@ -58,6 +59,16 @@ func GetSupportedChains(c *gin.Context) {
...
@@ -58,6 +59,16 @@ func GetSupportedChains(c *gin.Context) {
}
}
func
AddSupportedChain
(
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
{}
chain
:=
validate_service
.
SupportedChain
{}
c
.
ShouldBindJSON
(
&
chain
)
c
.
ShouldBindJSON
(
&
chain
)
...
@@ -68,38 +79,47 @@ func AddSupportedChain(c *gin.Context) {
...
@@ -68,38 +79,47 @@ func AddSupportedChain(c *gin.Context) {
return
return
}
}
}
}
return
//自定义验证
coinService
:=
coin_service
.
Coin
{
supportedCurrencyValidate
:=
supported_chain_service
.
SupportedChain
{
Name
:
chain
.
CoinName
,
PlatformId
:
chain
.
PlatformId
,
Chain
:
strings
.
ToUpper
(
chain
.
CoinName
),
CoinId
:
11111
,
}
}
total
,
err
:=
supportedCurrencyValidate
.
Count
()
coin
,
err
:=
coinService
.
Find
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCo
untSupportedChain
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrCo
inNotFound
,
nil
)
return
return
}
}
if
(
total
>
0
)
{
if
""
==
coin
.
Name
{
handler
.
SendResponse
(
c
,
errno
.
ErrExistSupportedChain
,
nil
)
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
return
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
chainService
:=
supported_chain_service
.
SupportedChain
{
authService
:=
auth_service
.
Auth
{
Token
:
token
}
PlatformId
:
chain
.
PlatformId
,
auth
,
_
:=
authService
.
GetUserInfo
()
CoinId
:
coin
.
ID
,
group
:=
auth
.
Group
}
var
platform_id
int
total
,
err
:=
chainService
.
Count
()
platform_id
=
auth
.
PlatformId
if
err
!=
nil
{
if
(
"administrator"
==
group
)
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountCoin
,
nil
)
if
chain
.
PlatformId
!=
0
{
return
platform_id
=
chain
.
PlatformId
}
}
}
chainService
:=
supported_chain_service
.
SupportedChain
{
if
0
!=
total
{
PlatformId
:
platform_id
,
handler
.
SendResponse
(
c
,
errno
.
ErrExistCoin
,
nil
)
CoinId
:
11111
,
return
}
}
if
err
:=
chainService
.
Add
();
err
!=
nil
{
if
err
:=
chainService
.
Add
();
err
!=
nil
{
...
@@ -111,6 +131,16 @@ func AddSupportedChain(c *gin.Context) {
...
@@ -111,6 +131,16 @@ func AddSupportedChain(c *gin.Context) {
}
}
func
DeleteSupportedChain
(
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
{}
valid
:=
validation
.
Validation
{}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
...
@@ -133,18 +163,6 @@ func DeleteSupportedChain(c *gin.Context) {
...
@@ -133,18 +163,6 @@ func DeleteSupportedChain(c *gin.Context) {
return
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
()
err
=
chainService
.
Delete
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteSupportedChain
,
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) {
...
@@ -72,6 +72,16 @@ func (c *Coin) GetAll() ([]*models.Coin, error) {
return
coins
,
nil
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
* @param
...
...
service/supported_chain_service/supported_chain.go
View file @
b112db03
...
@@ -63,6 +63,10 @@ func (c *SupportedChain) getMaps() (map[string]interface{}) {
...
@@ -63,6 +63,10 @@ func (c *SupportedChain) getMaps() (map[string]interface{}) {
maps
[
"id"
]
=
c
.
ID
maps
[
"id"
]
=
c
.
ID
}
}
if
c
.
CoinId
!=
0
{
maps
[
"coin_id"
]
=
c
.
CoinId
}
if
c
.
PlatformId
!=
0
{
if
c
.
PlatformId
!=
0
{
maps
[
"platform_id"
]
=
c
.
PlatformId
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