You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.0 KiB
93 lines
2.0 KiB
2 months ago
|
package validation
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
|
||
|
v1 "wallet-system/api/walletSystem/v1"
|
||
|
)
|
||
|
|
||
|
var ps = fmt.Sprintf
|
||
|
var parameterV = "Parameter verification error."
|
||
|
var Success = "success"
|
||
|
|
||
|
// GenerateAddressValidation 验证生成钱包地址参数
|
||
|
func GenerateAddressValidation(in *v1.GenerateAddressRequest) error {
|
||
|
if len(in.Wallet) <= 0 {
|
||
|
return errors.New(ps("wallet err=%v", parameterV))
|
||
|
}
|
||
|
if in.Number <= 0 {
|
||
|
return errors.New(ps("number err=%v", parameterV))
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// SignatureTrc20GrpcValidation 验证签名参数
|
||
|
func SignatureTrc20GrpcValidation(in *v1.SignatureTrc20Request) error {
|
||
|
if len(in.From) <= 0 {
|
||
|
return errors.New(ps("from err=%v", parameterV))
|
||
|
}
|
||
|
if len(in.To) <= 0 {
|
||
|
return errors.New(ps("to err=%v", parameterV))
|
||
|
}
|
||
|
if in.Amount <= 0 {
|
||
|
return errors.New(ps("amount err=%v", parameterV))
|
||
|
}
|
||
|
if in.FeeLimit <= 0 {
|
||
|
return errors.New(ps("fee_limit err=%v", parameterV))
|
||
|
}
|
||
|
|
||
|
switch in.TrcCheck {
|
||
|
case "Trx":
|
||
|
return nil
|
||
|
case "Trc20":
|
||
|
if len(in.Contract) <= 0 {
|
||
|
return errors.New(ps("contract err=%v", parameterV))
|
||
|
}
|
||
|
default:
|
||
|
return errors.New(ps("trc_check err=%v", parameterV))
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// GetPrivateKeyByAddressValidation 验证钱包地址参数
|
||
|
func GetPrivateKeyByAddressValidation(in *v1.GetPrivateKeyByAddressRequest) error {
|
||
|
if len(in.Address) <= 0 {
|
||
|
return errors.New(ps("address err=%v", parameterV))
|
||
|
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// WalletApproveValidation 验证签名参数
|
||
|
func WalletApproveValidation(in *v1.WalletApproveRequest) error {
|
||
|
if len(in.From) <= 0 {
|
||
|
return errors.New(ps("from err=%v", parameterV))
|
||
|
}
|
||
|
if len(in.To) <= 0 {
|
||
|
return errors.New(ps("to err=%v", parameterV))
|
||
|
}
|
||
|
if in.Amount <= 0 {
|
||
|
return errors.New(ps("amount err=%v", parameterV))
|
||
|
}
|
||
|
if in.FeeLimit <= 0 {
|
||
|
return errors.New(ps("fee_limit err=%v", parameterV))
|
||
|
}
|
||
|
|
||
|
switch in.TrcCheck {
|
||
|
case "Trx":
|
||
|
return nil
|
||
|
case "Trc20":
|
||
|
if len(in.Contract) <= 0 {
|
||
|
return errors.New(ps("contract err=%v", parameterV))
|
||
|
}
|
||
|
default:
|
||
|
return errors.New(ps("trc_check err=%v", parameterV))
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|