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
}
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
return
}
type privacyTxInfo struct {
tx *types.Transaction
blockDetail *types.BlockDetail
actionTy int32
actionName string
input *privacytypes.PrivacyInput
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 {
assetExec string
tokenname string
block *types.BlockDetail
tx *types.Transaction
index int
newbatch db.Batch
senderRecver string
isprivacy bool
addDelType int32
txInfo *privacyTxInfo
addr string
sendRecvFlag int32
utxos []*privacytypes.UTXO
}
// OnAddBlockTx 响应区块交易添加的处理
......
......@@ -642,7 +642,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
}
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
//UTXO---->moveUTXO2FTXO---->FTXO---->moveFTXO2STXO---->STXO
//1.calcUTXOKey------------>types.PrivacyDBStore 该kv值在db中的存储一旦写入就不再改变,除非产生该UTXO的交易被撤销
//2.calcUTXOKey4TokenAddr-->calcUTXOKey,创建kv,方便查询现在某个地址下某种token的可用utxo
func (store *privacyStore) setUTXO(addr, txhash *string, outindex int, dbStore *privacytypes.PrivacyDBStore, 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
}
func (store *privacyStore) setUTXO(utxoInfo *privacytypes.PrivacyDBStore, txHash string, newbatch db.Batch) error {
privacyStorebyte, err := proto.Marshal(dbStore)
privacyStorebyte, err := proto.Marshal(utxoInfo)
if err != nil {
bizlog.Error("setUTXO proto.Marshal err!", "err", err)
return types.ErrMarshal
}
utxoKey := calcUTXOKey(*txhash, outindex)
bizlog.Debug("setUTXO", "addr", *addr, "tx with hash", *txhash, "amount:", dbStore.Amount/types.Coin)
newbatch.Set(calcUTXOKey4TokenAddr(dbStore.AssetExec, dbStore.Tokenname, *addr, *txhash, outindex), utxoKey)
outIndex := int(utxoInfo.OutIndex)
utxoKey := calcUTXOKey(txHash, outIndex)
bizlog.Debug("setUTXO", "addr", utxoInfo.Owner, "tx with hash", txHash, "amount:", utxoInfo.Amount/types.Coin)
newbatch.Set(calcUTXOKey4TokenAddr(utxoInfo.AssetExec, utxoInfo.Tokenname, utxoInfo.Owner, txHash, outIndex), utxoKey)
newbatch.Set(utxoKey, privacyStorebyte)
return nil
}
......
......@@ -117,16 +117,11 @@ func testStore_storeScanPrivacyInputUTXO(t *testing.T) {
}
func testStore_setUTXO(t *testing.T) {
var addr, txhash string
var txhash string
store := createStore(t)
dbbatch := store.NewBatch(true)
err := store.setUTXO(&addr, &txhash, 0, nil, dbbatch)
assert.NotNil(t, err)
addr = "setUTXO"
txhash = "TXHASH"
err = store.setUTXO(&addr, &txhash, 0, nil, dbbatch)
assert.NotNil(t, err)
err := store.setUTXO(&pt.PrivacyDBStore{}, txhash, dbbatch)
assert.Nil(t, err)
}
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