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) {
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",
......
......@@ -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 {
......
......@@ -18,7 +18,7 @@ index: status
*/
var txBoardOpt = &table.Option{
Prefix: "LODB-mixcoin",
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
......
......@@ -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;
}
......
This diff is collapsed.
......@@ -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 {
......
......@@ -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.WalletIndexInfo)
r, ok := row.Data.(*mixTy.WalletDbMixInfo)
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
}
......
......@@ -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.Encoded}
dhSecret, err := encryptSecretData(req)
assert.Nil(t, err)
t.Log(dhSecret)
......
......@@ -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 false, "", types.ErrNotSupport
return true, "", types.ErrNotSupport
}
......@@ -16,7 +16,7 @@ index: status
*/
var boardOpt = &table.Option{
Prefix: "LODB-mixcoin",
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":
......
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