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
f08844a1
Commit
f08844a1
authored
Nov 20, 2018
by
sanghg
Committed by
vipwzw
Nov 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复隐私合约中golint的警告
修改rpc、types、wallet中的golint警告
parent
aa2a8ff1
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
141 additions
and
69 deletions
+141
-69
createutxosCase.go
plugin/dapp/privacy/autotest/createutxosCase.go
+16
-12
pubToPriv.go
plugin/dapp/privacy/autotest/pubToPriv.go
+4
-1
rpc.go
plugin/dapp/privacy/rpc/rpc.go
+13
-2
types.go
plugin/dapp/privacy/rpc/types.go
+3
-0
privacy.go
plugin/dapp/privacy/types/privacy.go
+40
-8
const.go
plugin/dapp/privacy/wallet/const.go
+2
-1
keys.go
plugin/dapp/privacy/wallet/keys.go
+13
-13
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+2
-2
privacybizpolicy.go
plugin/dapp/privacy/wallet/privacybizpolicy.go
+30
-12
privacystore.go
plugin/dapp/privacy/wallet/privacystore.go
+2
-2
util.go
plugin/dapp/privacy/wallet/util.go
+10
-10
util_test.go
plugin/dapp/privacy/wallet/util_test.go
+6
-6
No files found.
plugin/dapp/privacy/autotest/createutxosCase.go
View file @
f08844a1
// 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
//pub2priv case
type
CreateUtxosCase
struct
{
type
CreateUtxosCase
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"`
}
}
// CreateUtxosPack create utxos package
type
CreateUtxosPack
struct
{
type
CreateUtxosPack
struct
{
BaseCasePack
types
.
BaseCasePack
}
}
func
(
testCase
*
CreateUtxosCase
)
SendCommand
(
packID
string
)
(
PackFunc
,
error
)
{
// SendCommand send command
func
(
testCase
*
CreateUtxosCase
)
SendCommand
(
packID
string
)
(
types
.
PackFunc
,
error
)
{
return
DefaultSend
(
testCase
,
&
CreateUtxosPack
{},
packID
)
return
types
.
DefaultSend
(
testCase
,
&
CreateUtxosPack
{},
packID
)
}
}
// GetCheckHandlerMap get check handler map
func
(
pack
*
CreateUtxosPack
)
GetCheckHandlerMap
()
interface
{}
{
func
(
pack
*
CreateUtxosPack
)
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
...
@@ -50,8 +54,8 @@ func (pack *CreateUtxosPack) checkBalance(txInfo map[string]interface{}) bool {
...
@@ -50,8 +54,8 @@ func (pack *CreateUtxosPack) 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
*
CreateUtxosPack
)
checkUtxo
(
txInfo
map
[
string
]
interface
{})
bool
{
func
(
pack
*
CreateUtxosPack
)
checkUtxo
(
txInfo
map
[
string
]
interface
{})
bool
{
...
@@ -62,14 +66,14 @@ func (pack *CreateUtxosPack) checkUtxo(txInfo map[string]interface{}) bool {
...
@@ -62,14 +66,14 @@ func (pack *CreateUtxosPack) 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
(
"PrivCreateutxosDetail"
,
"TestID"
,
pack
.
PackID
,
pack
.
FLog
.
Info
(
"PrivCreateutxosDetail"
,
"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/autotest/pubToPriv.go
View file @
f08844a1
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
.
"github.com/33cn/chain33/cmd/autotest/types"
.
"github.com/33cn/chain33/cmd/autotest/types"
)
)
//pub2priv case
//
PubToPrivCase
pub2priv case
type
PubToPrivCase
struct
{
type
PubToPrivCase
struct
{
BaseCase
BaseCase
From
string
`toml:"from"`
From
string
`toml:"from"`
...
@@ -17,15 +17,18 @@ type PubToPrivCase struct {
...
@@ -17,15 +17,18 @@ type PubToPrivCase struct {
Amount
string
`toml:"amount"`
Amount
string
`toml:"amount"`
}
}
// PubToPrivPack public to privacy package
type
PubToPrivPack
struct
{
type
PubToPrivPack
struct
{
BaseCasePack
BaseCasePack
}
}
// SendCommand send command
func
(
testCase
*
PubToPrivCase
)
SendCommand
(
packID
string
)
(
PackFunc
,
error
)
{
func
(
testCase
*
PubToPrivCase
)
SendCommand
(
packID
string
)
(
PackFunc
,
error
)
{
return
DefaultSend
(
testCase
,
&
PubToPrivPack
{},
packID
)
return
DefaultSend
(
testCase
,
&
PubToPrivPack
{},
packID
)
}
}
// GetCheckHandlerMap get check handler map
func
(
pack
*
PubToPrivPack
)
GetCheckHandlerMap
()
interface
{}
{
func
(
pack
*
PubToPrivPack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
CheckHandlerMapDiscard
,
2
)
funcMap
:=
make
(
CheckHandlerMapDiscard
,
2
)
...
...
plugin/dapp/privacy/rpc/rpc.go
View file @
f08844a1
...
@@ -86,6 +86,7 @@ func (g *channelClient) CreateRawTransaction(ctx context.Context, in *types.ReqC
...
@@ -86,6 +86,7 @@ func (g *channelClient) CreateRawTransaction(ctx context.Context, in *types.ReqC
return
data
.
(
*
types
.
Transaction
),
nil
return
data
.
(
*
types
.
Transaction
),
nil
}
}
// ShowPrivacyAccountInfo display privacy account information for json rpc
func
(
c
*
Jrpc
)
ShowPrivacyAccountInfo
(
in
*
pty
.
ReqPPrivacyAccount
,
result
*
json
.
RawMessage
)
error
{
func
(
c
*
Jrpc
)
ShowPrivacyAccountInfo
(
in
*
pty
.
ReqPPrivacyAccount
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
pty
.
PrivacyX
,
"ShowPrivacyAccountInfo"
,
in
)
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
pty
.
PrivacyX
,
"ShowPrivacyAccountInfo"
,
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -96,6 +97,8 @@ func (c *Jrpc) ShowPrivacyAccountInfo(in *pty.ReqPPrivacyAccount, result *json.R
...
@@ -96,6 +97,8 @@ func (c *Jrpc) ShowPrivacyAccountInfo(in *pty.ReqPPrivacyAccount, result *json.R
}
}
/////////////////privacy///////////////
/////////////////privacy///////////////
// ShowPrivacyAccountSpend display spend privacy account for json rpc
func
(
c
*
Jrpc
)
ShowPrivacyAccountSpend
(
in
*
pty
.
ReqPrivBal4AddrToken
,
result
*
json
.
RawMessage
)
error
{
func
(
c
*
Jrpc
)
ShowPrivacyAccountSpend
(
in
*
pty
.
ReqPrivBal4AddrToken
,
result
*
json
.
RawMessage
)
error
{
if
0
==
len
(
in
.
Addr
)
{
if
0
==
len
(
in
.
Addr
)
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
...
@@ -109,6 +112,7 @@ func (c *Jrpc) ShowPrivacyAccountSpend(in *pty.ReqPrivBal4AddrToken, result *jso
...
@@ -109,6 +112,7 @@ func (c *Jrpc) ShowPrivacyAccountSpend(in *pty.ReqPrivBal4AddrToken, result *jso
return
err
return
err
}
}
// ShowPrivacykey display privacy key for json rpc
func
(
c
*
Jrpc
)
ShowPrivacykey
(
in
*
types
.
ReqString
,
result
*
json
.
RawMessage
)
error
{
func
(
c
*
Jrpc
)
ShowPrivacykey
(
in
*
types
.
ReqString
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ShowPrivacyKey
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
ShowPrivacyKey
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -118,6 +122,7 @@ func (c *Jrpc) ShowPrivacykey(in *types.ReqString, result *json.RawMessage) erro
...
@@ -118,6 +122,7 @@ func (c *Jrpc) ShowPrivacykey(in *types.ReqString, result *json.RawMessage) erro
return
err
return
err
}
}
// MakeTxPublic2privacy create public to privacy trasaction for json rpc
func
(
c
*
Jrpc
)
MakeTxPublic2privacy
(
in
*
pty
.
ReqPub2Pri
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
MakeTxPublic2privacy
(
in
*
pty
.
ReqPub2Pri
,
result
*
interface
{})
error
{
reply
,
err
:=
c
.
cli
.
MakeTxPublic2Privacy
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
MakeTxPublic2Privacy
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -129,6 +134,7 @@ func (c *Jrpc) MakeTxPublic2privacy(in *pty.ReqPub2Pri, result *interface{}) err
...
@@ -129,6 +134,7 @@ func (c *Jrpc) MakeTxPublic2privacy(in *pty.ReqPub2Pri, result *interface{}) err
return
nil
return
nil
}
}
// MakeTxPrivacy2privacy create privacy to privacy transaction
func
(
c
*
Jrpc
)
MakeTxPrivacy2privacy
(
in
*
pty
.
ReqPri2Pri
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
MakeTxPrivacy2privacy
(
in
*
pty
.
ReqPri2Pri
,
result
*
interface
{})
error
{
reply
,
err
:=
c
.
cli
.
MakeTxPrivacy2Privacy
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
MakeTxPrivacy2Privacy
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -140,6 +146,7 @@ func (c *Jrpc) MakeTxPrivacy2privacy(in *pty.ReqPri2Pri, result *interface{}) er
...
@@ -140,6 +146,7 @@ func (c *Jrpc) MakeTxPrivacy2privacy(in *pty.ReqPri2Pri, result *interface{}) er
return
nil
return
nil
}
}
// MakeTxPrivacy2public make privacy to public trasaction
func
(
c
*
Jrpc
)
MakeTxPrivacy2public
(
in
*
pty
.
ReqPri2Pub
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
MakeTxPrivacy2public
(
in
*
pty
.
ReqPri2Pub
,
result
*
interface
{})
error
{
reply
,
err
:=
c
.
cli
.
MakeTxPrivacy2Public
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
MakeTxPrivacy2Public
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -150,6 +157,7 @@ func (c *Jrpc) MakeTxPrivacy2public(in *pty.ReqPri2Pub, result *interface{}) err
...
@@ -150,6 +157,7 @@ func (c *Jrpc) MakeTxPrivacy2public(in *pty.ReqPri2Pub, result *interface{}) err
return
nil
return
nil
}
}
// CreateUTXOs create utxos for json rpc
func
(
c
*
Jrpc
)
CreateUTXOs
(
in
*
pty
.
ReqCreateUTXOs
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
CreateUTXOs
(
in
*
pty
.
ReqCreateUTXOs
,
result
*
interface
{})
error
{
reply
,
err
:=
c
.
cli
.
CreateUTXOs
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
CreateUTXOs
(
context
.
Background
(),
in
)
...
@@ -178,6 +186,7 @@ func (c *Jrpc) PrivacyTxList(in *pty.ReqPrivacyTransactionList, result *interfac
...
@@ -178,6 +186,7 @@ func (c *Jrpc) PrivacyTxList(in *pty.ReqPrivacyTransactionList, result *interfac
return
nil
return
nil
}
}
// RescanUtxos rescan utxosl for json rpc
func
(
c
*
Jrpc
)
RescanUtxos
(
in
*
pty
.
ReqRescanUtxos
,
result
*
json
.
RawMessage
)
error
{
func
(
c
*
Jrpc
)
RescanUtxos
(
in
*
pty
.
ReqRescanUtxos
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
RescanUtxos
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
RescanUtxos
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -187,6 +196,7 @@ func (c *Jrpc) RescanUtxos(in *pty.ReqRescanUtxos, result *json.RawMessage) erro
...
@@ -187,6 +196,7 @@ func (c *Jrpc) RescanUtxos(in *pty.ReqRescanUtxos, result *json.RawMessage) erro
return
err
return
err
}
}
// EnablePrivacy enable privacy for json rpc
func
(
c
*
Jrpc
)
EnablePrivacy
(
in
*
pty
.
ReqEnablePrivacy
,
result
*
json
.
RawMessage
)
error
{
func
(
c
*
Jrpc
)
EnablePrivacy
(
in
*
pty
.
ReqEnablePrivacy
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
EnablePrivacy
(
context
.
Background
(),
in
)
reply
,
err
:=
c
.
cli
.
EnablePrivacy
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -196,8 +206,9 @@ func (c *Jrpc) EnablePrivacy(in *pty.ReqEnablePrivacy, result *json.RawMessage)
...
@@ -196,8 +206,9 @@ func (c *Jrpc) EnablePrivacy(in *pty.ReqEnablePrivacy, result *json.RawMessage)
return
err
return
err
}
}
func
(
this
*
Jrpc
)
CreateRawTransaction
(
in
*
types
.
ReqCreateTransaction
,
result
*
interface
{})
error
{
// CreateRawTransaction create raw trasaction for json rpc
reply
,
err
:=
this
.
cli
.
CreateRawTransaction
(
context
.
Background
(),
in
)
func
(
c
*
Jrpc
)
CreateRawTransaction
(
in
*
types
.
ReqCreateTransaction
,
result
*
interface
{})
error
{
reply
,
err
:=
c
.
cli
.
CreateRawTransaction
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
plugin/dapp/privacy/rpc/types.go
View file @
f08844a1
...
@@ -12,10 +12,12 @@ import (
...
@@ -12,10 +12,12 @@ import (
var
log
=
log15
.
New
(
"module"
,
"privacy.rpc"
)
var
log
=
log15
.
New
(
"module"
,
"privacy.rpc"
)
// Jrpc json rpc class
type
Jrpc
struct
{
type
Jrpc
struct
{
cli
*
channelClient
cli
*
channelClient
}
}
// Grpc grpc class
type
Grpc
struct
{
type
Grpc
struct
{
*
channelClient
*
channelClient
}
}
...
@@ -24,6 +26,7 @@ type channelClient struct {
...
@@ -24,6 +26,7 @@ type channelClient struct {
types
.
ChannelClient
types
.
ChannelClient
}
}
// Init init rpc server
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
...
...
plugin/dapp/privacy/types/privacy.go
View file @
f08844a1
...
@@ -11,26 +11,41 @@ import (
...
@@ -11,26 +11,41 @@ import (
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
)
)
// PrivacyX privacy executor name
var
PrivacyX
=
"privacy"
var
PrivacyX
=
"privacy"
const
(
const
(
// InvalidAction invalid action type
InvalidAction
=
0
InvalidAction
=
0
//action type for privacy
//action type for privacy
// ActionPublic2Privacy public to privacy action type
ActionPublic2Privacy
=
iota
+
100
ActionPublic2Privacy
=
iota
+
100
// ActionPrivacy2Privacy privacy to privacy action type
ActionPrivacy2Privacy
ActionPrivacy2Privacy
// ActionPrivacy2Public privacy to public action type
ActionPrivacy2Public
ActionPrivacy2Public
// log for privacy
// log for privacy
// TyLogPrivacyFee privacy fee log type
TyLogPrivacyFee
=
500
TyLogPrivacyFee
=
500
// TyLogPrivacyInput privacy input type
TyLogPrivacyInput
=
501
TyLogPrivacyInput
=
501
// TyLogPrivacyOutput privacy output type
TyLogPrivacyOutput
=
502
TyLogPrivacyOutput
=
502
//privacy name of crypto
//
SignNameOnetimeED25519
privacy name of crypto
SignNameOnetimeED25519
=
"privacy.onetimeed25519"
SignNameOnetimeED25519
=
"privacy.onetimeed25519"
// SignNameRing signature name ring
SignNameRing
=
"privacy.RingSignatue"
SignNameRing
=
"privacy.RingSignatue"
// OnetimeED25519 one time ED25519
OnetimeED25519
=
4
OnetimeED25519
=
4
// RingBaseonED25519 ring raseon ED25519
RingBaseonED25519
=
5
RingBaseonED25519
=
5
// PrivacyMaxCount max mix utxo cout
PrivacyMaxCount
=
16
PrivacyMaxCount
=
16
// PrivacyTxFee privacy tx fee
PrivacyTxFee
=
types
.
Coin
PrivacyTxFee
=
types
.
Coin
)
)
...
@@ -41,6 +56,7 @@ const (
...
@@ -41,6 +56,7 @@ const (
UtxoFlagScanEnd
int32
=
2
UtxoFlagScanEnd
int32
=
2
)
)
// RescanFlagMapint2string 常量字符串转换关系表
var
RescanFlagMapint2string
=
map
[
int32
]
string
{
var
RescanFlagMapint2string
=
map
[
int32
]
string
{
UtxoFlagNoScan
:
"UtxoFlagNoScan"
,
UtxoFlagNoScan
:
"UtxoFlagNoScan"
,
UtxoFlagScaning
:
"UtxoFlagScaning"
,
UtxoFlagScaning
:
"UtxoFlagScaning"
,
...
@@ -64,25 +80,30 @@ func init() {
...
@@ -64,25 +80,30 @@ func init() {
types
.
RegisterDappFork
(
PrivacyX
,
"Enable"
,
980000
)
types
.
RegisterDappFork
(
PrivacyX
,
"Enable"
,
980000
)
}
}
// PrivacyType declare PrivacyType class
type
PrivacyType
struct
{
type
PrivacyType
struct
{
types
.
ExecTypeBase
types
.
ExecTypeBase
}
}
// NewType create PrivacyType object
func
NewType
()
*
PrivacyType
{
func
NewType
()
*
PrivacyType
{
c
:=
&
PrivacyType
{}
c
:=
&
PrivacyType
{}
c
.
SetChild
(
c
)
c
.
SetChild
(
c
)
return
c
return
c
}
}
func
(
at
*
PrivacyType
)
GetPayload
()
types
.
Message
{
// GetPayload get PrivacyType payload
func
(
t
*
PrivacyType
)
GetPayload
()
types
.
Message
{
return
&
PrivacyAction
{}
return
&
PrivacyAction
{}
}
}
func
(
at
*
PrivacyType
)
GetName
()
string
{
// GetName get PrivacyType name
func
(
t
*
PrivacyType
)
GetName
()
string
{
return
PrivacyX
return
PrivacyX
}
}
func
(
at
*
PrivacyType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
// GetLogMap get PrivacyType log map
func
(
t
*
PrivacyType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
TyLogPrivacyFee
:
{
reflect
.
TypeOf
(
types
.
ReceiptExecAccountTransfer
{}),
"LogPrivacyFee"
},
TyLogPrivacyFee
:
{
reflect
.
TypeOf
(
types
.
ReceiptExecAccountTransfer
{}),
"LogPrivacyFee"
},
TyLogPrivacyInput
:
{
reflect
.
TypeOf
(
PrivacyInput
{}),
"LogPrivacyInput"
},
TyLogPrivacyInput
:
{
reflect
.
TypeOf
(
PrivacyInput
{}),
"LogPrivacyInput"
},
...
@@ -90,7 +111,8 @@ func (at *PrivacyType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -90,7 +111,8 @@ func (at *PrivacyType) GetLogMap() map[int64]*types.LogInfo {
}
}
}
}
func
(
c
*
PrivacyType
)
GetTypeMap
()
map
[
string
]
int32
{
// GetTypeMap get PrivacyType type map
func
(
t
*
PrivacyType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Public2Privacy"
:
ActionPublic2Privacy
,
"Public2Privacy"
:
ActionPublic2Privacy
,
"Privacy2Privacy"
:
ActionPrivacy2Privacy
,
"Privacy2Privacy"
:
ActionPrivacy2Privacy
,
...
@@ -98,7 +120,8 @@ func (c *PrivacyType) GetTypeMap() map[string]int32 {
...
@@ -98,7 +120,8 @@ func (c *PrivacyType) GetTypeMap() map[string]int32 {
}
}
}
}
func
(
coins
PrivacyType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
// ActionName get PrivacyType action name
func
(
t
PrivacyType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
var
action
PrivacyAction
var
action
PrivacyAction
err
:=
types
.
Decode
(
tx
.
Payload
,
&
action
)
err
:=
types
.
Decode
(
tx
.
Payload
,
&
action
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -108,29 +131,35 @@ func (coins PrivacyType) ActionName(tx *types.Transaction) string {
...
@@ -108,29 +131,35 @@ func (coins PrivacyType) ActionName(tx *types.Transaction) string {
}
}
// TODO 暂时不修改实现, 先完成结构的重构
// TODO 暂时不修改实现, 先完成结构的重构
// CreateTx create transaction
func
(
t
*
PrivacyType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
func
(
t
*
PrivacyType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
return
tx
,
nil
return
tx
,
nil
}
}
// Amount get amout
func
(
t
*
PrivacyType
)
Amount
(
tx
*
types
.
Transaction
)
(
int64
,
error
)
{
func
(
t
*
PrivacyType
)
Amount
(
tx
*
types
.
Transaction
)
(
int64
,
error
)
{
return
0
,
nil
return
0
,
nil
}
}
func
(
base
*
PrivacyType
)
GetCryptoDriver
(
ty
int
)
(
string
,
error
)
{
// GetCryptoDriver get crypto driver
func
(
t
*
PrivacyType
)
GetCryptoDriver
(
ty
int
)
(
string
,
error
)
{
if
name
,
ok
:=
mapSignType2name
[
ty
];
ok
{
if
name
,
ok
:=
mapSignType2name
[
ty
];
ok
{
return
name
,
nil
return
name
,
nil
}
}
return
""
,
types
.
ErrNotSupport
return
""
,
types
.
ErrNotSupport
}
}
func
(
base
*
PrivacyType
)
GetCryptoType
(
name
string
)
(
int
,
error
)
{
// GetCryptoType get crypto type
func
(
t
*
PrivacyType
)
GetCryptoType
(
name
string
)
(
int
,
error
)
{
if
ty
,
ok
:=
mapSignName2Type
[
name
];
ok
{
if
ty
,
ok
:=
mapSignName2Type
[
name
];
ok
{
return
ty
,
nil
return
ty
,
nil
}
}
return
0
,
types
.
ErrNotSupport
return
0
,
types
.
ErrNotSupport
}
}
// GetInput get action input information
func
(
action
*
PrivacyAction
)
GetInput
()
*
PrivacyInput
{
func
(
action
*
PrivacyAction
)
GetInput
()
*
PrivacyInput
{
if
action
.
GetTy
()
==
ActionPrivacy2Privacy
&&
action
.
GetPrivacy2Privacy
()
!=
nil
{
if
action
.
GetTy
()
==
ActionPrivacy2Privacy
&&
action
.
GetPrivacy2Privacy
()
!=
nil
{
return
action
.
GetPrivacy2Privacy
()
.
GetInput
()
return
action
.
GetPrivacy2Privacy
()
.
GetInput
()
...
@@ -141,6 +170,7 @@ func (action *PrivacyAction) GetInput() *PrivacyInput {
...
@@ -141,6 +170,7 @@ func (action *PrivacyAction) GetInput() *PrivacyInput {
return
nil
return
nil
}
}
// GetOutput get action output information
func
(
action
*
PrivacyAction
)
GetOutput
()
*
PrivacyOutput
{
func
(
action
*
PrivacyAction
)
GetOutput
()
*
PrivacyOutput
{
if
action
.
GetTy
()
==
ActionPublic2Privacy
&&
action
.
GetPublic2Privacy
()
!=
nil
{
if
action
.
GetTy
()
==
ActionPublic2Privacy
&&
action
.
GetPublic2Privacy
()
!=
nil
{
return
action
.
GetPublic2Privacy
()
.
GetOutput
()
return
action
.
GetPublic2Privacy
()
.
GetOutput
()
...
@@ -152,6 +182,7 @@ func (action *PrivacyAction) GetOutput() *PrivacyOutput {
...
@@ -152,6 +182,7 @@ func (action *PrivacyAction) GetOutput() *PrivacyOutput {
return
nil
return
nil
}
}
// GetActionName get action name
func
(
action
*
PrivacyAction
)
GetActionName
()
string
{
func
(
action
*
PrivacyAction
)
GetActionName
()
string
{
if
action
.
Ty
==
ActionPrivacy2Privacy
&&
action
.
GetPrivacy2Privacy
()
!=
nil
{
if
action
.
Ty
==
ActionPrivacy2Privacy
&&
action
.
GetPrivacy2Privacy
()
!=
nil
{
return
"Privacy2Privacy"
return
"Privacy2Privacy"
...
@@ -163,6 +194,7 @@ func (action *PrivacyAction) GetActionName() string {
...
@@ -163,6 +194,7 @@ func (action *PrivacyAction) GetActionName() string {
return
"unknow-privacy"
return
"unknow-privacy"
}
}
// GetTokenName get action token name
func
(
action
*
PrivacyAction
)
GetTokenName
()
string
{
func
(
action
*
PrivacyAction
)
GetTokenName
()
string
{
if
action
.
GetTy
()
==
ActionPublic2Privacy
&&
action
.
GetPublic2Privacy
()
!=
nil
{
if
action
.
GetTy
()
==
ActionPublic2Privacy
&&
action
.
GetPublic2Privacy
()
!=
nil
{
return
action
.
GetPublic2Privacy
()
.
GetTokenname
()
return
action
.
GetPublic2Privacy
()
.
GetTokenname
()
...
...
plugin/dapp/privacy/wallet/const.go
View file @
f08844a1
...
@@ -5,8 +5,9 @@
...
@@ -5,8 +5,9 @@
package
wallet
package
wallet
const
(
const
(
//
交易操作的方向
//
AddTx 增加交易
AddTx
int32
=
20001
AddTx
int32
=
20001
// DelTx 删除交易
DelTx
int32
=
20002
DelTx
int32
=
20002
// 交易收发方向
// 交易收发方向
sendTx
int32
=
30001
sendTx
int32
=
30001
...
...
plugin/dapp/privacy/wallet/keys.go
View file @
f08844a1
...
@@ -7,53 +7,53 @@ package wallet
...
@@ -7,53 +7,53 @@ package wallet
import
"fmt"
import
"fmt"
const
(
const
(
// 隐私交易运行过程中,需要使用到钱包数据库存储的数据库版本信息的KEY值
//
PrivacyDBVersion
隐私交易运行过程中,需要使用到钱包数据库存储的数据库版本信息的KEY值
PrivacyDBVersion
=
"Privacy-DBVersion"
PrivacyDBVersion
=
"Privacy-DBVersion"
// 存储隐私交易保存账户的隐私公钥对信息的KEY值
//
Privacy4Addr
存储隐私交易保存账户的隐私公钥对信息的KEY值
// KEY值格式为 Privacy4Addr-账号地址
// KEY值格式为 Privacy4Addr-账号地址
// VALUE值格式为 types.WalletAccountPrivacy, 存储隐私公钥对
// VALUE值格式为 types.WalletAccountPrivacy, 存储隐私公钥对
Privacy4Addr
=
"Privacy-Addr"
Privacy4Addr
=
"Privacy-Addr"
// 当前钱包内对应地址下可用UTXO的信息索引KEY值
//
AvailUTXOs
当前钱包内对应地址下可用UTXO的信息索引KEY值
// KEY值格式为 AvailUTXOs-tokenname-address-outtxhash-outindex 其中outtxhash是输出该UTXO的交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 AvailUTXOs-tokenname-address-outtxhash-outindex 其中outtxhash是输出该UTXO的交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 types.PrivacyDBStore,存储当前钱包地址下可用UTXO的详细信息
// VALUE值格式为 types.PrivacyDBStore,存储当前钱包地址下可用UTXO的详细信息
AvailUTXOs
=
"Privacy-UTXO"
AvailUTXOs
=
"Privacy-UTXO"
// 创建一笔隐私交易后,创建该交易使用的UTXO信息,用以记录某一笔交易,占用了某些UTXO以及该交易的一些摘要信息
//
UTXOsSpentInTx
创建一笔隐私交易后,创建该交易使用的UTXO信息,用以记录某一笔交易,占用了某些UTXO以及该交易的一些摘要信息
// KEY值格式为 UTXOsSpentInTx:costtxhash 其中costtxhash是创建的隐私交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 UTXOsSpentInTx:costtxhash 其中costtxhash是创建的隐私交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 types.FTXOsSTXOsInOneTx
// VALUE值格式为 types.FTXOsSTXOsInOneTx
UTXOsSpentInTx
=
"Privacy-UTXOsSpentInTx"
UTXOsSpentInTx
=
"Privacy-UTXOsSpentInTx"
// 通过钱包创建交易后,会将该交易使用到的UTXO信息进行冻结,冻结信息的索引KEY值
//
FrozenUTXOs
通过钱包创建交易后,会将该交易使用到的UTXO信息进行冻结,冻结信息的索引KEY值
// KEY值格式为 FrozenUTXOs:tokenname-address-costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 FrozenUTXOs:tokenname-address-costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
FrozenUTXOs
=
"Privacy-FUTXO4Tx"
FrozenUTXOs
=
"Privacy-FUTXO4Tx"
// 通过钱包创建的交易被确认打包到区块后,可用UTXO变成已花费UTXO,用来保存已花费UTXO信息的KEY值
//
PrivacySTXO
通过钱包创建的交易被确认打包到区块后,可用UTXO变成已花费UTXO,用来保存已花费UTXO信息的KEY值
// KEY值格式为 PrivacySTXO-tokenname-address-costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 PrivacySTXO-tokenname-address-costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
PrivacySTXO
=
"Privacy-SUTXO"
PrivacySTXO
=
"Privacy-SUTXO"
// 保存花费了UTXO的交易索引的KEY值
//
STXOs4Tx
保存花费了UTXO的交易索引的KEY值
// KEY值格式为 STXOs4Tx:costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 STXOs4Tx:costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
STXOs4Tx
=
"Privacy-SUTXO4Tx"
STXOs4Tx
=
"Privacy-SUTXO4Tx"
// 缓存因为区块发生回退时作为花费输出的UTXO信息
//
RevertSendtx
缓存因为区块发生回退时作为花费输出的UTXO信息
// KEY值格式为 RevertSendtx:tokenname-address-costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 RevertSendtx:tokenname-address-costtxhash 其中costtxhash是使用UTXO的交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
// VALUE值格式为 是指向UTXOsSpentInTx的KEY值的串
RevertSendtx
=
"Privacy-RevertSendtx"
RevertSendtx
=
"Privacy-RevertSendtx"
// 记录本钱包收到的发送给钱包内地址的交易信息KEY值
//
RecvPrivacyTx
记录本钱包收到的发送给钱包内地址的交易信息KEY值
// KEY值格式为 RecvPrivacyTx:tokenname-address-heighstr 其中heighstr是区块高度乘以types.MaxTxsPerBlock加上当前交易在该区块上的位置index
// KEY值格式为 RecvPrivacyTx:tokenname-address-heighstr 其中heighstr是区块高度乘以types.MaxTxsPerBlock加上当前交易在该区块上的位置index
// VALUE值格式为 指向PrivacyTX定义的KEY串
// VALUE值格式为 指向PrivacyTX定义的KEY串
RecvPrivacyTx
=
"Privacy-RecvTX"
RecvPrivacyTx
=
"Privacy-RecvTX"
// 记录从本钱包花费出去的的交易信息KEY值
//
SendPrivacyTx
记录从本钱包花费出去的的交易信息KEY值
// KEY值格式为 SendPrivacyTx:tokenname-address-heighstr 其中heighstr是区块高度乘以types.MaxTxsPerBlock加上当前交易在该区块上的位置index
// KEY值格式为 SendPrivacyTx:tokenname-address-heighstr 其中heighstr是区块高度乘以types.MaxTxsPerBlock加上当前交易在该区块上的位置index
// VALUE值格式为 指向PrivacyTX定义的KEY串
// VALUE值格式为 指向PrivacyTX定义的KEY串
SendPrivacyTx
=
"Privacy-SendTX"
SendPrivacyTx
=
"Privacy-SendTX"
// 用以保存钱包收到的所有隐私交易具体信息的索引KEY值
//
PrivacyTX
用以保存钱包收到的所有隐私交易具体信息的索引KEY值
// KEY值格式为 PrivacyTX:heighstr 其中heighstr是区块高度乘以types.MaxTxsPerBlock加上当前交易在该区块上的位置index
// KEY值格式为 PrivacyTX:heighstr 其中heighstr是区块高度乘以types.MaxTxsPerBlock加上当前交易在该区块上的位置index
// VALUE值格式为 types.WalletTxDetail
// VALUE值格式为 types.WalletTxDetail
PrivacyTX
=
"Privacy-TX"
PrivacyTX
=
"Privacy-TX"
// 通过扫描全链表,保存隐私交易中所有给当前钱包地址的交易的输入UTXO信息
//
ScanPrivacyInput
通过扫描全链表,保存隐私交易中所有给当前钱包地址的交易的输入UTXO信息
// KEY值格式为 ScanPrivacyInput-outtxhash-outindex 其中outtxhash是输出该UTXO的交易哈希,使用common.Byte2Hex()生成
// KEY值格式为 ScanPrivacyInput-outtxhash-outindex 其中outtxhash是输出该UTXO的交易哈希,使用common.Byte2Hex()生成
// VALUE值格式为 types.UTXOGlobalIndex
// VALUE值格式为 types.UTXOGlobalIndex
ScanPrivacyInput
=
"Privacy-ScaneInput"
ScanPrivacyInput
=
"Privacy-ScaneInput"
// 存储是否处于重新扫描UTXO信息的标识
//
ReScanUtxosFlag
存储是否处于重新扫描UTXO信息的标识
// KEY值格式为 ReScanUtxosFlag
// KEY值格式为 ReScanUtxosFlag
// VALUE值格式为 types.Int64,具体含义
// VALUE值格式为 types.Int64,具体含义
// UtxoFlagNoScan int32 = 0
// UtxoFlagNoScan int32 = 0
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
f08844a1
...
@@ -232,13 +232,13 @@ func (policy *privacyPolicy) getPrivacykeyPair(addr string) (*privacy.Privacy, e
...
@@ -232,13 +232,13 @@ func (policy *privacyPolicy) getPrivacykeyPair(addr string) (*privacy.Privacy, e
copy
(
privacyInfo
.
SpendPrivKey
[
:
],
decrypteredSpend
)
copy
(
privacyInfo
.
SpendPrivKey
[
:
],
decrypteredSpend
)
return
privacyInfo
,
nil
return
privacyInfo
,
nil
}
else
{
}
_
,
err
:=
policy
.
getPrivKeyByAddr
(
addr
)
_
,
err
:=
policy
.
getPrivKeyByAddr
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
privacytypes
.
ErrPrivacyNotEnabled
return
nil
,
privacytypes
.
ErrPrivacyNotEnabled
}
}
}
func
(
policy
*
privacyPolicy
)
savePrivacykeyPair
(
addr
string
)
(
*
privacy
.
Privacy
,
error
)
{
func
(
policy
*
privacyPolicy
)
savePrivacykeyPair
(
addr
string
)
(
*
privacy
.
Privacy
,
error
)
{
...
...
plugin/dapp/privacy/wallet/privacybizpolicy.go
View file @
f08844a1
// 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
policy
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
wallet
package
wallet
...
@@ -19,7 +19,9 @@ import (
...
@@ -19,7 +19,9 @@ import (
var
(
var
(
bizlog
=
log15
.
New
(
"module"
,
"wallet.privacy"
)
bizlog
=
log15
.
New
(
"module"
,
"wallet.privacy"
)
// MaxTxHashsPerTime 单词处理的最大哈希书
MaxTxHashsPerTime
int64
=
100
MaxTxHashsPerTime
int64
=
100
// maxTxNumPerBlock 单个区块最大数
maxTxNumPerBlock
int64
=
types
.
MaxTxsPerBlock
maxTxNumPerBlock
int64
=
types
.
MaxTxsPerBlock
)
)
...
@@ -27,6 +29,7 @@ func init() {
...
@@ -27,6 +29,7 @@ func init() {
wcom
.
RegisterPolicy
(
privacytypes
.
PrivacyX
,
New
())
wcom
.
RegisterPolicy
(
privacytypes
.
PrivacyX
,
New
())
}
}
// New 创建一盒钱包业务策略
func
New
()
wcom
.
WalletBizPolicy
{
func
New
()
wcom
.
WalletBizPolicy
{
return
&
privacyPolicy
{
return
&
privacyPolicy
{
mtx
:
&
sync
.
Mutex
{},
mtx
:
&
sync
.
Mutex
{},
...
@@ -55,56 +58,66 @@ func (policy *privacyPolicy) getWalletOperate() wcom.WalletOperate {
...
@@ -55,56 +58,66 @@ func (policy *privacyPolicy) getWalletOperate() wcom.WalletOperate {
return
policy
.
walletOperate
return
policy
.
walletOperate
}
}
// Init 初始化处理
func
(
policy
*
privacyPolicy
)
Init
(
walletOperate
wcom
.
WalletOperate
,
sub
[]
byte
)
{
func
(
policy
*
privacyPolicy
)
Init
(
walletOperate
wcom
.
WalletOperate
,
sub
[]
byte
)
{
policy
.
setWalletOperate
(
walletOperate
)
policy
.
setWalletOperate
(
walletOperate
)
policy
.
store
=
N
ewStore
(
walletOperate
.
GetDBStore
())
policy
.
store
=
n
ewStore
(
walletOperate
.
GetDBStore
())
// 启动定时检查超期FTXO的协程
// 启动定时检查超期FTXO的协程
walletOperate
.
GetWaitGroup
()
.
Add
(
1
)
walletOperate
.
GetWaitGroup
()
.
Add
(
1
)
go
policy
.
checkWalletStoreData
()
go
policy
.
checkWalletStoreData
()
}
}
// OnCreateNewAccount 在账号创建时做一些处理
func
(
policy
*
privacyPolicy
)
OnCreateNewAccount
(
acc
*
types
.
Account
)
{
func
(
policy
*
privacyPolicy
)
OnCreateNewAccount
(
acc
*
types
.
Account
)
{
wg
:=
policy
.
getWalletOperate
()
.
GetWaitGroup
()
wg
:=
policy
.
getWalletOperate
()
.
GetWaitGroup
()
wg
.
Add
(
1
)
wg
.
Add
(
1
)
go
policy
.
rescanReqTxDetailByAddr
(
acc
.
Addr
,
wg
)
go
policy
.
rescanReqTxDetailByAddr
(
acc
.
Addr
,
wg
)
}
}
// OnImportPrivateKey 在私钥导入时做一些处理
func
(
policy
*
privacyPolicy
)
OnImportPrivateKey
(
acc
*
types
.
Account
)
{
func
(
policy
*
privacyPolicy
)
OnImportPrivateKey
(
acc
*
types
.
Account
)
{
wg
:=
policy
.
getWalletOperate
()
.
GetWaitGroup
()
wg
:=
policy
.
getWalletOperate
()
.
GetWaitGroup
()
wg
.
Add
(
1
)
wg
.
Add
(
1
)
go
policy
.
rescanReqTxDetailByAddr
(
acc
.
Addr
,
wg
)
go
policy
.
rescanReqTxDetailByAddr
(
acc
.
Addr
,
wg
)
}
}
// OnAddBlockFinish 在区块被添加成功时做一些处理
func
(
policy
*
privacyPolicy
)
OnAddBlockFinish
(
block
*
types
.
BlockDetail
)
{
func
(
policy
*
privacyPolicy
)
OnAddBlockFinish
(
block
*
types
.
BlockDetail
)
{
}
}
// OnDeleteBlockFinish 在区块被删除成功时做一些处理
func
(
policy
*
privacyPolicy
)
OnDeleteBlockFinish
(
block
*
types
.
BlockDetail
)
{
func
(
policy
*
privacyPolicy
)
OnDeleteBlockFinish
(
block
*
types
.
BlockDetail
)
{
}
}
// OnClose 在钱包关闭时做一些处理
func
(
policy
*
privacyPolicy
)
OnClose
()
{
func
(
policy
*
privacyPolicy
)
OnClose
()
{
}
}
func
(
this
*
privacyPolicy
)
OnSetQueueClient
()
{
// OnSetQueueClient 在钱包消息队列初始化时做一些处理
version
:=
this
.
store
.
getVersion
()
func
(
policy
*
privacyPolicy
)
OnSetQueueClient
()
{
version
:=
policy
.
store
.
getVersion
()
if
version
<
PRIVACYDBVERSION
{
if
version
<
PRIVACYDBVERSION
{
this
.
rescanAllTxAddToUpdateUTXOs
()
policy
.
rescanAllTxAddToUpdateUTXOs
()
this
.
store
.
setVersion
()
policy
.
store
.
setVersion
()
}
}
}
}
// OnWalletLocked 在钱包加锁时做一些处理
func
(
policy
*
privacyPolicy
)
OnWalletLocked
()
{
func
(
policy
*
privacyPolicy
)
OnWalletLocked
()
{
}
}
// OnWalletUnlocked 在钱包解锁时做一些处理
func
(
policy
*
privacyPolicy
)
OnWalletUnlocked
(
WalletUnLock
*
types
.
WalletUnLock
)
{
func
(
policy
*
privacyPolicy
)
OnWalletUnlocked
(
WalletUnLock
*
types
.
WalletUnLock
)
{
}
}
func
(
this
*
privacyPolicy
)
Call
(
funName
string
,
in
types
.
Message
)
(
ret
types
.
Message
,
err
error
)
{
// Call 调用隐私的方法
func
(
policy
*
privacyPolicy
)
Call
(
funName
string
,
in
types
.
Message
)
(
ret
types
.
Message
,
err
error
)
{
switch
funName
{
switch
funName
{
case
"GetUTXOScaningFlag"
:
case
"GetUTXOScaningFlag"
:
isok
:=
this
.
GetRescanFlag
()
==
privacytypes
.
UtxoFlagScaning
isok
:=
policy
.
GetRescanFlag
()
==
privacytypes
.
UtxoFlagScaning
ret
=
&
types
.
Reply
{
IsOk
:
isok
}
ret
=
&
types
.
Reply
{
IsOk
:
isok
}
default
:
default
:
err
=
types
.
ErrNotSupport
err
=
types
.
ErrNotSupport
...
@@ -112,6 +125,7 @@ func (this *privacyPolicy) Call(funName string, in types.Message) (ret types.Mes
...
@@ -112,6 +125,7 @@ func (this *privacyPolicy) Call(funName string, in types.Message) (ret types.Mes
return
return
}
}
// SignTransaction 对隐私交易进行签名
func
(
policy
*
privacyPolicy
)
SignTransaction
(
key
crypto
.
PrivKey
,
req
*
types
.
ReqSignRawTx
)
(
needSysSign
bool
,
signtxhex
string
,
err
error
)
{
func
(
policy
*
privacyPolicy
)
SignTransaction
(
key
crypto
.
PrivKey
,
req
*
types
.
ReqSignRawTx
)
(
needSysSign
bool
,
signtxhex
string
,
err
error
)
{
needSysSign
=
false
needSysSign
=
false
bytes
,
err
:=
common
.
FromHex
(
req
.
GetTxHex
())
bytes
,
err
:=
common
.
FromHex
(
req
.
GetTxHex
())
...
@@ -169,22 +183,26 @@ type buildStoreWalletTxDetailParam struct {
...
@@ -169,22 +183,26 @@ type buildStoreWalletTxDetailParam struct {
utxos
[]
*
privacytypes
.
UTXO
utxos
[]
*
privacytypes
.
UTXO
}
}
// OnAddBlockTx 响应区块交易添加的处理
func
(
policy
*
privacyPolicy
)
OnAddBlockTx
(
block
*
types
.
BlockDetail
,
tx
*
types
.
Transaction
,
index
int32
,
dbbatch
db
.
Batch
)
*
types
.
WalletTxDetail
{
func
(
policy
*
privacyPolicy
)
OnAddBlockTx
(
block
*
types
.
BlockDetail
,
tx
*
types
.
Transaction
,
index
int32
,
dbbatch
db
.
Batch
)
*
types
.
WalletTxDetail
{
policy
.
addDelPrivacyTxsFromBlock
(
tx
,
index
,
block
,
dbbatch
,
AddTx
)
policy
.
addDelPrivacyTxsFromBlock
(
tx
,
index
,
block
,
dbbatch
,
AddTx
)
// 自己处理掉所有事务,部需要外部处理了
// 自己处理掉所有事务,部需要外部处理了
return
nil
return
nil
}
}
// OnDeleteBlockTx 响应删除区块交易的处理
func
(
policy
*
privacyPolicy
)
OnDeleteBlockTx
(
block
*
types
.
BlockDetail
,
tx
*
types
.
Transaction
,
index
int32
,
dbbatch
db
.
Batch
)
*
types
.
WalletTxDetail
{
func
(
policy
*
privacyPolicy
)
OnDeleteBlockTx
(
block
*
types
.
BlockDetail
,
tx
*
types
.
Transaction
,
index
int32
,
dbbatch
db
.
Batch
)
*
types
.
WalletTxDetail
{
policy
.
addDelPrivacyTxsFromBlock
(
tx
,
index
,
block
,
dbbatch
,
DelTx
)
policy
.
addDelPrivacyTxsFromBlock
(
tx
,
index
,
block
,
dbbatch
,
DelTx
)
// 自己处理掉所有事务,部需要外部处理了
// 自己处理掉所有事务,部需要外部处理了
return
nil
return
nil
}
}
func
(
this
*
privacyPolicy
)
GetRescanFlag
()
int32
{
// GetRescanFlag get rescan utxo flag
return
atomic
.
LoadInt32
(
&
this
.
rescanUTXOflag
)
func
(
policy
*
privacyPolicy
)
GetRescanFlag
()
int32
{
return
atomic
.
LoadInt32
(
&
policy
.
rescanUTXOflag
)
}
}
func
(
this
*
privacyPolicy
)
SetRescanFlag
(
flag
int32
)
{
// SetRescanFlag set rescan utxos flag
atomic
.
StoreInt32
(
&
this
.
rescanUTXOflag
,
flag
)
func
(
policy
*
privacyPolicy
)
SetRescanFlag
(
flag
int32
)
{
atomic
.
StoreInt32
(
&
policy
.
rescanUTXOflag
,
flag
)
}
}
plugin/dapp/privacy/wallet/privacystore.go
View file @
f08844a1
...
@@ -19,11 +19,11 @@ import (
...
@@ -19,11 +19,11 @@ import (
)
)
const
(
const
(
// 隐私交易数据库版本号
//
PRIVACYDBVERSION
隐私交易数据库版本号
PRIVACYDBVERSION
int64
=
1
PRIVACYDBVERSION
int64
=
1
)
)
func
N
ewStore
(
db
db
.
DB
)
*
privacyStore
{
func
n
ewStore
(
db
db
.
DB
)
*
privacyStore
{
return
&
privacyStore
{
Store
:
wcom
.
NewStore
(
db
)}
return
&
privacyStore
{
Store
:
wcom
.
NewStore
(
db
)}
}
}
...
...
plugin/dapp/privacy/wallet/util.go
View file @
f08844a1
...
@@ -66,30 +66,30 @@ func decomAmount2Nature(amount int64, order int64) []int64 {
...
@@ -66,30 +66,30 @@ func decomAmount2Nature(amount int64, order int64) []int64 {
return
res
return
res
}
}
// 62387455827 -> 455827 + 7000000 + 80000000 + 300000000 + 2000000000 + 60000000000, where 455827 <= dust
_t
hreshold
// 62387455827 -> 455827 + 7000000 + 80000000 + 300000000 + 2000000000 + 60000000000, where 455827 <= dust
T
hreshold
//res:[455827, 7000000, 80000000, 300000000, 2000000000, 60000000000]
//res:[455827, 7000000, 80000000, 300000000, 2000000000, 60000000000]
func
decomposeAmount2digits
(
amount
,
dust
_t
hreshold
int64
)
[]
int64
{
func
decomposeAmount2digits
(
amount
,
dust
T
hreshold
int64
)
[]
int64
{
res
:=
make
([]
int64
,
0
)
res
:=
make
([]
int64
,
0
)
if
0
>=
amount
{
if
0
>=
amount
{
return
res
return
res
}
}
is
_dust_h
andled
:=
false
is
DustH
andled
:=
false
var
dust
int64
=
0
var
dust
int64
var
order
int64
=
1
var
order
int64
=
1
var
chunk
int64
=
0
var
chunk
int64
for
0
!=
amount
{
for
0
!=
amount
{
chunk
=
(
amount
%
10
)
*
order
chunk
=
(
amount
%
10
)
*
order
amount
/=
10
amount
/=
10
order
*=
10
order
*=
10
if
dust
+
chunk
<
dust
_t
hreshold
{
if
dust
+
chunk
<
dust
T
hreshold
{
dust
+=
chunk
//累加小数,直到超过dust_threshold为止
dust
+=
chunk
//累加小数,直到超过dust_threshold为止
}
else
{
}
else
{
if
!
is
_dust_h
andled
&&
0
!=
dust
{
if
!
is
DustH
andled
&&
0
!=
dust
{
//1st 正常情况下,先把dust保存下来
//1st 正常情况下,先把dust保存下来
res
=
append
(
res
,
dust
)
res
=
append
(
res
,
dust
)
is
_dust_h
andled
=
true
is
DustH
andled
=
true
}
}
if
0
!=
chunk
{
if
0
!=
chunk
{
//2nd 然后依次将大的整数额度进行保存
//2nd 然后依次将大的整数额度进行保存
...
@@ -99,8 +99,8 @@ func decomposeAmount2digits(amount, dust_threshold int64) []int64 {
...
@@ -99,8 +99,8 @@ func decomposeAmount2digits(amount, dust_threshold int64) []int64 {
}
}
}
}
//如果需要被拆分的额度 < dust
_t
hreshold,则直接将其进行保存
//如果需要被拆分的额度 < dust
T
hreshold,则直接将其进行保存
if
!
is
_dust_h
andled
&&
0
!=
dust
{
if
!
is
DustH
andled
&&
0
!=
dust
{
res
=
append
(
res
,
dust
)
res
=
append
(
res
,
dust
)
}
}
...
...
plugin/dapp/privacy/wallet/util_test.go
View file @
f08844a1
...
@@ -99,32 +99,32 @@ func Test_decomAmount2Nature(t *testing.T) {
...
@@ -99,32 +99,32 @@ func Test_decomAmount2Nature(t *testing.T) {
func
Test_decomposeAmount2digits
(
t
*
testing
.
T
)
{
func
Test_decomposeAmount2digits
(
t
*
testing
.
T
)
{
testCase
:=
[]
struct
{
testCase
:=
[]
struct
{
amount
int64
amount
int64
dust
_t
hreshold
int64
dust
T
hreshold
int64
actual
[]
int64
actual
[]
int64
}{
}{
{
{
amount
:
0
,
amount
:
0
,
dust
_t
hreshold
:
0
,
dust
T
hreshold
:
0
,
actual
:
[]
int64
{},
actual
:
[]
int64
{},
},
},
{
{
amount
:
-
1
,
amount
:
-
1
,
dust
_t
hreshold
:
0
,
dust
T
hreshold
:
0
,
actual
:
[]
int64
{},
actual
:
[]
int64
{},
},
},
{
{
amount
:
2
,
amount
:
2
,
dust
_t
hreshold
:
1
,
dust
T
hreshold
:
1
,
actual
:
[]
int64
{
2
},
actual
:
[]
int64
{
2
},
},
},
{
{
amount
:
62387455827
,
amount
:
62387455827
,
dust
_t
hreshold
:
types
.
BTYDustThreshold
,
dust
T
hreshold
:
types
.
BTYDustThreshold
,
actual
:
[]
int64
{
87455827
,
1e8
,
2e8
,
2e9
,
5e10
,
1e10
},
actual
:
[]
int64
{
87455827
,
1e8
,
2e8
,
2e9
,
5e10
,
1e10
},
},
},
}
}
for
_
,
test
:=
range
testCase
{
for
_
,
test
:=
range
testCase
{
res
:=
decomposeAmount2digits
(
test
.
amount
,
test
.
dust
_t
hreshold
)
res
:=
decomposeAmount2digits
(
test
.
amount
,
test
.
dust
T
hreshold
)
require
.
Equal
(
t
,
res
,
test
.
actual
)
require
.
Equal
(
t
,
res
,
test
.
actual
)
}
}
}
}
...
...
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