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
23751000
Commit
23751000
authored
Jan 12, 2021
by
madengji
Committed by
vipwzw
Sep 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mix wallet base pass
parent
1ea44029
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
67 additions
and
38 deletions
+67
-38
mix.go
plugin/dapp/mix/commands/mix.go
+28
-0
mixlocaldb.go
plugin/dapp/mix/executor/mixlocaldb.go
+9
-14
mixtxtable.go
plugin/dapp/mix/executor/mixtxtable.go
+2
-2
mix.proto
plugin/dapp/mix/proto/mix.proto
+8
-8
mix.pb.go
plugin/dapp/mix/types/mix.pb.go
+0
-0
mix.go
plugin/dapp/mix/wallet/mix.go
+6
-2
mixbizdb.go
plugin/dapp/mix/wallet/mixbizdb.go
+9
-9
mixbizdb_test.go
plugin/dapp/mix/wallet/mixbizdb_test.go
+1
-1
mixbizpolicy.go
plugin/dapp/mix/wallet/mixbizpolicy.go
+1
-1
mixbiztable.go
plugin/dapp/mix/wallet/mixbiztable.go
+3
-1
No files found.
plugin/dapp/mix/commands/mix.go
View file @
23751000
...
...
@@ -60,6 +60,19 @@ func addCreateDepositFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
Uint64P
(
"amount"
,
"a"
,
0
,
"deposit amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"secretPayment"
,
"s"
,
""
,
"secret for payment addr"
)
cmd
.
MarkFlagRequired
(
"secretPayment"
)
cmd
.
Flags
()
.
StringP
(
"pubX"
,
"x"
,
""
,
"receiving pub key X"
)
cmd
.
MarkFlagRequired
(
"pubX"
)
cmd
.
Flags
()
.
StringP
(
"pubY"
,
"y"
,
""
,
"receiving pub key Y"
)
cmd
.
MarkFlagRequired
(
"pubY"
)
cmd
.
Flags
()
.
StringP
(
"secretAuth"
,
"u"
,
""
,
"secret for authorize addr"
)
cmd
.
Flags
()
.
StringP
(
"secretReturn"
,
"r"
,
""
,
"secret for return addr"
)
}
func
parseProofPara
(
input
string
)
([]
*
mixTy
.
ZkProofInfo
,
error
)
{
...
...
@@ -83,15 +96,30 @@ func createDeposit(cmd *cobra.Command, args []string) {
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"amount"
)
proofsPara
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proofs"
)
secretPayment
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secretPayment"
)
pubX
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubX"
)
pubY
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubY"
)
proofInputs
,
err
:=
parseProofPara
(
proofsPara
)
if
err
!=
nil
{
return
}
var
pubkey
mixTy
.
PubKey
pubkey
.
X
=
pubX
pubkey
.
Y
=
pubY
var
paySecret
mixTy
.
DHSecret
paySecret
.
Secret
=
secretPayment
paySecret
.
Epk
=
&
pubkey
var
group
mixTy
.
DHSecretGroup
group
.
Spender
=
&
paySecret
payload
:=
&
mixTy
.
MixDepositAction
{}
payload
.
Amount
=
amount
payload
.
NewCommits
=
append
(
payload
.
NewCommits
,
proofInputs
...
)
payload
.
NewCommits
[
0
]
.
Group
=
&
group
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
getRealExecName
(
paraName
,
mixTy
.
MixX
),
ActionName
:
"Deposit"
,
...
...
plugin/dapp/mix/executor/mixlocaldb.go
View file @
23751000
...
...
@@ -27,7 +27,7 @@ func (e *Mix) execLocalMix(tx *types.Transaction, receiptData *types.ReceiptData
table
:=
NewMixTxTable
(
e
.
GetLocalDB
())
r
:=
&
mixTy
.
LocalMixTx
{
Hash
:
tx
.
Hash
(
),
Hash
:
common
.
ToHex
(
tx
.
Hash
()
),
Height
:
e
.
GetHeight
(),
Index
:
int64
(
index
),
}
...
...
@@ -66,29 +66,24 @@ func (e *Mix) listMixInfos(req *mixTy.MixTxListReq) (types.Message, error) {
primary
=
[]
byte
(
req
.
TxIndex
)
}
cur
:=
&
MixTxRow
{}
indexName
:=
"height"
var
prefix
[]
byte
info
:=
&
mixTy
.
LocalMixTx
{
Height
:
req
.
Height
,
Index
:
req
.
Index
}
if
len
(
req
.
Hash
)
>
0
{
hash
,
err
:=
common
.
FromHex
(
req
.
Hash
)
info
.
Hash
=
req
.
Hash
indexName
=
"hash"
var
err
error
prefix
,
err
=
cur
.
Get
(
indexName
)
if
err
!=
nil
{
mlog
.
Error
(
"listMixInfos
fromHex"
,
"hash"
,
req
.
Hash
,
"err"
,
err
)
mlog
.
Error
(
"listMixInfos
Get"
,
"indexName"
,
indexName
,
"err"
,
err
)
return
nil
,
err
}
info
.
Hash
=
hash
indexName
=
"hash"
}
cur
:=
&
MixTxRow
{}
cur
.
SetPayload
(
info
)
prefix
,
err
:=
cur
.
Get
(
indexName
)
if
err
!=
nil
{
mlog
.
Error
(
"listMixInfos Get"
,
"indexName"
,
indexName
,
"err"
,
err
)
return
nil
,
err
}
rows
,
err
:=
query
.
ListIndex
(
indexName
,
prefix
,
primary
,
req
.
Count
,
req
.
Direction
)
if
err
!=
nil
{
mlog
.
Error
(
"listMixInfos query failed"
,
"indexName"
,
indexName
,
"prefix"
,
prefix
,
"key"
,
string
(
primary
),
"err"
,
err
)
mlog
.
Error
(
"listMixInfos query failed"
,
"indexName"
,
indexName
,
"prefix"
,
string
(
prefix
)
,
"key"
,
string
(
primary
),
"err"
,
err
)
return
nil
,
err
}
if
len
(
rows
)
==
0
{
...
...
plugin/dapp/mix/executor/mixtxtable.go
View file @
23751000
...
...
@@ -18,7 +18,7 @@ index: status
*/
var
txBoardOpt
=
&
table
.
Option
{
Prefix
:
"LODB-mix
coin
"
,
Prefix
:
"LODB-mix"
,
Name
:
"tx"
,
Primary
:
"txIndex"
,
Index
:
[]
string
{
"height"
,
"hash"
},
...
...
@@ -66,7 +66,7 @@ func (r *MixTxRow) Get(key string) ([]byte, error) {
case
"height"
:
return
[]
byte
(
fmt
.
Sprintf
(
"%022d"
,
r
.
Height
)),
nil
case
"hash"
:
return
r
.
Hash
,
nil
return
[]
byte
(
r
.
Hash
)
,
nil
default
:
return
nil
,
types
.
ErrNotFound
...
...
plugin/dapp/mix/proto/mix.proto
View file @
23751000
...
...
@@ -267,13 +267,13 @@ enum NoteStatus{
}
message
WalletIndexInfo
{
string
noteHash
=
1
;
string
nullifier
=
2
;
string
authSpendHash
=
3
;
string
spender
=
4
;
string
account
=
5
;
//账户地址
NoteStatus
status
=
6
;
SecretData
note
=
7
;
string
noteHash
=
1
;
string
nullifier
=
2
;
string
authSpendHash
=
3
;
string
spender
=
4
;
string
account
=
5
;
//账户地址
NoteStatus
status
=
6
;
SecretData
secret
=
7
;
}
...
...
@@ -322,7 +322,7 @@ enum MixWalletRescanStatus{
///////localdb index query
message
LocalMixTx
{
bytes
hash
=
1
;
string
hash
=
1
;
int64
height
=
2
;
int64
index
=
3
;
}
...
...
plugin/dapp/mix/types/mix.pb.go
View file @
23751000
This diff is collapsed.
Click to expand it.
plugin/dapp/mix/wallet/mix.go
View file @
23751000
...
...
@@ -292,7 +292,7 @@ func (policy *mixPolicy) rescanNotes() {
}
mixTxInfos
:=
msg
.
(
*
mixTy
.
MixTxListResp
)
if
mixTxInfos
==
nil
{
bizlog
.
Info
(
"privacy ReqTxInfosByAddr ReplyTxInfos is nil"
)
bizlog
.
Info
(
"
rescanNotes mix
privacy ReqTxInfosByAddr ReplyTxInfos is nil"
)
break
}
txcount
:=
len
(
mixTxInfos
.
Txs
)
...
...
@@ -300,7 +300,11 @@ func (policy *mixPolicy) rescanNotes() {
var
ReqHashes
types
.
ReqHashes
ReqHashes
.
Hashes
=
make
([][]
byte
,
len
(
mixTxInfos
.
Txs
))
for
index
,
tx
:=
range
mixTxInfos
.
Txs
{
ReqHashes
.
Hashes
[
index
]
=
tx
.
GetHash
()
hash
,
err
:=
common
.
FromHex
(
tx
.
Hash
)
if
err
!=
nil
{
bizlog
.
Error
(
"rescanNotes mix decode hash"
,
"hash"
,
tx
.
Hash
)
}
ReqHashes
.
Hashes
[
index
]
=
hash
}
if
txcount
>
0
{
...
...
plugin/dapp/mix/wallet/mixbizdb.go
View file @
23751000
...
...
@@ -5,7 +5,7 @@
package
wallet
import
(
"
encoding/hex
"
"
github.com/33cn/chain33/common
"
commondb
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
...
...
@@ -46,7 +46,7 @@ func (p *mixPolicy) processMixTx(tx *types.Transaction, height, index int64) (*t
return
nil
,
types
.
ErrInvalidParam
}
table
:=
NewMixTable
(
p
.
getWalletOperate
()
.
GetDBStore
(
))
table
:=
NewMixTable
(
commondb
.
NewKVDB
(
p
.
getWalletOperate
()
.
GetDBStore
()
))
switch
v
.
GetTy
()
{
//deposit 匹配newcommits,属于自己的存到数据库
case
mixTy
.
MixActionDeposit
:
...
...
@@ -227,12 +227,12 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
}
var
rep
mixTy
.
WalletIndexResp
for
_
,
row
:=
range
rows
{
r
,
ok
:=
row
.
Data
.
(
*
mixTy
.
Wallet
Inde
xInfo
)
r
,
ok
:=
row
.
Data
.
(
*
mixTy
.
Wallet
DbMi
xInfo
)
if
!
ok
{
bizlog
.
Error
(
"listMixInfos"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrDecode
}
rep
.
Datas
=
append
(
rep
.
Datas
,
r
)
rep
.
Datas
=
append
(
rep
.
Datas
,
r
.
Info
)
}
return
&
rep
,
nil
}
...
...
@@ -273,7 +273,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
//可能自己账户里面既有spender,也有returner 或authorize,都要解一遍
info
,
err
:=
p
.
decodeSecret
(
noteHash
,
secretGroup
.
Spender
,
privacyKeys
)
if
err
!=
nil
{
bizlog
.
Info
(
"processSecretGroup.spender"
,
"err"
,
err
)
bizlog
.
Error
(
"processSecretGroup.spender"
,
"err"
,
err
)
}
if
info
!=
nil
{
p
.
addTable
(
info
,
heightIndex
,
table
)
...
...
@@ -281,7 +281,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
info
,
err
=
p
.
decodeSecret
(
noteHash
,
secretGroup
.
Returner
,
privacyKeys
)
if
err
!=
nil
{
bizlog
.
Info
(
"processSecretGroup.Returner"
,
"err"
,
err
)
bizlog
.
Error
(
"processSecretGroup.Returner"
,
"err"
,
err
)
}
if
info
!=
nil
{
p
.
addTable
(
info
,
heightIndex
,
table
)
...
...
@@ -289,7 +289,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
info
,
err
=
p
.
decodeSecret
(
noteHash
,
secretGroup
.
Authorize
,
privacyKeys
)
if
err
!=
nil
{
bizlog
.
Info
(
"processSecretGroup.Authorize"
,
"err"
,
err
)
bizlog
.
Error
(
"processSecretGroup.Authorize"
,
"err"
,
err
)
}
if
info
!=
nil
{
p
.
addTable
(
info
,
heightIndex
,
table
)
...
...
@@ -304,7 +304,7 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv
tempPubKey
:=
&
mixTy
.
PubKey
{
X
:
dhSecret
.
Epk
.
X
,
Y
:
dhSecret
.
Epk
.
Y
}
for
_
,
key
:=
range
privacyKeys
{
cryptData
,
err
:=
hex
.
DecodeString
(
dhSecret
.
Secret
)
cryptData
,
err
:=
common
.
FromHex
(
dhSecret
.
Secret
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"decode for notehash=%s,crypt=%s"
,
noteHash
,
dhSecret
.
Secret
)
}
...
...
@@ -341,7 +341,7 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv
}
//账户地址
info
.
Account
=
key
.
Addr
info
.
Secret
=
&
rawData
return
&
info
,
nil
}
...
...
plugin/dapp/mix/wallet/mixbizdb_test.go
View file @
23751000
...
...
@@ -93,7 +93,7 @@ func TestEncodeSecretData(t *testing.T) {
privacy
,
err
:=
newPrivacyWithPrivKey
(
keyByte
)
assert
.
Equal
(
t
,
nil
,
err
)
req
:=
&
mixTy
.
EncryptSecretData
{
ReceivingPk
:
privacy
.
ShareSecretKey
.
ReceivingPk
,
Secret
:
ret
.
Encode
}
req
:=
&
mixTy
.
EncryptSecretData
{
ReceivingPk
:
privacy
.
ShareSecretKey
.
ReceivingPk
,
Secret
:
ret
.
Encode
d
}
dhSecret
,
err
:=
encryptSecretData
(
req
)
assert
.
Nil
(
t
,
err
)
t
.
Log
(
dhSecret
)
...
...
plugin/dapp/mix/wallet/mixbizpolicy.go
View file @
23751000
...
...
@@ -141,5 +141,5 @@ func (policy *mixPolicy) Call(funName string, in types.Message) (ret types.Messa
// SignTransaction 对隐私交易进行签名
func
(
policy
*
mixPolicy
)
SignTransaction
(
key
crypto
.
PrivKey
,
req
*
types
.
ReqSignRawTx
)
(
needSysSign
bool
,
signtxhex
string
,
err
error
)
{
return
fals
e
,
""
,
types
.
ErrNotSupport
return
tru
e
,
""
,
types
.
ErrNotSupport
}
plugin/dapp/mix/wallet/mixbiztable.go
View file @
23751000
...
...
@@ -16,7 +16,7 @@ index: status
*/
var
boardOpt
=
&
table
.
Option
{
Prefix
:
"LODB-mix
coin
"
,
Prefix
:
"LODB-mix"
,
Name
:
"wallet"
,
Primary
:
"heightindex"
,
Index
:
[]
string
{
...
...
@@ -69,6 +69,8 @@ func (r *MixRow) Get(key string) ([]byte, error) {
return
[]
byte
(
r
.
TxIndex
),
nil
case
"noteHash"
:
return
[]
byte
(
r
.
Info
.
NoteHash
),
nil
case
"nullifier"
:
return
[]
byte
(
r
.
Info
.
Nullifier
),
nil
case
"authSpendHash"
:
return
[]
byte
(
r
.
Info
.
AuthSpendHash
),
nil
case
"spender"
:
...
...
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