Commit 4875a477 authored by sanghg's avatar sanghg Committed by vipwzw

修复隐私合约中golint的警告

修改commands、autotest中的golint警告
parent e4481593
......@@ -10,7 +10,7 @@ import (
"github.com/33cn/chain33/cmd/autotest/types"
)
//pub2priv case
//CreateUtxosCase pub2priv case
type CreateUtxosCase struct {
types.BaseCase
From string `toml:"from"`
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package autotest
import (
"strconv"
. "github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
//pub2priv case
//PrivToPrivCase pub2priv case
type PrivToPrivCase struct {
BaseCase
types.BaseCase
From string `toml:"from"`
To string `toml:"to"`
Amount string `toml:"amount"`
}
// PrivToPrivPack privacy to privacy package
type PrivToPrivPack struct {
BaseCasePack
types.BaseCasePack
}
func (testCase *PrivToPrivCase) SendCommand(packID string) (PackFunc, error) {
// SendCommand send command
func (testCase *PrivToPrivCase) SendCommand(packID string) (types.PackFunc, error) {
return DefaultSend(testCase, &PrivToPrivPack{}, packID)
return types.DefaultSend(testCase, &PrivToPrivPack{}, packID)
}
// GetCheckHandlerMap get check handler map
func (pack *PrivToPrivPack) GetCheckHandlerMap() interface{} {
funcMap := make(CheckHandlerMapDiscard, 2)
funcMap := make(types.CheckHandlerMapDiscard, 2)
funcMap["utxo"] = pack.checkUtxo
return funcMap
}
......@@ -42,16 +46,16 @@ func (pack *PrivToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
amount, _ := strconv.ParseFloat(interCase.Amount, 64)
fee, _ := strconv.ParseFloat(txInfo["tx"].(map[string]interface{})["fee"].(string), 64)
utxoInput := CalcTxUtxoAmount(inputLog, "keyinput")
utxoOutput := CalcTxUtxoAmount(outputLog, "keyoutput")
utxoInput := types.CalcTxUtxoAmount(inputLog, "keyinput")
utxoOutput := types.CalcTxUtxoAmount(outputLog, "keyoutput")
fromAvail, err1 := CalcUtxoAvailAmount(interCase.From, pack.TxHash)
fromSpend, err2 := CalcUtxoSpendAmount(interCase.From, pack.TxHash)
toAvail, err3 := CalcUtxoAvailAmount(interCase.To, pack.TxHash)
fromAvail, err1 := types.CalcUtxoAvailAmount(interCase.From, pack.TxHash)
fromSpend, err2 := types.CalcUtxoSpendAmount(interCase.From, pack.TxHash)
toAvail, err3 := types.CalcUtxoAvailAmount(interCase.To, pack.TxHash)
utxoCheck := IsBalanceEqualFloat(fromAvail, utxoInput-amount-fee) &&
IsBalanceEqualFloat(toAvail, amount) &&
IsBalanceEqualFloat(fromSpend, utxoInput)
utxoCheck := types.IsBalanceEqualFloat(fromAvail, utxoInput-amount-fee) &&
types.IsBalanceEqualFloat(toAvail, amount) &&
types.IsBalanceEqualFloat(fromSpend, utxoInput)
pack.FLog.Info("Private2PrivateUtxoDetail", "TestID", pack.PackID,
"FromAddr", interCase.From, "ToAddr", interCase.To, "Fee", fee,
......@@ -59,5 +63,5 @@ func (pack *PrivToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
"FromAvailable", fromAvail, "FromSpend", fromSpend, "ToAvailable", toAvail,
"CalcFromAvailErr", err1, "CalcFromSpendErr", err2, "CalcToAvailErr", err3)
return IsBalanceEqualFloat(fee, utxoInput-utxoOutput) && utxoCheck
return types.IsBalanceEqualFloat(fee, utxoInput-utxoOutput) && utxoCheck
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package autotest
import (
"strconv"
. "github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
//pub2priv case
//PrivToPubCase pub2priv case
type PrivToPubCase struct {
BaseCase
types.BaseCase
From string `toml:"from"`
To string `toml:"to"`
Amount string `toml:"amount"`
}
// PrivToPubPack privacy to public package
type PrivToPubPack struct {
BaseCasePack
types.BaseCasePack
}
func (testCase *PrivToPubCase) SendCommand(packID string) (PackFunc, error) {
// SendCommand send command
func (testCase *PrivToPubCase) SendCommand(packID string) (types.PackFunc, error) {
return DefaultSend(testCase, &PrivToPubPack{}, packID)
return types.DefaultSend(testCase, &PrivToPubPack{}, packID)
}
// GetCheckHandlerMap get check handler map
func (pack *PrivToPubPack) GetCheckHandlerMap() interface{} {
funcMap := make(CheckHandlerMapDiscard, 2)
funcMap := make(types.CheckHandlerMapDiscard, 2)
funcMap["balance"] = pack.checkBalance
funcMap["utxo"] = pack.checkUtxo
return funcMap
......@@ -52,8 +56,8 @@ func (pack *PrivToPubPack) checkBalance(txInfo map[string]interface{}) bool {
"ToPrev", logPub["prev"].(map[string]interface{})["balance"].(string),
"ToCurr", logPub["current"].(map[string]interface{})["balance"].(string))
return CheckBalanceDeltaWithAddr(logFee, from, -fee) &&
CheckBalanceDeltaWithAddr(logPub, interCase.To, amount)
return types.CheckBalanceDeltaWithAddr(logFee, from, -fee) &&
types.CheckBalanceDeltaWithAddr(logPub, interCase.To, amount)
}
func (pack *PrivToPubPack) checkUtxo(txInfo map[string]interface{}) bool {
......@@ -65,19 +69,19 @@ func (pack *PrivToPubPack) checkUtxo(txInfo map[string]interface{}) bool {
amount, _ := strconv.ParseFloat(interCase.Amount, 64)
fee, _ := strconv.ParseFloat(txInfo["tx"].(map[string]interface{})["fee"].(string), 64)
utxoInput := CalcTxUtxoAmount(inputLog, "keyinput")
utxoOutput := CalcTxUtxoAmount(outputLog, "keyoutput")
utxoInput := types.CalcTxUtxoAmount(inputLog, "keyinput")
utxoOutput := types.CalcTxUtxoAmount(outputLog, "keyoutput")
//get available utxo with addr
availUtxo, err1 := CalcUtxoAvailAmount(interCase.From, pack.TxHash)
availUtxo, err1 := types.CalcUtxoAvailAmount(interCase.From, pack.TxHash)
//get spend utxo with addr
spendUtxo, err2 := CalcUtxoSpendAmount(interCase.From, pack.TxHash)
spendUtxo, err2 := types.CalcUtxoSpendAmount(interCase.From, pack.TxHash)
utxoCheck := IsBalanceEqualFloat(availUtxo, utxoOutput) && IsBalanceEqualFloat(spendUtxo, utxoInput)
utxoCheck := types.IsBalanceEqualFloat(availUtxo, utxoOutput) && types.IsBalanceEqualFloat(spendUtxo, utxoInput)
pack.FLog.Info("Private2PubUtxoDetail", "TestID", pack.PackID, "Fee", fee,
"TransferAmount", interCase.Amount, "UtxoInput", utxoInput, "UtxoOutput", utxoOutput,
"FromAddr", interCase.From, "UtxoAvailable", availUtxo, "UtxoSpend", spendUtxo,
"CalcAvailErr", err1, "CalcSpendErr", err2)
return IsBalanceEqualFloat(amount, utxoInput-utxoOutput-fee) && utxoCheck
return types.IsBalanceEqualFloat(amount, utxoInput-utxoOutput-fee) && utxoCheck
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package autotest
import (
"reflect"
. "github.com/33cn/chain33/cmd/autotest/types"
. "github.com/33cn/chain33/system/dapp/coins/autotest"
. "github.com/33cn/plugin/plugin/dapp/token/autotest"
"github.com/33cn/chain33/cmd/autotest/types"
ca "github.com/33cn/chain33/system/dapp/coins/autotest"
ta "github.com/33cn/plugin/plugin/dapp/token/autotest"
)
type privacyAutoTest struct {
SimpleCaseArr []SimpleCase `toml:"SimpleCase,omitempty"`
TokenPreCreateCaseArr []TokenPreCreateCase `toml:"TokenPreCreateCase,omitempty"`
TokenFinishCreateCaseArr []TokenFinishCreateCase `toml:"TokenFinishCreateCase,omitempty"`
TransferCaseArr []TransferCase `toml:"TransferCase,omitempty"`
PubToPrivCaseArr []PubToPrivCase `toml:"PubToPrivCase,omitempty"`
PrivToPrivCaseArr []PrivToPrivCase `toml:"PrivToPrivCase,omitempty"`
PrivToPubCaseArr []PrivToPubCase `toml:"PrivToPubCase,omitempty"`
CreateUtxosCaseArr []CreateUtxosCase `toml:"CreateUtxosCase,omitempty"`
SimpleCaseArr []types.SimpleCase `toml:"SimpleCase,omitempty"`
TokenPreCreateCaseArr []ta.TokenPreCreateCase `toml:"TokenPreCreateCase,omitempty"`
TokenFinishCreateCaseArr []ta.TokenFinishCreateCase `toml:"TokenFinishCreateCase,omitempty"`
TransferCaseArr []ca.TransferCase `toml:"TransferCase,omitempty"`
PubToPrivCaseArr []PubToPrivCase `toml:"PubToPrivCase,omitempty"`
PrivToPrivCaseArr []PrivToPrivCase `toml:"PrivToPrivCase,omitempty"`
PrivToPubCaseArr []PrivToPubCase `toml:"PrivToPubCase,omitempty"`
CreateUtxosCaseArr []CreateUtxosCase `toml:"CreateUtxosCase,omitempty"`
}
func init() {
RegisterAutoTest(privacyAutoTest{})
types.RegisterAutoTest(privacyAutoTest{})
}
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package autotest
import (
"strconv"
. "github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
//PubToPrivCase pub2priv case
type PubToPrivCase struct {
BaseCase
types.BaseCase
From string `toml:"from"`
To string `toml:"to"`
Amount string `toml:"amount"`
......@@ -19,19 +20,19 @@ type PubToPrivCase struct {
// PubToPrivPack public to privacy package
type PubToPrivPack struct {
BaseCasePack
types.BaseCasePack
}
// SendCommand send command
func (testCase *PubToPrivCase) SendCommand(packID string) (PackFunc, error) {
func (testCase *PubToPrivCase) SendCommand(packID string) (types.PackFunc, error) {
return DefaultSend(testCase, &PubToPrivPack{}, packID)
return types.DefaultSend(testCase, &PubToPrivPack{}, packID)
}
// GetCheckHandlerMap get check handler map
func (pack *PubToPrivPack) GetCheckHandlerMap() interface{} {
funcMap := make(CheckHandlerMapDiscard, 2)
funcMap := make(types.CheckHandlerMapDiscard, 2)
funcMap["balance"] = pack.checkBalance
funcMap["utxo"] = pack.checkUtxo
return funcMap
......@@ -53,8 +54,8 @@ func (pack *PubToPrivPack) checkBalance(txInfo map[string]interface{}) bool {
"FromPrev", logSend["prev"].(map[string]interface{})["balance"].(string),
"FromCurr", logSend["current"].(map[string]interface{})["balance"].(string))
return CheckBalanceDeltaWithAddr(logFee, interCase.From, -fee) &&
CheckBalanceDeltaWithAddr(logSend, interCase.From, -amount)
return types.CheckBalanceDeltaWithAddr(logFee, interCase.From, -fee) &&
types.CheckBalanceDeltaWithAddr(logSend, interCase.From, -amount)
}
func (pack *PubToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
......@@ -65,14 +66,14 @@ func (pack *PubToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
amount, _ := strconv.ParseFloat(interCase.Amount, 64)
//get available utxo with addr
availUtxo, err := CalcUtxoAvailAmount(interCase.To, pack.TxHash)
totalOutput := CalcTxUtxoAmount(outputLog, "keyoutput")
availCheck := IsBalanceEqualFloat(availUtxo, amount)
availUtxo, err := types.CalcUtxoAvailAmount(interCase.To, pack.TxHash)
totalOutput := types.CalcTxUtxoAmount(outputLog, "keyoutput")
availCheck := types.IsBalanceEqualFloat(availUtxo, amount)
pack.FLog.Info("Pub2PrivateUtxoDetail", "TestID", pack.PackID,
"TransferAmount", interCase.Amount, "UtxoOutput", totalOutput,
"ToAddr", interCase.To, "UtxoAvailable", availUtxo, "CalcAvailErr", err)
return availCheck && IsBalanceEqualFloat(totalOutput, amount)
return availCheck && types.IsBalanceEqualFloat(totalOutput, amount)
}
......@@ -24,6 +24,7 @@ var (
defMixCount int32 = 16
)
// PrivacyCmd 添加隐私交易的命令
func PrivacyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "privacy",
......@@ -32,25 +33,25 @@ func PrivacyCmd() *cobra.Command {
}
cmd.AddCommand(
ShowPrivacyKeyCmd(),
ShowPrivacyAccountSpendCmd(),
Public2PrivacyCmd(),
Privacy2PrivacyCmd(),
Privacy2PublicCmd(),
ShowAmountsOfUTXOCmd(),
ShowUTXOs4SpecifiedAmountCmd(),
CreateUTXOsCmd(),
ShowPrivacyAccountInfoCmd(),
ListPrivacyTxsCmd(),
RescanUtxosOptCmd(),
EnablePrivacyCmd(),
showPrivacyKeyCmd(),
showPrivacyAccountSpendCmd(),
public2PrivacyCmd(),
privacy2PrivacyCmd(),
privacy2PublicCmd(),
showAmountsOfUTXOCmd(),
showUTXOs4SpecifiedAmountCmd(),
createUTXOsCmd(),
showPrivacyAccountInfoCmd(),
listPrivacyTxsCmd(),
rescanUtxosOptCmd(),
enablePrivacyCmd(),
)
return cmd
}
// ShowPrivacyKeyCmd show privacy key by address
func ShowPrivacyKeyCmd() *cobra.Command {
// showPrivacyKeyCmd show privacy key by address
func showPrivacyKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showpk",
Short: "Show privacy key by address",
......@@ -77,8 +78,8 @@ func showPrivacyKey(cmd *cobra.Command, args []string) {
ctx.Run()
}
// Public2PrivacyCmd public address to privacy address
func Public2PrivacyCmd() *cobra.Command {
// public2PrivacyCmd public address to privacy address
func public2PrivacyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pub2priv",
Short: "Public to privacy from pubkeypair amout note",
......@@ -142,7 +143,7 @@ func public2Privacy(cmd *cobra.Command, args []string) {
}
// privacy address to privacy address
func Privacy2PrivacyCmd() *cobra.Command {
func privacy2PrivacyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "priv2priv",
Short: "Privacy to privacy from toviewpubkey tospendpubkey amout note",
......@@ -208,7 +209,7 @@ func privacy2Privacy(cmd *cobra.Command, args []string) {
}
// privacy address to public address
func Privacy2PublicCmd() *cobra.Command {
func privacy2PublicCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "priv2pub",
Short: "Public to privacy from toviewpubkey tospendpubkey amout note",
......@@ -274,7 +275,7 @@ func privacy2Public(cmd *cobra.Command, args []string) {
ctx.Run()
}
func ShowPrivacyAccountSpendCmd() *cobra.Command {
func showPrivacyAccountSpendCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showpas",
Short: "Show privacy account spend command",
......@@ -346,7 +347,7 @@ func parseShowPrivacyAccountSpendRes(arg interface{}) (interface{}, error) {
return rets, nil
}
func ShowAmountsOfUTXOCmd() *cobra.Command {
func showAmountsOfUTXOCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showau",
Short: "Show Amount of UTXO",
......@@ -382,7 +383,7 @@ func parseShowAmountOfUTXORes(arg interface{}) (interface{}, error) {
return res, nil
}
func ShowUTXOs4SpecifiedAmountCmd() *cobra.Command {
func showUTXOs4SpecifiedAmountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showutxo4a",
Short: "Show specified amount UTXOs",
......@@ -432,7 +433,7 @@ func parseShowUTXOs4SpecifiedAmountRes(arg interface{}) (interface{}, error) {
return ret, nil
}
func CreateUTXOsCmd() *cobra.Command {
func createUTXOsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "createutxos",
Short: "Create specified count UTXOs with specified amount",
......@@ -482,8 +483,8 @@ func createUTXOs(cmd *cobra.Command, args []string) {
ctx.Run()
}
// ShowPrivacyAccountInfoCmd
func ShowPrivacyAccountInfoCmd() *cobra.Command {
// showPrivacyAccountInfoCmd
func showPrivacyAccountInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showpai",
Short: "Show privacy account information",
......@@ -573,7 +574,7 @@ func parseshowPrivacyAccountInfo(arg interface{}) (interface{}, error) {
return ret, nil
}
func ListPrivacyTxsCmd() *cobra.Command {
func listPrivacyTxsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list_txs",
Short: "List privacy transactions in wallet",
......@@ -637,24 +638,24 @@ func parseWalletTxListRes(arg interface{}) (interface{}, error) {
return result, nil
}
func RescanUtxosOptCmd() *cobra.Command {
func rescanUtxosOptCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "rescanOpt",
Short: "rescan Utxos in wallet and query rescan utxos status",
Run: RescanUtxosOpt,
Run: rescanUtxosOpt,
}
RescanUtxosOptFlags(cmd)
rescanUtxosOptFlags(cmd)
return cmd
}
func RescanUtxosOptFlags(cmd *cobra.Command) {
func rescanUtxosOptFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "privacy rescanOpt -a [all-addr0-addr1] (all indicate all wallet address)")
cmd.MarkFlagRequired("addr")
//
cmd.Flags().Int32P("flag", "f", 0, "Rescan or query rescan flag (0: Rescan, 1: query rescan)")
}
func RescanUtxosOpt(cmd *cobra.Command, args []string) {
func rescanUtxosOpt(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
address, _ := cmd.Flags().GetString("addr")
flag, _ := cmd.Flags().GetInt32("flag")
......@@ -677,41 +678,41 @@ func RescanUtxosOpt(cmd *cobra.Command, args []string) {
func parseRescanUtxosOpt(arg interface{}) (interface{}, error) {
res := arg.(*pty.RepRescanUtxos)
var result showRescanResults
if 0 == res.Flag {
str := "start rescan UTXO"
return str, nil
} else {
for _, v := range res.RepRescanResults {
str, ok := pty.RescanFlagMapint2string[v.Flag]
if ok {
showRescanResult := &ShowRescanResult{
Addr: v.Addr,
FlagString: str,
}
result.RescanResults = append(result.RescanResults, showRescanResult)
}
var result showRescanResults
for _, v := range res.RepRescanResults {
str, ok := pty.RescanFlagMapint2string[v.Flag]
if ok {
showRescanResult := &ShowRescanResult{
Addr: v.Addr,
FlagString: str,
}
result.RescanResults = append(result.RescanResults, showRescanResult)
}
return &result, nil
}
return &result, nil
}
func EnablePrivacyCmd() *cobra.Command {
func enablePrivacyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "enable",
Short: "enable privacy address in wallet",
Run: EnablePrivacy,
Run: enablePrivacy,
}
EnablePrivacyFlags(cmd)
enablePrivacyFlags(cmd)
return cmd
}
func EnablePrivacyFlags(cmd *cobra.Command) {
func enablePrivacyFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "privacy enable -a [all-addr0-addr1] (all indicate enable all wallet address)")
cmd.MarkFlagRequired("addr")
}
func EnablePrivacy(cmd *cobra.Command, args []string) {
func enablePrivacy(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
address, _ := cmd.Flags().GetString("addr")
......@@ -725,7 +726,7 @@ func EnablePrivacy(cmd *cobra.Command, args []string) {
}
var res pty.RepEnablePrivacy
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.EnablePrivacy", params, &res)
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.enablePrivacy", params, &res)
ctx.SetResultCb(parseEnablePrivacy)
ctx.Run()
}
......
......@@ -4,6 +4,7 @@
package commands
// PrivacyAccountResult display privacy account result
type PrivacyAccountResult struct {
Token string `json:"Token,omitempty"`
Txhash string `json:"Txhash,omitempty"`
......@@ -12,6 +13,7 @@ type PrivacyAccountResult struct {
OnetimePubKey string `json:"OnetimePubKey,omitempty"`
}
// PrivacyAccountInfoResult display privacy account information result
type PrivacyAccountInfoResult struct {
AvailableDetail []*PrivacyAccountResult `json:"AvailableDetail,omitempty"`
FrozenDetail []*PrivacyAccountResult `json:"FrozenDetail,omitempty"`
......@@ -20,11 +22,13 @@ type PrivacyAccountInfoResult struct {
TotalAmount string `json:"TotalAmount,omitempty"`
}
// PrivacyAccountSpendResult display privacy account spend result
type PrivacyAccountSpendResult struct {
Txhash string `json:"Txhash,omitempty"`
Res []*PrivacyAccountResult `json:"Spend,omitempty"`
}
// ShowRescanResult display rescan utxos result
type ShowRescanResult struct {
Addr string `json:"addr"`
FlagString string `json:"FlagString"`
......@@ -34,10 +38,12 @@ type showRescanResults struct {
RescanResults []*ShowRescanResult `json:"ShowRescanResults,omitempty"`
}
// ShowEnablePrivacy display enable privacy
type ShowEnablePrivacy struct {
Results []*ShowPriAddrResult `json:"results"`
}
// ShowPriAddrResult display privacy address result
type ShowPriAddrResult struct {
Addr string `json:"addr"`
IsOK bool `json:"IsOK"`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment