Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
4875a477
Commit
4875a477
authored
Nov 20, 2018
by
sanghg
Committed by
vipwzw
Nov 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复隐私合约中golint的警告
修改commands、autotest中的golint警告
parent
e4481593
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
103 deletions
+120
-103
createutxosCase.go
plugin/dapp/privacy/autotest/createutxosCase.go
+1
-1
privToPrivCase.go
plugin/dapp/privacy/autotest/privToPrivCase.go
+20
-16
privToPubCase.go
plugin/dapp/privacy/autotest/privToPubCase.go
+19
-15
privacy.go
plugin/dapp/privacy/autotest/privacy.go
+13
-12
pubToPriv.go
plugin/dapp/privacy/autotest/pubToPriv.go
+13
-12
privacy.go
plugin/dapp/privacy/commands/privacy.go
+48
-47
types.go
plugin/dapp/privacy/commands/types.go
+6
-0
No files found.
plugin/dapp/privacy/autotest/createutxosCase.go
View file @
4875a477
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
"github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
)
//pub2priv case
//
CreateUtxosCase
pub2priv case
type
CreateUtxosCase
struct
{
type
CreateUtxosCase
struct
{
types
.
BaseCase
types
.
BaseCase
From
string
`toml:"from"`
From
string
`toml:"from"`
...
...
plugin/dapp/privacy/autotest/privToPrivCase.go
View file @
4875a477
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
autotest
package
autotest
import
(
import
(
"strconv"
"strconv"
.
"github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
)
//pub2priv case
//
PrivToPrivCase
pub2priv case
type
PrivToPrivCase
struct
{
type
PrivToPrivCase
struct
{
BaseCase
types
.
BaseCase
From
string
`toml:"from"`
From
string
`toml:"from"`
To
string
`toml:"to"`
To
string
`toml:"to"`
Amount
string
`toml:"amount"`
Amount
string
`toml:"amount"`
}
}
// PrivToPrivPack privacy to privacy package
type
PrivToPrivPack
struct
{
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
{}
{
func
(
pack
*
PrivToPrivPack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
CheckHandlerMapDiscard
,
2
)
funcMap
:=
make
(
types
.
CheckHandlerMapDiscard
,
2
)
funcMap
[
"utxo"
]
=
pack
.
checkUtxo
funcMap
[
"utxo"
]
=
pack
.
checkUtxo
return
funcMap
return
funcMap
}
}
...
@@ -42,16 +46,16 @@ func (pack *PrivToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
...
@@ -42,16 +46,16 @@ func (pack *PrivToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
amount
,
_
:=
strconv
.
ParseFloat
(
interCase
.
Amount
,
64
)
amount
,
_
:=
strconv
.
ParseFloat
(
interCase
.
Amount
,
64
)
fee
,
_
:=
strconv
.
ParseFloat
(
txInfo
[
"tx"
]
.
(
map
[
string
]
interface
{})[
"fee"
]
.
(
string
),
64
)
fee
,
_
:=
strconv
.
ParseFloat
(
txInfo
[
"tx"
]
.
(
map
[
string
]
interface
{})[
"fee"
]
.
(
string
),
64
)
utxoInput
:=
CalcTxUtxoAmount
(
inputLog
,
"keyinput"
)
utxoInput
:=
types
.
CalcTxUtxoAmount
(
inputLog
,
"keyinput"
)
utxoOutput
:=
CalcTxUtxoAmount
(
outputLog
,
"keyoutput"
)
utxoOutput
:=
types
.
CalcTxUtxoAmount
(
outputLog
,
"keyoutput"
)
fromAvail
,
err1
:=
CalcUtxoAvailAmount
(
interCase
.
From
,
pack
.
TxHash
)
fromAvail
,
err1
:=
types
.
CalcUtxoAvailAmount
(
interCase
.
From
,
pack
.
TxHash
)
fromSpend
,
err2
:=
CalcUtxoSpendAmount
(
interCase
.
From
,
pack
.
TxHash
)
fromSpend
,
err2
:=
types
.
CalcUtxoSpendAmount
(
interCase
.
From
,
pack
.
TxHash
)
toAvail
,
err3
:=
CalcUtxoAvailAmount
(
interCase
.
To
,
pack
.
TxHash
)
toAvail
,
err3
:=
types
.
CalcUtxoAvailAmount
(
interCase
.
To
,
pack
.
TxHash
)
utxoCheck
:=
IsBalanceEqualFloat
(
fromAvail
,
utxoInput
-
amount
-
fee
)
&&
utxoCheck
:=
types
.
IsBalanceEqualFloat
(
fromAvail
,
utxoInput
-
amount
-
fee
)
&&
IsBalanceEqualFloat
(
toAvail
,
amount
)
&&
types
.
IsBalanceEqualFloat
(
toAvail
,
amount
)
&&
IsBalanceEqualFloat
(
fromSpend
,
utxoInput
)
types
.
IsBalanceEqualFloat
(
fromSpend
,
utxoInput
)
pack
.
FLog
.
Info
(
"Private2PrivateUtxoDetail"
,
"TestID"
,
pack
.
PackID
,
pack
.
FLog
.
Info
(
"Private2PrivateUtxoDetail"
,
"TestID"
,
pack
.
PackID
,
"FromAddr"
,
interCase
.
From
,
"ToAddr"
,
interCase
.
To
,
"Fee"
,
fee
,
"FromAddr"
,
interCase
.
From
,
"ToAddr"
,
interCase
.
To
,
"Fee"
,
fee
,
...
@@ -59,5 +63,5 @@ func (pack *PrivToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
...
@@ -59,5 +63,5 @@ func (pack *PrivToPrivPack) checkUtxo(txInfo map[string]interface{}) bool {
"FromAvailable"
,
fromAvail
,
"FromSpend"
,
fromSpend
,
"ToAvailable"
,
toAvail
,
"FromAvailable"
,
fromAvail
,
"FromSpend"
,
fromSpend
,
"ToAvailable"
,
toAvail
,
"CalcFromAvailErr"
,
err1
,
"CalcFromSpendErr"
,
err2
,
"CalcToAvailErr"
,
err3
)
"CalcFromAvailErr"
,
err1
,
"CalcFromSpendErr"
,
err2
,
"CalcToAvailErr"
,
err3
)
return
IsBalanceEqualFloat
(
fee
,
utxoInput
-
utxoOutput
)
&&
utxoCheck
return
types
.
IsBalanceEqualFloat
(
fee
,
utxoInput
-
utxoOutput
)
&&
utxoCheck
}
}
plugin/dapp/privacy/autotest/privToPubCase.go
View file @
4875a477
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
autotest
package
autotest
import
(
import
(
"strconv"
"strconv"
.
"github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
)
//pub2priv case
//
PrivToPubCase
pub2priv case
type
PrivToPubCase
struct
{
type
PrivToPubCase
struct
{
BaseCase
types
.
BaseCase
From
string
`toml:"from"`
From
string
`toml:"from"`
To
string
`toml:"to"`
To
string
`toml:"to"`
Amount
string
`toml:"amount"`
Amount
string
`toml:"amount"`
}
}
// PrivToPubPack privacy to public package
type
PrivToPubPack
struct
{
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
{}
{
func
(
pack
*
PrivToPubPack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
CheckHandlerMapDiscard
,
2
)
funcMap
:=
make
(
types
.
CheckHandlerMapDiscard
,
2
)
funcMap
[
"balance"
]
=
pack
.
checkBalance
funcMap
[
"balance"
]
=
pack
.
checkBalance
funcMap
[
"utxo"
]
=
pack
.
checkUtxo
funcMap
[
"utxo"
]
=
pack
.
checkUtxo
return
funcMap
return
funcMap
...
@@ -52,8 +56,8 @@ func (pack *PrivToPubPack) checkBalance(txInfo map[string]interface{}) bool {
...
@@ -52,8 +56,8 @@ func (pack *PrivToPubPack) checkBalance(txInfo map[string]interface{}) bool {
"ToPrev"
,
logPub
[
"prev"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
),
"ToPrev"
,
logPub
[
"prev"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
),
"ToCurr"
,
logPub
[
"current"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
))
"ToCurr"
,
logPub
[
"current"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
))
return
CheckBalanceDeltaWithAddr
(
logFee
,
from
,
-
fee
)
&&
return
types
.
CheckBalanceDeltaWithAddr
(
logFee
,
from
,
-
fee
)
&&
CheckBalanceDeltaWithAddr
(
logPub
,
interCase
.
To
,
amount
)
types
.
CheckBalanceDeltaWithAddr
(
logPub
,
interCase
.
To
,
amount
)
}
}
func
(
pack
*
PrivToPubPack
)
checkUtxo
(
txInfo
map
[
string
]
interface
{})
bool
{
func
(
pack
*
PrivToPubPack
)
checkUtxo
(
txInfo
map
[
string
]
interface
{})
bool
{
...
@@ -65,19 +69,19 @@ 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
)
amount
,
_
:=
strconv
.
ParseFloat
(
interCase
.
Amount
,
64
)
fee
,
_
:=
strconv
.
ParseFloat
(
txInfo
[
"tx"
]
.
(
map
[
string
]
interface
{})[
"fee"
]
.
(
string
),
64
)
fee
,
_
:=
strconv
.
ParseFloat
(
txInfo
[
"tx"
]
.
(
map
[
string
]
interface
{})[
"fee"
]
.
(
string
),
64
)
utxoInput
:=
CalcTxUtxoAmount
(
inputLog
,
"keyinput"
)
utxoInput
:=
types
.
CalcTxUtxoAmount
(
inputLog
,
"keyinput"
)
utxoOutput
:=
CalcTxUtxoAmount
(
outputLog
,
"keyoutput"
)
utxoOutput
:=
types
.
CalcTxUtxoAmount
(
outputLog
,
"keyoutput"
)
//get available utxo with addr
//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
//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
,
pack
.
FLog
.
Info
(
"Private2PubUtxoDetail"
,
"TestID"
,
pack
.
PackID
,
"Fee"
,
fee
,
"TransferAmount"
,
interCase
.
Amount
,
"UtxoInput"
,
utxoInput
,
"UtxoOutput"
,
utxoOutput
,
"TransferAmount"
,
interCase
.
Amount
,
"UtxoInput"
,
utxoInput
,
"UtxoOutput"
,
utxoOutput
,
"FromAddr"
,
interCase
.
From
,
"UtxoAvailable"
,
availUtxo
,
"UtxoSpend"
,
spendUtxo
,
"FromAddr"
,
interCase
.
From
,
"UtxoAvailable"
,
availUtxo
,
"UtxoSpend"
,
spendUtxo
,
"CalcAvailErr"
,
err1
,
"CalcSpendErr"
,
err2
)
"CalcAvailErr"
,
err1
,
"CalcSpendErr"
,
err2
)
return
IsBalanceEqualFloat
(
amount
,
utxoInput
-
utxoOutput
-
fee
)
&&
utxoCheck
return
types
.
IsBalanceEqualFloat
(
amount
,
utxoInput
-
utxoOutput
-
fee
)
&&
utxoCheck
}
}
plugin/dapp/privacy/autotest/privacy.go
View file @
4875a477
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
autotest
package
autotest
import
(
import
(
"reflect"
"reflect"
.
"github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
.
"github.com/33cn/chain33/system/dapp/coins/autotest"
ca
"github.com/33cn/chain33/system/dapp/coins/autotest"
.
"github.com/33cn/plugin/plugin/dapp/token/autotest"
ta
"github.com/33cn/plugin/plugin/dapp/token/autotest"
)
)
type
privacyAutoTest
struct
{
type
privacyAutoTest
struct
{
SimpleCaseArr
[]
SimpleCase
`toml:"SimpleCase,omitempty"`
SimpleCaseArr
[]
types
.
SimpleCase
`toml:"SimpleCase,omitempty"`
TokenPreCreateCaseArr
[]
TokenPreCreateCase
`toml:"TokenPreCreateCase,omitempty"`
TokenPreCreateCaseArr
[]
ta
.
TokenPreCreateCase
`toml:"TokenPreCreateCase,omitempty"`
TokenFinishCreateCaseArr
[]
TokenFinishCreateCase
`toml:"TokenFinishCreateCase,omitempty"`
TokenFinishCreateCaseArr
[]
ta
.
TokenFinishCreateCase
`toml:"TokenFinishCreateCase,omitempty"`
TransferCaseArr
[]
TransferCase
`toml:"TransferCase,omitempty"`
TransferCaseArr
[]
ca
.
TransferCase
`toml:"TransferCase,omitempty"`
PubToPrivCaseArr
[]
PubToPrivCase
`toml:"PubToPrivCase,omitempty"`
PubToPrivCaseArr
[]
PubToPrivCase
`toml:"PubToPrivCase,omitempty"`
PrivToPrivCaseArr
[]
PrivToPrivCase
`toml:"PrivToPrivCase,omitempty"`
PrivToPrivCaseArr
[]
PrivToPrivCase
`toml:"PrivToPrivCase,omitempty"`
PrivToPubCaseArr
[]
PrivToPubCase
`toml:"PrivToPubCase,omitempty"`
PrivToPubCaseArr
[]
PrivToPubCase
`toml:"PrivToPubCase,omitempty"`
CreateUtxosCaseArr
[]
CreateUtxosCase
`toml:"CreateUtxosCase,omitempty"`
CreateUtxosCaseArr
[]
CreateUtxosCase
`toml:"CreateUtxosCase,omitempty"`
}
}
func
init
()
{
func
init
()
{
RegisterAutoTest
(
privacyAutoTest
{})
types
.
RegisterAutoTest
(
privacyAutoTest
{})
}
}
...
...
plugin/dapp/privacy/autotest/pubToPriv.go
View file @
4875a477
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
autotest
package
autotest
import
(
import
(
"strconv"
"strconv"
.
"github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
)
//PubToPrivCase pub2priv case
//PubToPrivCase pub2priv case
type
PubToPrivCase
struct
{
type
PubToPrivCase
struct
{
BaseCase
types
.
BaseCase
From
string
`toml:"from"`
From
string
`toml:"from"`
To
string
`toml:"to"`
To
string
`toml:"to"`
Amount
string
`toml:"amount"`
Amount
string
`toml:"amount"`
...
@@ -19,19 +20,19 @@ type PubToPrivCase struct {
...
@@ -19,19 +20,19 @@ type PubToPrivCase struct {
// PubToPrivPack public to privacy package
// PubToPrivPack public to privacy package
type
PubToPrivPack
struct
{
type
PubToPrivPack
struct
{
BaseCasePack
types
.
BaseCasePack
}
}
// SendCommand send command
// 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
// GetCheckHandlerMap get check handler map
func
(
pack
*
PubToPrivPack
)
GetCheckHandlerMap
()
interface
{}
{
func
(
pack
*
PubToPrivPack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
CheckHandlerMapDiscard
,
2
)
funcMap
:=
make
(
types
.
CheckHandlerMapDiscard
,
2
)
funcMap
[
"balance"
]
=
pack
.
checkBalance
funcMap
[
"balance"
]
=
pack
.
checkBalance
funcMap
[
"utxo"
]
=
pack
.
checkUtxo
funcMap
[
"utxo"
]
=
pack
.
checkUtxo
return
funcMap
return
funcMap
...
@@ -53,8 +54,8 @@ func (pack *PubToPrivPack) checkBalance(txInfo map[string]interface{}) bool {
...
@@ -53,8 +54,8 @@ func (pack *PubToPrivPack) checkBalance(txInfo map[string]interface{}) bool {
"FromPrev"
,
logSend
[
"prev"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
),
"FromPrev"
,
logSend
[
"prev"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
),
"FromCurr"
,
logSend
[
"current"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
))
"FromCurr"
,
logSend
[
"current"
]
.
(
map
[
string
]
interface
{})[
"balance"
]
.
(
string
))
return
CheckBalanceDeltaWithAddr
(
logFee
,
interCase
.
From
,
-
fee
)
&&
return
types
.
CheckBalanceDeltaWithAddr
(
logFee
,
interCase
.
From
,
-
fee
)
&&
CheckBalanceDeltaWithAddr
(
logSend
,
interCase
.
From
,
-
amount
)
types
.
CheckBalanceDeltaWithAddr
(
logSend
,
interCase
.
From
,
-
amount
)
}
}
func
(
pack
*
PubToPrivPack
)
checkUtxo
(
txInfo
map
[
string
]
interface
{})
bool
{
func
(
pack
*
PubToPrivPack
)
checkUtxo
(
txInfo
map
[
string
]
interface
{})
bool
{
...
@@ -65,14 +66,14 @@ 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
)
amount
,
_
:=
strconv
.
ParseFloat
(
interCase
.
Amount
,
64
)
//get available utxo with addr
//get available utxo with addr
availUtxo
,
err
:=
CalcUtxoAvailAmount
(
interCase
.
To
,
pack
.
TxHash
)
availUtxo
,
err
:=
types
.
CalcUtxoAvailAmount
(
interCase
.
To
,
pack
.
TxHash
)
totalOutput
:=
CalcTxUtxoAmount
(
outputLog
,
"keyoutput"
)
totalOutput
:=
types
.
CalcTxUtxoAmount
(
outputLog
,
"keyoutput"
)
availCheck
:=
IsBalanceEqualFloat
(
availUtxo
,
amount
)
availCheck
:=
types
.
IsBalanceEqualFloat
(
availUtxo
,
amount
)
pack
.
FLog
.
Info
(
"Pub2PrivateUtxoDetail"
,
"TestID"
,
pack
.
PackID
,
pack
.
FLog
.
Info
(
"Pub2PrivateUtxoDetail"
,
"TestID"
,
pack
.
PackID
,
"TransferAmount"
,
interCase
.
Amount
,
"UtxoOutput"
,
totalOutput
,
"TransferAmount"
,
interCase
.
Amount
,
"UtxoOutput"
,
totalOutput
,
"ToAddr"
,
interCase
.
To
,
"UtxoAvailable"
,
availUtxo
,
"CalcAvailErr"
,
err
)
"ToAddr"
,
interCase
.
To
,
"UtxoAvailable"
,
availUtxo
,
"CalcAvailErr"
,
err
)
return
availCheck
&&
IsBalanceEqualFloat
(
totalOutput
,
amount
)
return
availCheck
&&
types
.
IsBalanceEqualFloat
(
totalOutput
,
amount
)
}
}
plugin/dapp/privacy/commands/privacy.go
View file @
4875a477
...
@@ -24,6 +24,7 @@ var (
...
@@ -24,6 +24,7 @@ var (
defMixCount
int32
=
16
defMixCount
int32
=
16
)
)
// PrivacyCmd 添加隐私交易的命令
func
PrivacyCmd
()
*
cobra
.
Command
{
func
PrivacyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"privacy"
,
Use
:
"privacy"
,
...
@@ -32,25 +33,25 @@ func PrivacyCmd() *cobra.Command {
...
@@ -32,25 +33,25 @@ func PrivacyCmd() *cobra.Command {
}
}
cmd
.
AddCommand
(
cmd
.
AddCommand
(
S
howPrivacyKeyCmd
(),
s
howPrivacyKeyCmd
(),
S
howPrivacyAccountSpendCmd
(),
s
howPrivacyAccountSpendCmd
(),
P
ublic2PrivacyCmd
(),
p
ublic2PrivacyCmd
(),
P
rivacy2PrivacyCmd
(),
p
rivacy2PrivacyCmd
(),
P
rivacy2PublicCmd
(),
p
rivacy2PublicCmd
(),
S
howAmountsOfUTXOCmd
(),
s
howAmountsOfUTXOCmd
(),
S
howUTXOs4SpecifiedAmountCmd
(),
s
howUTXOs4SpecifiedAmountCmd
(),
C
reateUTXOsCmd
(),
c
reateUTXOsCmd
(),
S
howPrivacyAccountInfoCmd
(),
s
howPrivacyAccountInfoCmd
(),
L
istPrivacyTxsCmd
(),
l
istPrivacyTxsCmd
(),
R
escanUtxosOptCmd
(),
r
escanUtxosOptCmd
(),
E
nablePrivacyCmd
(),
e
nablePrivacyCmd
(),
)
)
return
cmd
return
cmd
}
}
//
S
howPrivacyKeyCmd show privacy key by address
//
s
howPrivacyKeyCmd show privacy key by address
func
S
howPrivacyKeyCmd
()
*
cobra
.
Command
{
func
s
howPrivacyKeyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"showpk"
,
Use
:
"showpk"
,
Short
:
"Show privacy key by address"
,
Short
:
"Show privacy key by address"
,
...
@@ -77,8 +78,8 @@ func showPrivacyKey(cmd *cobra.Command, args []string) {
...
@@ -77,8 +78,8 @@ func showPrivacyKey(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
//
P
ublic2PrivacyCmd public address to privacy address
//
p
ublic2PrivacyCmd public address to privacy address
func
P
ublic2PrivacyCmd
()
*
cobra
.
Command
{
func
p
ublic2PrivacyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"pub2priv"
,
Use
:
"pub2priv"
,
Short
:
"Public to privacy from pubkeypair amout note"
,
Short
:
"Public to privacy from pubkeypair amout note"
,
...
@@ -142,7 +143,7 @@ func public2Privacy(cmd *cobra.Command, args []string) {
...
@@ -142,7 +143,7 @@ func public2Privacy(cmd *cobra.Command, args []string) {
}
}
// privacy address to privacy address
// privacy address to privacy address
func
P
rivacy2PrivacyCmd
()
*
cobra
.
Command
{
func
p
rivacy2PrivacyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"priv2priv"
,
Use
:
"priv2priv"
,
Short
:
"Privacy to privacy from toviewpubkey tospendpubkey amout note"
,
Short
:
"Privacy to privacy from toviewpubkey tospendpubkey amout note"
,
...
@@ -208,7 +209,7 @@ func privacy2Privacy(cmd *cobra.Command, args []string) {
...
@@ -208,7 +209,7 @@ func privacy2Privacy(cmd *cobra.Command, args []string) {
}
}
// privacy address to public address
// privacy address to public address
func
P
rivacy2PublicCmd
()
*
cobra
.
Command
{
func
p
rivacy2PublicCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"priv2pub"
,
Use
:
"priv2pub"
,
Short
:
"Public to privacy from toviewpubkey tospendpubkey amout note"
,
Short
:
"Public to privacy from toviewpubkey tospendpubkey amout note"
,
...
@@ -274,7 +275,7 @@ func privacy2Public(cmd *cobra.Command, args []string) {
...
@@ -274,7 +275,7 @@ func privacy2Public(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
func
S
howPrivacyAccountSpendCmd
()
*
cobra
.
Command
{
func
s
howPrivacyAccountSpendCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"showpas"
,
Use
:
"showpas"
,
Short
:
"Show privacy account spend command"
,
Short
:
"Show privacy account spend command"
,
...
@@ -346,7 +347,7 @@ func parseShowPrivacyAccountSpendRes(arg interface{}) (interface{}, error) {
...
@@ -346,7 +347,7 @@ func parseShowPrivacyAccountSpendRes(arg interface{}) (interface{}, error) {
return
rets
,
nil
return
rets
,
nil
}
}
func
S
howAmountsOfUTXOCmd
()
*
cobra
.
Command
{
func
s
howAmountsOfUTXOCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"showau"
,
Use
:
"showau"
,
Short
:
"Show Amount of UTXO"
,
Short
:
"Show Amount of UTXO"
,
...
@@ -382,7 +383,7 @@ func parseShowAmountOfUTXORes(arg interface{}) (interface{}, error) {
...
@@ -382,7 +383,7 @@ func parseShowAmountOfUTXORes(arg interface{}) (interface{}, error) {
return
res
,
nil
return
res
,
nil
}
}
func
S
howUTXOs4SpecifiedAmountCmd
()
*
cobra
.
Command
{
func
s
howUTXOs4SpecifiedAmountCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"showutxo4a"
,
Use
:
"showutxo4a"
,
Short
:
"Show specified amount UTXOs"
,
Short
:
"Show specified amount UTXOs"
,
...
@@ -432,7 +433,7 @@ func parseShowUTXOs4SpecifiedAmountRes(arg interface{}) (interface{}, error) {
...
@@ -432,7 +433,7 @@ func parseShowUTXOs4SpecifiedAmountRes(arg interface{}) (interface{}, error) {
return
ret
,
nil
return
ret
,
nil
}
}
func
C
reateUTXOsCmd
()
*
cobra
.
Command
{
func
c
reateUTXOsCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"createutxos"
,
Use
:
"createutxos"
,
Short
:
"Create specified count UTXOs with specified amount"
,
Short
:
"Create specified count UTXOs with specified amount"
,
...
@@ -482,8 +483,8 @@ func createUTXOs(cmd *cobra.Command, args []string) {
...
@@ -482,8 +483,8 @@ func createUTXOs(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
//
S
howPrivacyAccountInfoCmd
//
s
howPrivacyAccountInfoCmd
func
S
howPrivacyAccountInfoCmd
()
*
cobra
.
Command
{
func
s
howPrivacyAccountInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"showpai"
,
Use
:
"showpai"
,
Short
:
"Show privacy account information"
,
Short
:
"Show privacy account information"
,
...
@@ -573,7 +574,7 @@ func parseshowPrivacyAccountInfo(arg interface{}) (interface{}, error) {
...
@@ -573,7 +574,7 @@ func parseshowPrivacyAccountInfo(arg interface{}) (interface{}, error) {
return
ret
,
nil
return
ret
,
nil
}
}
func
L
istPrivacyTxsCmd
()
*
cobra
.
Command
{
func
l
istPrivacyTxsCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"list_txs"
,
Use
:
"list_txs"
,
Short
:
"List privacy transactions in wallet"
,
Short
:
"List privacy transactions in wallet"
,
...
@@ -637,24 +638,24 @@ func parseWalletTxListRes(arg interface{}) (interface{}, error) {
...
@@ -637,24 +638,24 @@ func parseWalletTxListRes(arg interface{}) (interface{}, error) {
return
result
,
nil
return
result
,
nil
}
}
func
R
escanUtxosOptCmd
()
*
cobra
.
Command
{
func
r
escanUtxosOptCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"rescanOpt"
,
Use
:
"rescanOpt"
,
Short
:
"rescan Utxos in wallet and query rescan utxos status"
,
Short
:
"rescan Utxos in wallet and query rescan utxos status"
,
Run
:
R
escanUtxosOpt
,
Run
:
r
escanUtxosOpt
,
}
}
R
escanUtxosOptFlags
(
cmd
)
r
escanUtxosOptFlags
(
cmd
)
return
cmd
return
cmd
}
}
func
R
escanUtxosOptFlags
(
cmd
*
cobra
.
Command
)
{
func
r
escanUtxosOptFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"privacy rescanOpt -a [all-addr0-addr1] (all indicate all wallet address)"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"privacy rescanOpt -a [all-addr0-addr1] (all indicate all wallet address)"
)
cmd
.
MarkFlagRequired
(
"addr"
)
cmd
.
MarkFlagRequired
(
"addr"
)
//
//
cmd
.
Flags
()
.
Int32P
(
"flag"
,
"f"
,
0
,
"Rescan or query rescan flag (0: Rescan, 1: query rescan)"
)
cmd
.
Flags
()
.
Int32P
(
"flag"
,
"f"
,
0
,
"Rescan or query rescan flag (0: Rescan, 1: query rescan)"
)
}
}
func
R
escanUtxosOpt
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
r
escanUtxosOpt
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
address
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
address
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
flag
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"flag"
)
flag
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"flag"
)
...
@@ -677,41 +678,41 @@ func RescanUtxosOpt(cmd *cobra.Command, args []string) {
...
@@ -677,41 +678,41 @@ func RescanUtxosOpt(cmd *cobra.Command, args []string) {
func
parseRescanUtxosOpt
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseRescanUtxosOpt
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
RepRescanUtxos
)
res
:=
arg
.
(
*
pty
.
RepRescanUtxos
)
var
result
showRescanResults
if
0
==
res
.
Flag
{
if
0
==
res
.
Flag
{
str
:=
"start rescan UTXO"
str
:=
"start rescan UTXO"
return
str
,
nil
return
str
,
nil
}
else
{
}
for
_
,
v
:=
range
res
.
RepRescanResults
{
str
,
ok
:=
pty
.
RescanFlagMapint2string
[
v
.
Flag
]
var
result
showRescanResults
if
ok
{
for
_
,
v
:=
range
res
.
RepRescanResults
{
showRescanResult
:=
&
ShowRescanResult
{
str
,
ok
:=
pty
.
RescanFlagMapint2string
[
v
.
Flag
]
Addr
:
v
.
Addr
,
if
ok
{
FlagString
:
str
,
showRescanResult
:=
&
ShowRescanResult
{
}
Addr
:
v
.
Addr
,
result
.
RescanResults
=
append
(
result
.
RescanResults
,
showRescanResult
)
FlagString
:
str
,
}
}
result
.
RescanResults
=
append
(
result
.
RescanResults
,
showRescanResult
)
}
}
return
&
result
,
nil
}
}
return
&
result
,
nil
}
}
func
E
nablePrivacyCmd
()
*
cobra
.
Command
{
func
e
nablePrivacyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"enable"
,
Use
:
"enable"
,
Short
:
"enable privacy address in wallet"
,
Short
:
"enable privacy address in wallet"
,
Run
:
E
nablePrivacy
,
Run
:
e
nablePrivacy
,
}
}
E
nablePrivacyFlags
(
cmd
)
e
nablePrivacyFlags
(
cmd
)
return
cmd
return
cmd
}
}
func
E
nablePrivacyFlags
(
cmd
*
cobra
.
Command
)
{
func
e
nablePrivacyFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"privacy enable -a [all-addr0-addr1] (all indicate enable all wallet address)"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"privacy enable -a [all-addr0-addr1] (all indicate enable all wallet address)"
)
cmd
.
MarkFlagRequired
(
"addr"
)
cmd
.
MarkFlagRequired
(
"addr"
)
}
}
func
E
nablePrivacy
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
e
nablePrivacy
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
address
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
address
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
...
@@ -725,7 +726,7 @@ func EnablePrivacy(cmd *cobra.Command, args []string) {
...
@@ -725,7 +726,7 @@ func EnablePrivacy(cmd *cobra.Command, args []string) {
}
}
var
res
pty
.
RepEnablePrivacy
var
res
pty
.
RepEnablePrivacy
ctx
:=
jsonclient
.
NewRpcCtx
(
rpcLaddr
,
"privacy.
E
nablePrivacy"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRpcCtx
(
rpcLaddr
,
"privacy.
e
nablePrivacy"
,
params
,
&
res
)
ctx
.
SetResultCb
(
parseEnablePrivacy
)
ctx
.
SetResultCb
(
parseEnablePrivacy
)
ctx
.
Run
()
ctx
.
Run
()
}
}
...
...
plugin/dapp/privacy/commands/types.go
View file @
4875a477
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
package
commands
package
commands
// PrivacyAccountResult display privacy account result
type
PrivacyAccountResult
struct
{
type
PrivacyAccountResult
struct
{
Token
string
`json:"Token,omitempty"`
Token
string
`json:"Token,omitempty"`
Txhash
string
`json:"Txhash,omitempty"`
Txhash
string
`json:"Txhash,omitempty"`
...
@@ -12,6 +13,7 @@ type PrivacyAccountResult struct {
...
@@ -12,6 +13,7 @@ type PrivacyAccountResult struct {
OnetimePubKey
string
`json:"OnetimePubKey,omitempty"`
OnetimePubKey
string
`json:"OnetimePubKey,omitempty"`
}
}
// PrivacyAccountInfoResult display privacy account information result
type
PrivacyAccountInfoResult
struct
{
type
PrivacyAccountInfoResult
struct
{
AvailableDetail
[]
*
PrivacyAccountResult
`json:"AvailableDetail,omitempty"`
AvailableDetail
[]
*
PrivacyAccountResult
`json:"AvailableDetail,omitempty"`
FrozenDetail
[]
*
PrivacyAccountResult
`json:"FrozenDetail,omitempty"`
FrozenDetail
[]
*
PrivacyAccountResult
`json:"FrozenDetail,omitempty"`
...
@@ -20,11 +22,13 @@ type PrivacyAccountInfoResult struct {
...
@@ -20,11 +22,13 @@ type PrivacyAccountInfoResult struct {
TotalAmount
string
`json:"TotalAmount,omitempty"`
TotalAmount
string
`json:"TotalAmount,omitempty"`
}
}
// PrivacyAccountSpendResult display privacy account spend result
type
PrivacyAccountSpendResult
struct
{
type
PrivacyAccountSpendResult
struct
{
Txhash
string
`json:"Txhash,omitempty"`
Txhash
string
`json:"Txhash,omitempty"`
Res
[]
*
PrivacyAccountResult
`json:"Spend,omitempty"`
Res
[]
*
PrivacyAccountResult
`json:"Spend,omitempty"`
}
}
// ShowRescanResult display rescan utxos result
type
ShowRescanResult
struct
{
type
ShowRescanResult
struct
{
Addr
string
`json:"addr"`
Addr
string
`json:"addr"`
FlagString
string
`json:"FlagString"`
FlagString
string
`json:"FlagString"`
...
@@ -34,10 +38,12 @@ type showRescanResults struct {
...
@@ -34,10 +38,12 @@ type showRescanResults struct {
RescanResults
[]
*
ShowRescanResult
`json:"ShowRescanResults,omitempty"`
RescanResults
[]
*
ShowRescanResult
`json:"ShowRescanResults,omitempty"`
}
}
// ShowEnablePrivacy display enable privacy
type
ShowEnablePrivacy
struct
{
type
ShowEnablePrivacy
struct
{
Results
[]
*
ShowPriAddrResult
`json:"results"`
Results
[]
*
ShowPriAddrResult
`json:"results"`
}
}
// ShowPriAddrResult display privacy address result
type
ShowPriAddrResult
struct
{
type
ShowPriAddrResult
struct
{
Addr
string
`json:"addr"`
Addr
string
`json:"addr"`
IsOK
bool
`json:"IsOK"`
IsOK
bool
`json:"IsOK"`
...
...
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