Commit 23751000 authored by madengji's avatar madengji Committed by vipwzw

mix wallet base pass

parent 1ea44029
...@@ -60,6 +60,19 @@ func addCreateDepositFlags(cmd *cobra.Command) { ...@@ -60,6 +60,19 @@ func addCreateDepositFlags(cmd *cobra.Command) {
cmd.Flags().Uint64P("amount", "a", 0, "deposit amount") cmd.Flags().Uint64P("amount", "a", 0, "deposit amount")
cmd.MarkFlagRequired("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) { func parseProofPara(input string) ([]*mixTy.ZkProofInfo, error) {
...@@ -83,15 +96,30 @@ func createDeposit(cmd *cobra.Command, args []string) { ...@@ -83,15 +96,30 @@ func createDeposit(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
amount, _ := cmd.Flags().GetUint64("amount") amount, _ := cmd.Flags().GetUint64("amount")
proofsPara, _ := cmd.Flags().GetString("proofs") proofsPara, _ := cmd.Flags().GetString("proofs")
secretPayment, _ := cmd.Flags().GetString("secretPayment")
pubX, _ := cmd.Flags().GetString("pubX")
pubY, _ := cmd.Flags().GetString("pubY")
proofInputs, err := parseProofPara(proofsPara) proofInputs, err := parseProofPara(proofsPara)
if err != nil { if err != nil {
return 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 := &mixTy.MixDepositAction{}
payload.Amount = amount payload.Amount = amount
payload.NewCommits = append(payload.NewCommits, proofInputs...) payload.NewCommits = append(payload.NewCommits, proofInputs...)
payload.NewCommits[0].Group = &group
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, mixTy.MixX), Execer: getRealExecName(paraName, mixTy.MixX),
ActionName: "Deposit", ActionName: "Deposit",
......
...@@ -27,7 +27,7 @@ func (e *Mix) execLocalMix(tx *types.Transaction, receiptData *types.ReceiptData ...@@ -27,7 +27,7 @@ func (e *Mix) execLocalMix(tx *types.Transaction, receiptData *types.ReceiptData
table := NewMixTxTable(e.GetLocalDB()) table := NewMixTxTable(e.GetLocalDB())
r := &mixTy.LocalMixTx{ r := &mixTy.LocalMixTx{
Hash: tx.Hash(), Hash: common.ToHex(tx.Hash()),
Height: e.GetHeight(), Height: e.GetHeight(),
Index: int64(index), Index: int64(index),
} }
...@@ -66,29 +66,24 @@ func (e *Mix) listMixInfos(req *mixTy.MixTxListReq) (types.Message, error) { ...@@ -66,29 +66,24 @@ func (e *Mix) listMixInfos(req *mixTy.MixTxListReq) (types.Message, error) {
primary = []byte(req.TxIndex) primary = []byte(req.TxIndex)
} }
cur := &MixTxRow{}
indexName := "height" indexName := "height"
var prefix []byte
info := &mixTy.LocalMixTx{Height: req.Height, Index: req.Index} info := &mixTy.LocalMixTx{Height: req.Height, Index: req.Index}
if len(req.Hash) > 0 { 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 { if err != nil {
mlog.Error("listMixInfos fromHex", "hash", req.Hash, "err", err) mlog.Error("listMixInfos Get", "indexName", indexName, "err", err)
return nil, err return nil, err
} }
info.Hash = hash
indexName = "hash"
} }
cur := &MixTxRow{}
cur.SetPayload(info) 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) rows, err := query.ListIndex(indexName, prefix, primary, req.Count, req.Direction)
if err != nil { 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 return nil, err
} }
if len(rows) == 0 { if len(rows) == 0 {
......
...@@ -18,7 +18,7 @@ index: status ...@@ -18,7 +18,7 @@ index: status
*/ */
var txBoardOpt = &table.Option{ var txBoardOpt = &table.Option{
Prefix: "LODB-mixcoin", Prefix: "LODB-mix",
Name: "tx", Name: "tx",
Primary: "txIndex", Primary: "txIndex",
Index: []string{"height", "hash"}, Index: []string{"height", "hash"},
...@@ -66,7 +66,7 @@ func (r *MixTxRow) Get(key string) ([]byte, error) { ...@@ -66,7 +66,7 @@ func (r *MixTxRow) Get(key string) ([]byte, error) {
case "height": case "height":
return []byte(fmt.Sprintf("%022d", r.Height)), nil return []byte(fmt.Sprintf("%022d", r.Height)), nil
case "hash": case "hash":
return r.Hash, nil return []byte(r.Hash), nil
default: default:
return nil, types.ErrNotFound return nil, types.ErrNotFound
......
...@@ -267,13 +267,13 @@ enum NoteStatus{ ...@@ -267,13 +267,13 @@ enum NoteStatus{
} }
message WalletIndexInfo { message WalletIndexInfo {
string noteHash = 1; string noteHash = 1;
string nullifier = 2; string nullifier = 2;
string authSpendHash = 3; string authSpendHash = 3;
string spender = 4; string spender = 4;
string account = 5; //账户地址 string account = 5; //账户地址
NoteStatus status = 6; NoteStatus status = 6;
SecretData note = 7; SecretData secret = 7;
} }
...@@ -322,7 +322,7 @@ enum MixWalletRescanStatus{ ...@@ -322,7 +322,7 @@ enum MixWalletRescanStatus{
///////localdb index query ///////localdb index query
message LocalMixTx { message LocalMixTx {
bytes hash = 1; string hash = 1;
int64 height = 2; int64 height = 2;
int64 index = 3; int64 index = 3;
} }
......
This diff is collapsed.
...@@ -292,7 +292,7 @@ func (policy *mixPolicy) rescanNotes() { ...@@ -292,7 +292,7 @@ func (policy *mixPolicy) rescanNotes() {
} }
mixTxInfos := msg.(*mixTy.MixTxListResp) mixTxInfos := msg.(*mixTy.MixTxListResp)
if mixTxInfos == nil { if mixTxInfos == nil {
bizlog.Info("privacy ReqTxInfosByAddr ReplyTxInfos is nil") bizlog.Info("rescanNotes mix privacy ReqTxInfosByAddr ReplyTxInfos is nil")
break break
} }
txcount := len(mixTxInfos.Txs) txcount := len(mixTxInfos.Txs)
...@@ -300,7 +300,11 @@ func (policy *mixPolicy) rescanNotes() { ...@@ -300,7 +300,11 @@ func (policy *mixPolicy) rescanNotes() {
var ReqHashes types.ReqHashes var ReqHashes types.ReqHashes
ReqHashes.Hashes = make([][]byte, len(mixTxInfos.Txs)) ReqHashes.Hashes = make([][]byte, len(mixTxInfos.Txs))
for index, tx := range 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 { if txcount > 0 {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package wallet package wallet
import ( import (
"encoding/hex" "github.com/33cn/chain33/common"
commondb "github.com/33cn/chain33/common/db" commondb "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table" "github.com/33cn/chain33/common/db/table"
...@@ -46,7 +46,7 @@ func (p *mixPolicy) processMixTx(tx *types.Transaction, height, index int64) (*t ...@@ -46,7 +46,7 @@ func (p *mixPolicy) processMixTx(tx *types.Transaction, height, index int64) (*t
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
table := NewMixTable(p.getWalletOperate().GetDBStore()) table := NewMixTable(commondb.NewKVDB(p.getWalletOperate().GetDBStore()))
switch v.GetTy() { switch v.GetTy() {
//deposit 匹配newcommits,属于自己的存到数据库 //deposit 匹配newcommits,属于自己的存到数据库
case mixTy.MixActionDeposit: case mixTy.MixActionDeposit:
...@@ -227,12 +227,12 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e ...@@ -227,12 +227,12 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
} }
var rep mixTy.WalletIndexResp var rep mixTy.WalletIndexResp
for _, row := range rows { for _, row := range rows {
r, ok := row.Data.(*mixTy.WalletIndexInfo) r, ok := row.Data.(*mixTy.WalletDbMixInfo)
if !ok { if !ok {
bizlog.Error("listMixInfos", "err", "bad row type") bizlog.Error("listMixInfos", "err", "bad row type")
return nil, types.ErrDecode return nil, types.ErrDecode
} }
rep.Datas = append(rep.Datas, r) rep.Datas = append(rep.Datas, r.Info)
} }
return &rep, nil return &rep, nil
} }
...@@ -273,7 +273,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec ...@@ -273,7 +273,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
//可能自己账户里面既有spender,也有returner 或authorize,都要解一遍 //可能自己账户里面既有spender,也有returner 或authorize,都要解一遍
info, err := p.decodeSecret(noteHash, secretGroup.Spender, privacyKeys) info, err := p.decodeSecret(noteHash, secretGroup.Spender, privacyKeys)
if err != nil { if err != nil {
bizlog.Info("processSecretGroup.spender", "err", err) bizlog.Error("processSecretGroup.spender", "err", err)
} }
if info != nil { if info != nil {
p.addTable(info, heightIndex, table) p.addTable(info, heightIndex, table)
...@@ -281,7 +281,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec ...@@ -281,7 +281,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
info, err = p.decodeSecret(noteHash, secretGroup.Returner, privacyKeys) info, err = p.decodeSecret(noteHash, secretGroup.Returner, privacyKeys)
if err != nil { if err != nil {
bizlog.Info("processSecretGroup.Returner", "err", err) bizlog.Error("processSecretGroup.Returner", "err", err)
} }
if info != nil { if info != nil {
p.addTable(info, heightIndex, table) p.addTable(info, heightIndex, table)
...@@ -289,7 +289,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec ...@@ -289,7 +289,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
info, err = p.decodeSecret(noteHash, secretGroup.Authorize, privacyKeys) info, err = p.decodeSecret(noteHash, secretGroup.Authorize, privacyKeys)
if err != nil { if err != nil {
bizlog.Info("processSecretGroup.Authorize", "err", err) bizlog.Error("processSecretGroup.Authorize", "err", err)
} }
if info != nil { if info != nil {
p.addTable(info, heightIndex, table) p.addTable(info, heightIndex, table)
...@@ -304,7 +304,7 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv ...@@ -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} tempPubKey := &mixTy.PubKey{X: dhSecret.Epk.X, Y: dhSecret.Epk.Y}
for _, key := range privacyKeys { for _, key := range privacyKeys {
cryptData, err := hex.DecodeString(dhSecret.Secret) cryptData, err := common.FromHex(dhSecret.Secret)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "decode for notehash=%s,crypt=%s", noteHash, dhSecret.Secret) 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 ...@@ -341,7 +341,7 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv
} }
//账户地址 //账户地址
info.Account = key.Addr info.Account = key.Addr
info.Secret = &rawData
return &info, nil return &info, nil
} }
......
...@@ -93,7 +93,7 @@ func TestEncodeSecretData(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestEncodeSecretData(t *testing.T) {
privacy, err := newPrivacyWithPrivKey(keyByte) privacy, err := newPrivacyWithPrivKey(keyByte)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
req := &mixTy.EncryptSecretData{ReceivingPk: privacy.ShareSecretKey.ReceivingPk, Secret: ret.Encode} req := &mixTy.EncryptSecretData{ReceivingPk: privacy.ShareSecretKey.ReceivingPk, Secret: ret.Encoded}
dhSecret, err := encryptSecretData(req) dhSecret, err := encryptSecretData(req)
assert.Nil(t, err) assert.Nil(t, err)
t.Log(dhSecret) t.Log(dhSecret)
......
...@@ -141,5 +141,5 @@ func (policy *mixPolicy) Call(funName string, in types.Message) (ret types.Messa ...@@ -141,5 +141,5 @@ func (policy *mixPolicy) Call(funName string, in types.Message) (ret types.Messa
// SignTransaction 对隐私交易进行签名 // SignTransaction 对隐私交易进行签名
func (policy *mixPolicy) SignTransaction(key crypto.PrivKey, req *types.ReqSignRawTx) (needSysSign bool, signtxhex string, err error) { func (policy *mixPolicy) SignTransaction(key crypto.PrivKey, req *types.ReqSignRawTx) (needSysSign bool, signtxhex string, err error) {
return false, "", types.ErrNotSupport return true, "", types.ErrNotSupport
} }
...@@ -16,7 +16,7 @@ index: status ...@@ -16,7 +16,7 @@ index: status
*/ */
var boardOpt = &table.Option{ var boardOpt = &table.Option{
Prefix: "LODB-mixcoin", Prefix: "LODB-mix",
Name: "wallet", Name: "wallet",
Primary: "heightindex", Primary: "heightindex",
Index: []string{ Index: []string{
...@@ -69,6 +69,8 @@ func (r *MixRow) Get(key string) ([]byte, error) { ...@@ -69,6 +69,8 @@ func (r *MixRow) Get(key string) ([]byte, error) {
return []byte(r.TxIndex), nil return []byte(r.TxIndex), nil
case "noteHash": case "noteHash":
return []byte(r.Info.NoteHash), nil return []byte(r.Info.NoteHash), nil
case "nullifier":
return []byte(r.Info.Nullifier), nil
case "authSpendHash": case "authSpendHash":
return []byte(r.Info.AuthSpendHash), nil return []byte(r.Info.AuthSpendHash), nil
case "spender": case "spender":
......
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