Commit 0559134e authored by jiangpeng's avatar jiangpeng Committed by vipwzw

privacy:update privacy tx storing

* add pub2priv tx db index * refactor add del block tx in wallet
parent 22f27b21
This diff is collapsed.
...@@ -181,7 +181,7 @@ func (mock *PrivacyMock) CreateUTXOs(sender string, pubkeypair string, amount in ...@@ -181,7 +181,7 @@ func (mock *PrivacyMock) CreateUTXOs(sender string, pubkeypair string, amount in
} }
utxos = append(utxos, utxoCreated) utxos = append(utxos, utxoCreated)
mock.store.setUTXO(info.Addr, &txhashstr, indexoutput, info2store, dbbatch) mock.store.setUTXO(info2store, txhashstr, dbbatch)
} }
} }
} }
......
...@@ -170,18 +170,28 @@ func (policy *privacyPolicy) SignTransaction(key crypto.PrivKey, req *types.ReqS ...@@ -170,18 +170,28 @@ func (policy *privacyPolicy) SignTransaction(key crypto.PrivKey, req *types.ReqS
return return
} }
type buildStoreWalletTxDetailParam struct { type privacyTxInfo struct {
assetExec string
tokenname string
block *types.BlockDetail
tx *types.Transaction tx *types.Transaction
index int blockDetail *types.BlockDetail
newbatch db.Batch actionTy int32
senderRecver string actionName string
isprivacy bool input *privacytypes.PrivacyInput
addDelType int32 output *privacytypes.PrivacyOutput
txIndex int32
blockHeight int64
isExecOk bool
isRollBack bool
txHash []byte
txHashHex string
assetExec string
assetSymbol string
batch db.Batch
}
type buildStoreWalletTxDetailParam struct {
txInfo *privacyTxInfo
addr string
sendRecvFlag int32 sendRecvFlag int32
utxos []*privacytypes.UTXO
} }
// OnAddBlockTx 响应区块交易添加的处理 // OnAddBlockTx 响应区块交易添加的处理
......
...@@ -642,7 +642,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti ...@@ -642,7 +642,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
} }
utxos = append(utxos, utxoCreated) utxos = append(utxos, utxoCreated)
store.setUTXO(info.Addr, &txhash, indexoutput, info2store, newbatch) store.setUTXO(info2store, txhash, newbatch)
} }
} }
} }
...@@ -671,25 +671,17 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti ...@@ -671,25 +671,17 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
//UTXO---->moveUTXO2FTXO---->FTXO---->moveFTXO2STXO---->STXO //UTXO---->moveUTXO2FTXO---->FTXO---->moveFTXO2STXO---->STXO
//1.calcUTXOKey------------>types.PrivacyDBStore 该kv值在db中的存储一旦写入就不再改变,除非产生该UTXO的交易被撤销 //1.calcUTXOKey------------>types.PrivacyDBStore 该kv值在db中的存储一旦写入就不再改变,除非产生该UTXO的交易被撤销
//2.calcUTXOKey4TokenAddr-->calcUTXOKey,创建kv,方便查询现在某个地址下某种token的可用utxo //2.calcUTXOKey4TokenAddr-->calcUTXOKey,创建kv,方便查询现在某个地址下某种token的可用utxo
func (store *privacyStore) setUTXO(addr, txhash *string, outindex int, dbStore *privacytypes.PrivacyDBStore, newbatch db.Batch) error { func (store *privacyStore) setUTXO(utxoInfo *privacytypes.PrivacyDBStore, txHash string, newbatch db.Batch) error {
if 0 == len(*addr) || 0 == len(*txhash) {
bizlog.Error("setUTXO addr or txhash is nil")
return types.ErrInvalidParam
}
if dbStore == nil {
bizlog.Error("setUTXO privacy is nil")
return types.ErrInvalidParam
}
privacyStorebyte, err := proto.Marshal(dbStore) privacyStorebyte, err := proto.Marshal(utxoInfo)
if err != nil { if err != nil {
bizlog.Error("setUTXO proto.Marshal err!", "err", err) bizlog.Error("setUTXO proto.Marshal err!", "err", err)
return types.ErrMarshal return types.ErrMarshal
} }
outIndex := int(utxoInfo.OutIndex)
utxoKey := calcUTXOKey(*txhash, outindex) utxoKey := calcUTXOKey(txHash, outIndex)
bizlog.Debug("setUTXO", "addr", *addr, "tx with hash", *txhash, "amount:", dbStore.Amount/types.Coin) bizlog.Debug("setUTXO", "addr", utxoInfo.Owner, "tx with hash", txHash, "amount:", utxoInfo.Amount/types.Coin)
newbatch.Set(calcUTXOKey4TokenAddr(dbStore.AssetExec, dbStore.Tokenname, *addr, *txhash, outindex), utxoKey) newbatch.Set(calcUTXOKey4TokenAddr(utxoInfo.AssetExec, utxoInfo.Tokenname, utxoInfo.Owner, txHash, outIndex), utxoKey)
newbatch.Set(utxoKey, privacyStorebyte) newbatch.Set(utxoKey, privacyStorebyte)
return nil return nil
} }
......
...@@ -117,16 +117,11 @@ func testStore_storeScanPrivacyInputUTXO(t *testing.T) { ...@@ -117,16 +117,11 @@ func testStore_storeScanPrivacyInputUTXO(t *testing.T) {
} }
func testStore_setUTXO(t *testing.T) { func testStore_setUTXO(t *testing.T) {
var addr, txhash string var txhash string
store := createStore(t) store := createStore(t)
dbbatch := store.NewBatch(true) dbbatch := store.NewBatch(true)
err := store.setUTXO(&addr, &txhash, 0, nil, dbbatch) err := store.setUTXO(&pt.PrivacyDBStore{}, txhash, dbbatch)
assert.NotNil(t, err) assert.Nil(t, err)
addr = "setUTXO"
txhash = "TXHASH"
err = store.setUTXO(&addr, &txhash, 0, nil, dbbatch)
assert.NotNil(t, err)
} }
func testStore_selectPrivacyTransactionToWallet(t *testing.T) { func testStore_selectPrivacyTransactionToWallet(t *testing.T) {
......
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