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
34e8c7c5
Commit
34e8c7c5
authored
Jan 07, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
钱包-链对应关系
parent
4c4e7b60
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
361 additions
and
26 deletions
+361
-26
chain.go
models/chain.go
+4
-2
platform_chain.go
models/platform_chain.go
+88
-0
wallet.go
models/wallet.go
+6
-6
errno.go
pkg/errno/errno.go
+8
-0
platform_chain.go
routers/api/v1/platform_chain.go
+149
-0
wallet.go
routers/api/v1/wallet.go
+6
-6
router.go
routers/router.go
+4
-0
platform_chain.go
service/platform_chain_service/platform_chain.go
+74
-0
wallet.go
service/wallet_service/wallet.go
+9
-9
platform_chain.go
validate_service/platform_chain.go
+10
-0
wallet.go
validate_service/wallet.go
+3
-3
No files found.
models/chain.go
View file @
34e8c7c5
package
models
package
models
import
(
import
(
"github.com/jinzhu/gorm"
"bwallet/pkg/setting"
"bwallet/pkg/setting"
"github.com/jinzhu/gorm"
)
)
type
Chain
struct
{
type
Chain
struct
{
ID
int
`json:"primary_key"`
Model
Id
int
`json:"primary_key"`
Platform
string
`json:"platform"`
//平行链名称
Platform
string
`json:"platform"`
//平行链名称
Address
string
`json:"address"`
//代扣地址
Address
string
`json:"address"`
//代扣地址
PrivateKey
string
`json:"private_key"`
//代扣私钥
PrivateKey
string
`json:"private_key"`
//代扣私钥
...
...
models/platform_chain.go
0 → 100644
View file @
34e8c7c5
package
models
import
(
"bwallet/pkg/setting"
"github.com/jinzhu/gorm"
)
type
PlatformChain
struct
{
Model
Id
int
`json:"primary_key,omitempty"`
ChainId
int
`json:"chain_id"`
PlatformId
int
`json:"platform_id"`
Chain
Chain
`json:"Chain"`
Platform
Wallet
`json:"Platform"`
}
func
(
c
PlatformChain
)
TableName
()
string
{
return
setting
.
DatabaseSetting
.
Name_Sources
+
".wallet_platform_chain"
}
func
GetPlatformChain
(
id
int
)
(
*
PlatformChain
,
error
)
{
var
platformChain
PlatformChain
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
First
(
&
platformChain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
platformChain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
platformChain
,
nil
}
func
ExistPlatformChainById
(
id
int
)
(
bool
,
error
)
{
var
platformChain
PlatformChain
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
platformChain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
platformChain
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
func
GetPlatformChainTotal
(
maps
interface
{})
(
int
,
error
)
{
var
count
int
if
err
:=
db
.
Debug
()
.
Model
(
&
PlatformChain
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
func
GetPlatformChains
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
PlatformChain
,
error
)
{
var
platformChain
[]
*
PlatformChain
err
:=
db
.
Preload
(
"Chain"
)
.
Preload
(
"Platform"
)
.
Where
(
maps
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
platformChain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
platformChain
,
nil
}
func
AddPlatformChain
(
data
map
[
string
]
interface
{})
(
error
)
{
platformChain
:=
PlatformChain
{
PlatformId
:
data
[
"platform_id"
]
.
(
int
),
ChainId
:
data
[
"chain_id"
]
.
(
int
),
}
if
err
:=
db
.
Create
(
&
platformChain
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
func
DeletePlatformChain
(
id
int
)
error
{
if
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
Delete
(
PlatformChain
{})
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
models/wallet.go
View file @
34e8c7c5
...
@@ -11,9 +11,9 @@ type Wallet struct {
...
@@ -11,9 +11,9 @@ type Wallet struct {
Name
string
`gorm:"size:255;not null;" json:"name"`
Name
string
`gorm:"size:255;not null;" json:"name"`
DownloadUrl
string
`gorm:"not null;" json:"download_url"`
DownloadUrl
string
`gorm:"not null;" json:"download_url"`
Introduce
string
`gorm:"not null;" json:"introduce"`
Introduce
string
`gorm:"not null;" json:"introduce"`
ChainId
int
`gorm:"not null;default:0" json:"chain_id"`
//
ChainId int `gorm:"not null;default:0" json:"chain_id"`
IssueCharge
float32
`gorm:"not null;default:0.00" json:"issue_charge"`
//
IssueCharge float32 `gorm:"not null;default:0.00" json:"issue_charge"`
ChargeUnit
string
`gorm:"not null;default:BTY" json:"charge_unit"`
//
ChargeUnit string `gorm:"not null;default:BTY" json:"charge_unit"`
}
}
func
(
w
Wallet
)
TableName
()
string
{
func
(
w
Wallet
)
TableName
()
string
{
...
@@ -73,9 +73,9 @@ func AddWallet(data map[string]interface{}) (error) {
...
@@ -73,9 +73,9 @@ func AddWallet(data map[string]interface{}) (error) {
Name
:
data
[
"name"
]
.
(
string
),
Name
:
data
[
"name"
]
.
(
string
),
DownloadUrl
:
data
[
"download_url"
]
.
(
string
),
DownloadUrl
:
data
[
"download_url"
]
.
(
string
),
Introduce
:
data
[
"introduce"
]
.
(
string
),
Introduce
:
data
[
"introduce"
]
.
(
string
),
ChargeUnit
:
data
[
"charge_unit"
]
.
(
string
),
//
ChargeUnit: data["charge_unit"].(string),
IssueCharge
:
data
[
"issue_charge"
]
.
(
float32
),
//
IssueCharge: data["issue_charge"].(float32),
ChainId
:
data
[
"chain_id"
]
.
(
int
),
//
ChainId: data["chain_id"].(int),
}
}
if
err
:=
db
.
Create
(
&
wallet
)
.
Error
;
err
!=
nil
{
if
err
:=
db
.
Create
(
&
wallet
)
.
Error
;
err
!=
nil
{
return
err
return
err
...
...
pkg/errno/errno.go
View file @
34e8c7c5
...
@@ -103,6 +103,14 @@ var (
...
@@ -103,6 +103,14 @@ var (
ErrDeleteSupportedCurrency
=
&
Errno
{
Code
:
20102
,
Message
:
"The supported currency delete error."
}
ErrDeleteSupportedCurrency
=
&
Errno
{
Code
:
20102
,
Message
:
"The supported currency delete error."
}
ErrExistSupportedCurrency
=
&
Errno
{
Code
:
20103
,
Message
:
"The supported currency already exists."
}
ErrExistSupportedCurrency
=
&
Errno
{
Code
:
20103
,
Message
:
"The supported currency already exists."
}
// wallet supported chain errors
ErrWalletSupportedChainNotFound
=
&
Errno
{
Code
:
20101
,
Message
:
"The wallet supported chain was not found."
}
ErrCountWalletSupportedChain
=
&
Errno
{
Code
:
20102
,
Message
:
"The wallet supported chain statistic error."
}
ErrAddWalletSupportedChain
=
&
Errno
{
Code
:
20101
,
Message
:
"The wallet supported chain add error."
}
ErrUpdateWalletSupportedChain
=
&
Errno
{
Code
:
20102
,
Message
:
"The wallet supported chain update error."
}
ErrDeleteWalletSupportedChain
=
&
Errno
{
Code
:
20102
,
Message
:
"The wallet supported chain delete error."
}
ErrExistWalletSupportedChain
=
&
Errno
{
Code
:
20103
,
Message
:
"The wallet supported chain already exists."
}
// user errors
// user errors
ErrUserTokenIncorrect
=
&
Errno
{
Code
:
40001
,
Message
:
"The user token was incorrect."
}
ErrUserTokenIncorrect
=
&
Errno
{
Code
:
40001
,
Message
:
"The user token was incorrect."
}
ErrUserAuthIncorrect
=
&
Errno
{
Code
:
40001
,
Message
:
"The user auth was incorrect."
}
ErrUserAuthIncorrect
=
&
Errno
{
Code
:
40001
,
Message
:
"The user auth was incorrect."
}
...
...
routers/api/v1/platform_chain.go
0 → 100644
View file @
34e8c7c5
package
v1
import
(
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/auth_service"
"bwallet/service/platform_chain_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"strings"
)
func
GetPlatformChains
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
platform_id
=
auth
.
PlatformId
if
(
"administrator"
==
group
)
{
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
platform_id
=
com
.
StrTo
(
c
.
Query
(
"platform_id"
))
.
MustInt
()
}
}
platformChainService
:=
platform_chain_service
.
PlatformChain
{
PlatformId
:
platform_id
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
total
,
err
:=
platformChainService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountWalletSupportedChain
,
nil
)
return
}
coinRecommends
,
err
:=
platformChainService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
coinRecommends
data
[
"total"
]
=
total
handler
.
SendResponse
(
c
,
nil
,
data
)
}
func
AddPlatformChain
(
c
*
gin
.
Context
)
{
platform_chain
:=
validate_service
.
PlatformChain
{}
c
.
ShouldBindJSON
(
&
platform_chain
)
//方法一
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
platform_chain
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
}
}
//自定义验证
platformChainValidate
:=
platform_chain_service
.
PlatformChain
{
PlatformId
:
platform_chain
.
PlatformId
,
ChainId
:
platform_chain
.
ChainId
,
}
total
,
err
:=
platformChainValidate
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountWalletSupportedChain
,
nil
)
return
}
if
(
total
>
0
)
{
handler
.
SendResponse
(
c
,
errno
.
ErrExistWalletSupportedChain
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
platform_id
=
auth
.
PlatformId
if
(
"administrator"
==
group
)
{
if
platform_chain
.
PlatformId
!=
0
{
platform_id
=
platform_chain
.
PlatformId
}
}
platformChainService
:=
platform_chain_service
.
PlatformChain
{
PlatformId
:
platform_id
,
ChainId
:
platform_chain
.
ChainId
,
}
if
err
:=
platformChainService
.
Add
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrAddWalletSupportedChain
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
DeletePlatformChain
(
c
*
gin
.
Context
)
{
valid
:=
validation
.
Validation
{}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
platformChainService
:=
platform_chain_service
.
PlatformChain
{
Id
:
id
}
exists
,
err
:=
platformChainService
.
ExistById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrWalletSupportedChainNotFound
,
nil
)
return
}
if
!
exists
{
handler
.
SendResponse
(
c
,
errno
.
ErrWalletSupportedChainNotFound
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
platform_chain
,
_
:=
platformChainService
.
Get
()
if
platform_chain
.
PlatformId
!=
auth
.
PlatformId
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
}
}
err
=
platformChainService
.
Delete
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteWalletSupportedChain
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
routers/api/v1/wallet.go
View file @
34e8c7c5
...
@@ -186,9 +186,9 @@ func AddWallet(c *gin.Context) {
...
@@ -186,9 +186,9 @@ func AddWallet(c *gin.Context) {
Name
:
wallet
.
Name
,
Name
:
wallet
.
Name
,
DownloadUrl
:
wallet
.
DownloadUrl
,
DownloadUrl
:
wallet
.
DownloadUrl
,
Introduce
:
wallet
.
Introduce
,
Introduce
:
wallet
.
Introduce
,
ChainId
:
wallet
.
ChainId
,
//
ChainId: wallet.ChainId,
IssueCharge
:
wallet
.
IssueCharge
,
//
IssueCharge: wallet.IssueCharge,
ChargeUnit
:
wallet
.
ChargeUnit
,
//
ChargeUnit: wallet.ChargeUnit,
}
}
if
err
:=
walletService
.
Add
();
err
!=
nil
{
if
err
:=
walletService
.
Add
();
err
!=
nil
{
...
@@ -216,9 +216,9 @@ func EditWallet(c *gin.Context) {
...
@@ -216,9 +216,9 @@ func EditWallet(c *gin.Context) {
Name
:
wallet
.
Name
,
Name
:
wallet
.
Name
,
DownloadUrl
:
wallet
.
DownloadUrl
,
DownloadUrl
:
wallet
.
DownloadUrl
,
Introduce
:
wallet
.
Introduce
,
Introduce
:
wallet
.
Introduce
,
ChainId
:
wallet
.
ChainId
,
//
ChainId: wallet.ChainId,
IssueCharge
:
wallet
.
IssueCharge
,
//
IssueCharge: wallet.IssueCharge,
ChargeUnit
:
wallet
.
ChargeUnit
,
//
ChargeUnit: wallet.ChargeUnit,
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
...
...
routers/router.go
View file @
34e8c7c5
...
@@ -61,6 +61,10 @@ func InitRouter() *gin.Engine {
...
@@ -61,6 +61,10 @@ func InitRouter() *gin.Engine {
api
.
PUT
(
"/supported-currency"
,
v1
.
EditSupportedCurrency
)
api
.
PUT
(
"/supported-currency"
,
v1
.
EditSupportedCurrency
)
api
.
DELETE
(
"/supported-currency/:id"
,
v1
.
DeleteSupportedCurrency
)
api
.
DELETE
(
"/supported-currency/:id"
,
v1
.
DeleteSupportedCurrency
)
api
.
GET
(
"/currencies"
,
v1
.
GetCurrencies
)
api
.
GET
(
"/currencies"
,
v1
.
GetCurrencies
)
api
.
GET
(
"/platform-chains"
,
v1
.
GetPlatformChains
)
api
.
POST
(
"/platform-chain"
,
v1
.
AddPlatformChain
)
api
.
DELETE
(
"/platform-chain/:id"
,
v1
.
DeletePlatformChain
)
}
}
return
r
return
r
...
...
service/platform_chain_service/platform_chain.go
0 → 100644
View file @
34e8c7c5
package
platform_chain_service
import
(
"bwallet/models"
)
type
PlatformChain
struct
{
Id
int
ChainId
int
PlatformId
int
PageNum
int
PageSize
int
}
func
(
c
*
PlatformChain
)
Get
()
(
*
models
.
PlatformChain
,
error
)
{
platformChain
,
err
:=
models
.
GetPlatformChain
(
c
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
return
platformChain
,
nil
}
func
(
c
*
PlatformChain
)
GetAll
()
([]
*
models
.
PlatformChain
,
error
)
{
var
coinsRecommend
[]
*
models
.
PlatformChain
coinsRecommend
,
err
:=
models
.
GetPlatformChains
(
c
.
PageNum
,
c
.
PageSize
,
c
.
getMaps
())
if
err
!=
nil
{
return
nil
,
err
}
return
coinsRecommend
,
nil
}
func
(
c
*
PlatformChain
)
Add
()
error
{
platformChain
:=
map
[
string
]
interface
{}{
"platform_id"
:
c
.
PlatformId
,
"chain_id"
:
c
.
ChainId
,
}
if
err
:=
models
.
AddPlatformChain
(
platformChain
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
c
*
PlatformChain
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistPlatformChainById
(
c
.
Id
)
}
func
(
c
*
PlatformChain
)
Count
()
(
int
,
error
)
{
return
models
.
GetPlatformChainTotal
(
c
.
getMaps
())
}
func
(
c
*
PlatformChain
)
Delete
()
error
{
return
models
.
DeletePlatformChain
(
c
.
Id
)
}
func
(
c
*
PlatformChain
)
getMaps
()
(
map
[
string
]
interface
{})
{
maps
:=
make
(
map
[
string
]
interface
{})
if
c
.
PlatformId
!=
0
{
maps
[
"platform_id"
]
=
c
.
PlatformId
}
if
c
.
ChainId
!=
0
{
maps
[
"chain_id"
]
=
c
.
ChainId
}
return
maps
}
service/wallet_service/wallet.go
View file @
34e8c7c5
...
@@ -10,9 +10,9 @@ type Wallet struct {
...
@@ -10,9 +10,9 @@ type Wallet struct {
Name
string
Name
string
DownloadUrl
string
DownloadUrl
string
Introduce
string
Introduce
string
ChainId
int
//
ChainId int
IssueCharge
float32
//
IssueCharge float32
ChargeUnit
string
//
ChargeUnit string
PageNum
int
PageNum
int
PageSize
int
PageSize
int
...
@@ -44,9 +44,9 @@ func (w *Wallet) Add() error {
...
@@ -44,9 +44,9 @@ func (w *Wallet) Add() error {
"name"
:
w
.
Name
,
"name"
:
w
.
Name
,
"download_url"
:
w
.
DownloadUrl
,
"download_url"
:
w
.
DownloadUrl
,
"introduce"
:
w
.
Introduce
,
"introduce"
:
w
.
Introduce
,
"chain_id"
:
w
.
ChainId
,
//
"chain_id": w.ChainId,
"charge_unit"
:
w
.
ChargeUnit
,
//
"charge_unit": w.ChargeUnit,
"issue_charge"
:
w
.
IssueCharge
,
//
"issue_charge": w.IssueCharge,
}
}
if
err
:=
models
.
AddWallet
(
wallet
);
err
!=
nil
{
if
err
:=
models
.
AddWallet
(
wallet
);
err
!=
nil
{
...
@@ -61,9 +61,9 @@ func (w *Wallet) Edit() error {
...
@@ -61,9 +61,9 @@ func (w *Wallet) Edit() error {
"name"
:
w
.
Name
,
"name"
:
w
.
Name
,
"download_url"
:
w
.
DownloadUrl
,
"download_url"
:
w
.
DownloadUrl
,
"introduce"
:
w
.
Introduce
,
"introduce"
:
w
.
Introduce
,
"chain_id"
:
w
.
ChainId
,
//
"chain_id": w.ChainId,
"issue_charge"
:
w
.
IssueCharge
,
//
"issue_charge": w.IssueCharge,
"charge_unit"
:
w
.
ChargeUnit
,
//
"charge_unit": w.ChargeUnit,
})
})
}
}
...
...
validate_service/platform_chain.go
0 → 100644
View file @
34e8c7c5
package
validate_service
type
PlatformChain
struct
{
ChainId
int
`json:"chain_id" validate:"required"`
PlatformId
int
`json:"platform_id" validate:"required"`
}
type
EditPlatformChain
struct
{
Id
int
`json:"id" validate:"required"`
}
validate_service/wallet.go
View file @
34e8c7c5
...
@@ -4,9 +4,9 @@ type Wallet struct {
...
@@ -4,9 +4,9 @@ type Wallet struct {
Name
string
`json:"name" validate:"required"`
Name
string
`json:"name" validate:"required"`
DownloadUrl
string
`json:"download_url" validate:"required,url"`
DownloadUrl
string
`json:"download_url" validate:"required,url"`
Introduce
string
`json:"introduce" validate:"required"`
Introduce
string
`json:"introduce" validate:"required"`
ChainId
int
`json:"chain_id" validate:"required"`
//
ChainId int `json:"chain_id" validate:"required"`
IssueCharge
float32
`json:"issue_charge" validate:"required"`
//
IssueCharge float32 `json:"issue_charge" validate:"required"`
ChargeUnit
string
`json:"charge_unit" validate:"required"`
//
ChargeUnit string `json:"charge_unit" validate:"required"`
}
}
type
EditWallet
struct
{
type
EditWallet
struct
{
...
...
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