Commit c53d3a3f authored by vipwzw's avatar vipwzw Committed by 33cn

fix test

parent 7957fb75
...@@ -443,7 +443,7 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) { ...@@ -443,7 +443,7 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) {
hash := blockSeq.Detail.Block.HashByForkHeight(mainBlockHashForkHeight) hash := blockSeq.Detail.Block.HashByForkHeight(mainBlockHashForkHeight)
if !bytes.Equal(blockSeq.Seq.Hash, hash) { if !bytes.Equal(blockSeq.Seq.Hash, hash) {
plog.Error("para compare ForkBlockHash fail", "forkHeight", mainBlockHashForkHeight, plog.Error("para compare ForkBlockHash fail", "forkHeight", mainBlockHashForkHeight,
"seqHash", common.Bytes2Hex(blockSeq.Seq.Hash), "calcHash", common.Bytes2Hex(hash)) "seqHash", hex.EncodeToString(blockSeq.Seq.Hash), "calcHash", hex.EncodeToString(hash))
return nil, types.ErrBlockHashNoMatch return nil, types.ErrBlockHashNoMatch
} }
...@@ -484,8 +484,8 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type ...@@ -484,8 +484,8 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
return txs, blockSeq, nil return txs, blockSeq, nil
} }
//not consistent case be processed at below //not consistent case be processed at below
plog.Error("RequestTx", "preMainHash", common.Bytes2Hex(preMainBlockHash), "currSeq preMainHash", common.Bytes2Hex(blockSeq.Detail.Block.ParentHash), plog.Error("RequestTx", "preMainHash", hex.EncodeToString(preMainBlockHash), "currSeq preMainHash", hex.EncodeToString(blockSeq.Detail.Block.ParentHash),
"currSeq mainHash", common.Bytes2Hex(blockSeq.Seq.Hash), "curr seq", currSeq, "ty", blockSeq.Seq.Type, "currSeq Mainheight", blockSeq.Detail.Block.Height) "currSeq mainHash", hex.EncodeToString(blockSeq.Seq.Hash), "curr seq", currSeq, "ty", blockSeq.Seq.Type, "currSeq Mainheight", blockSeq.Detail.Block.Height)
return nil, nil, paracross.ErrParaCurHashNotMatch return nil, nil, paracross.ErrParaCurHashNotMatch
} }
//lastSeq < CurrSeq case: //lastSeq < CurrSeq case:
...@@ -537,19 +537,19 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro ...@@ -537,19 +537,19 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro
return -2, nil, err return -2, nil, err
} }
plog.Info("switchHashMatchedBlock", "lastParaBlock height", miner.Height, "mainHeight", plog.Info("switchHashMatchedBlock", "lastParaBlock height", miner.Height, "mainHeight",
miner.MainBlockHeight, "mainHash", common.Bytes2Hex(miner.MainBlockHash)) miner.MainBlockHeight, "mainHash", hex.EncodeToString(miner.MainBlockHash))
mainSeq, err := client.GetSeqByHashOnMainChain(miner.MainBlockHash) mainSeq, err := client.GetSeqByHashOnMainChain(miner.MainBlockHash)
if err != nil { if err != nil {
depth-- depth--
if depth == 0 { if depth == 0 {
plog.Error("switchHashMatchedBlock depth overflow", "last info:mainHeight", miner.MainBlockHeight, plog.Error("switchHashMatchedBlock depth overflow", "last info:mainHeight", miner.MainBlockHeight,
"mainHash", common.Bytes2Hex(miner.MainBlockHash), "search startHeight", lastBlock.Height, "curHeight", miner.Height, "mainHash", hex.EncodeToString(miner.MainBlockHash), "search startHeight", lastBlock.Height, "curHeight", miner.Height,
"search depth", searchHashMatchDepth) "search depth", searchHashMatchDepth)
panic("search HashMatchedBlock overflow, re-setting search depth and restart to try") panic("search HashMatchedBlock overflow, re-setting search depth and restart to try")
} }
if height == 1 { if height == 1 {
plog.Error("switchHashMatchedBlock search to height=1 not found", "lastBlockHeight", lastBlock.Height, plog.Error("switchHashMatchedBlock search to height=1 not found", "lastBlockHeight", lastBlock.Height,
"height1 mainHash", common.Bytes2Hex(miner.MainBlockHash)) "height1 mainHash", hex.EncodeToString(miner.MainBlockHash))
err = client.removeBlocks(0) err = client.removeBlocks(0)
if err != nil { if err != nil {
return currSeq, nil, nil return currSeq, nil, nil
...@@ -567,7 +567,7 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro ...@@ -567,7 +567,7 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro
} }
plog.Info("switchHashMatchedBlock succ", "currHeight", height, "initHeight", lastBlock.Height, plog.Info("switchHashMatchedBlock succ", "currHeight", height, "initHeight", lastBlock.Height,
"new currSeq", mainSeq+1, "new preMainBlockHash", common.Bytes2Hex(miner.MainBlockHash)) "new currSeq", mainSeq+1, "new preMainBlockHash", hex.EncodeToString(miner.MainBlockHash))
return mainSeq + 1, miner.MainBlockHash, nil return mainSeq + 1, miner.MainBlockHash, nil
} }
return -2, nil, paracross.ErrParaCurHashNotMatch return -2, nil, paracross.ErrParaCurHashNotMatch
......
...@@ -106,7 +106,7 @@ func ExecAddress(execName string) Address { ...@@ -106,7 +106,7 @@ func ExecAddress(execName string) Address {
func BytesToAddress(b []byte) Address { func BytesToAddress(b []byte) Address {
a := new(address.Address) a := new(address.Address)
a.Version = 0 a.Version = 0
a.Hash160 = copyBytes(LeftPadBytes(b, 20)) a.SetBytes(copyBytes(LeftPadBytes(b, 20)))
return Address{addr: a} return Address{addr: a}
} }
...@@ -127,12 +127,14 @@ func StringToAddress(s string) *Address { ...@@ -127,12 +127,14 @@ func StringToAddress(s string) *Address {
return &Address{addr: addr} return &Address{addr: addr}
} }
func copyBytes(data []byte) (out [20]byte) { func copyBytes(data []byte) (out []byte) {
out = make([]byte, 20)
copy(out[:], data) copy(out[:], data)
return return
} }
func bigBytes(b *big.Int) (out [20]byte) { func bigBytes(b *big.Int) (out []byte) {
out = make([]byte, 20)
copy(out[:], b.Bytes()) copy(out[:], b.Bytes())
return return
} }
...@@ -141,7 +143,7 @@ func bigBytes(b *big.Int) (out [20]byte) { ...@@ -141,7 +143,7 @@ func bigBytes(b *big.Int) (out [20]byte) {
func BigToAddress(b *big.Int) Address { func BigToAddress(b *big.Int) Address {
a := new(address.Address) a := new(address.Address)
a.Version = 0 a.Version = 0
a.Hash160 = bigBytes(b) a.SetBytes(bigBytes(b))
return Address{addr: a} return Address{addr: a}
} }
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
package common package common
import ( import (
"fmt"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestAddressBig(t *testing.T) { func TestAddressBig(t *testing.T) {
...@@ -21,6 +22,5 @@ func TestAddressBig(t *testing.T) { ...@@ -21,6 +22,5 @@ func TestAddressBig(t *testing.T) {
func TestAddressBytes(t *testing.T) { func TestAddressBytes(t *testing.T) {
addr := BytesToAddress([]byte{1}) addr := BytesToAddress([]byte{1})
assert.Equal(t, addr.String(), "11111111111111111111BZbvjr")
fmt.Println(addr.String())
} }
...@@ -44,7 +44,7 @@ func (h *Hash) SetBytes(b []byte) { ...@@ -44,7 +44,7 @@ func (h *Hash) SetBytes(b []byte) {
// BigToHash 大数字转换为哈希 // BigToHash 大数字转换为哈希
func BigToHash(b *big.Int) Hash { func BigToHash(b *big.Int) Hash {
return Hash(common.BigToHash(b)) return Hash(common.BytesToHash(b.Bytes()))
} }
// BytesToHash 将[]byte直接当做哈希处理 // BytesToHash 将[]byte直接当做哈希处理
......
...@@ -6,10 +6,10 @@ package executor ...@@ -6,10 +6,10 @@ package executor
import ( import (
"bytes" "bytes"
"encoding/hex"
"github.com/33cn/chain33/account" "github.com/33cn/chain33/account"
"github.com/33cn/chain33/client" "github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp" "github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
...@@ -230,8 +230,8 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -230,8 +230,8 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
if titleStatus.Height+1 == commit.Status.Height && commit.Status.Height > 0 { if titleStatus.Height+1 == commit.Status.Height && commit.Status.Height > 0 {
if !bytes.Equal(titleStatus.BlockHash, commit.Status.PreBlockHash) { if !bytes.Equal(titleStatus.BlockHash, commit.Status.PreBlockHash) {
clog.Error("paracross.Commit", "check PreBlockHash", common.Bytes2Hex(titleStatus.BlockHash), clog.Error("paracross.Commit", "check PreBlockHash", hex.EncodeToString(titleStatus.BlockHash),
"commit tx", common.Bytes2Hex(commit.Status.PreBlockHash), "commitheit", commit.Status.Height, "commit tx", hex.EncodeToString(commit.Status.PreBlockHash), "commitheit", commit.Status.Height,
"from", a.fromaddr) "from", a.fromaddr)
return nil, pt.ErrParaBlockHashNoMatch return nil, pt.ErrParaBlockHashNoMatch
} }
...@@ -248,8 +248,8 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -248,8 +248,8 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
return nil, err return nil, err
} }
if !bytes.Equal(blockHash.Hash, commit.Status.MainBlockHash) && commit.Status.Height > 0 { if !bytes.Equal(blockHash.Hash, commit.Status.MainBlockHash) && commit.Status.Height > 0 {
clog.Error("paracross.Commit blockHash not match", "db", common.Bytes2Hex(blockHash.Hash), clog.Error("paracross.Commit blockHash not match", "db", hex.EncodeToString(blockHash.Hash),
"commit tx", common.Bytes2Hex(commit.Status.MainBlockHash), "commitHeight", commit.Status.Height, "commit tx", hex.EncodeToString(commit.Status.MainBlockHash), "commitHeight", commit.Status.Height,
"from", a.fromaddr) "from", a.fromaddr)
return nil, types.ErrBlockHashNoMatch return nil, types.ErrBlockHashNoMatch
} }
...@@ -342,7 +342,7 @@ func (a *action) execCrossTx(tx *types.TransactionDetail, commit *pt.ParacrossCo ...@@ -342,7 +342,7 @@ func (a *action) execCrossTx(tx *types.TransactionDetail, commit *pt.ParacrossCo
if err != nil { if err != nil {
clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title, clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return nil, err return nil, err
} }
...@@ -351,13 +351,13 @@ func (a *action) execCrossTx(tx *types.TransactionDetail, commit *pt.ParacrossCo ...@@ -351,13 +351,13 @@ func (a *action) execCrossTx(tx *types.TransactionDetail, commit *pt.ParacrossCo
if err != nil { if err != nil {
clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title, clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return nil, errors.Cause(err) return nil, errors.Cause(err)
} }
clog.Info("paracross.Commit WithdrawCoins", "para title", commit.Status.Title, clog.Info("paracross.Commit WithdrawCoins", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return receiptWithdraw, nil return receiptWithdraw, nil
} //else if tx.ActionName == pt.ParacrossActionAssetTransferStr { } //else if tx.ActionName == pt.ParacrossActionAssetTransferStr {
return nil, nil return nil, nil
...@@ -368,20 +368,20 @@ func (a *action) execCrossTxs(commit *pt.ParacrossCommitAction) (*types.Receipt, ...@@ -368,20 +368,20 @@ func (a *action) execCrossTxs(commit *pt.ParacrossCommitAction) (*types.Receipt,
var receipt types.Receipt var receipt types.Receipt
for i := 0; i < len(commit.Status.CrossTxHashs); i++ { for i := 0; i < len(commit.Status.CrossTxHashs); i++ {
clog.Info("paracross.Commit commitDone", "do cross number", i, "hash", clog.Info("paracross.Commit commitDone", "do cross number", i, "hash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i]), hex.EncodeToString(commit.Status.CrossTxHashs[i]),
"res", util.BitMapBit(commit.Status.CrossTxResult, uint32(i))) "res", util.BitMapBit(commit.Status.CrossTxResult, uint32(i)))
if util.BitMapBit(commit.Status.CrossTxResult, uint32(i)) { if util.BitMapBit(commit.Status.CrossTxResult, uint32(i)) {
tx, err := GetTx(a.api, commit.Status.CrossTxHashs[i]) tx, err := GetTx(a.api, commit.Status.CrossTxHashs[i])
if err != nil { if err != nil {
clog.Crit("paracross.Commit Load Tx failed", "para title", commit.Status.Title, clog.Crit("paracross.Commit Load Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return nil, err return nil, err
} }
if tx == nil { if tx == nil {
clog.Error("paracross.Commit Load Tx failed", "para title", commit.Status.Title, clog.Error("paracross.Commit Load Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return nil, types.ErrHashNotExist return nil, types.ErrHashNotExist
} }
receiptCross, err := a.execCrossTx(tx, commit, i) receiptCross, err := a.execCrossTx(tx, commit, i)
...@@ -395,7 +395,7 @@ func (a *action) execCrossTxs(commit *pt.ParacrossCommitAction) (*types.Receipt, ...@@ -395,7 +395,7 @@ func (a *action) execCrossTxs(commit *pt.ParacrossCommitAction) (*types.Receipt,
receipt.Logs = append(receipt.Logs, receiptCross.Logs...) receipt.Logs = append(receipt.Logs, receiptCross.Logs...)
} else { } else {
clog.Error("paracross.Commit commitDone", "do cross number", i, "hash", clog.Error("paracross.Commit commitDone", "do cross number", i, "hash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i]), hex.EncodeToString(commit.Status.CrossTxHashs[i]),
"para res", util.BitMapBit(commit.Status.CrossTxResult, uint32(i))) "para res", util.BitMapBit(commit.Status.CrossTxResult, uint32(i)))
} }
} }
...@@ -424,7 +424,7 @@ func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt, ...@@ -424,7 +424,7 @@ func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt,
return nil, nil return nil, nil
} }
clog.Debug("paracross.AssetWithdraw isPara", "execer", string(a.tx.Execer), clog.Debug("paracross.AssetWithdraw isPara", "execer", string(a.tx.Execer),
"txHash", common.Bytes2Hex(a.tx.Hash())) "txHash", hex.EncodeToString(a.tx.Hash()))
receipt, err := a.assetWithdraw(withdraw, a.tx) receipt, err := a.assetWithdraw(withdraw, a.tx)
if err != nil { if err != nil {
clog.Error("AssetWithdraw failed", "err", err) clog.Error("AssetWithdraw failed", "err", err)
...@@ -469,7 +469,7 @@ func (a *Paracross) CrossLimits(tx *types.Transaction, index int) bool { ...@@ -469,7 +469,7 @@ func (a *Paracross) CrossLimits(tx *types.Transaction, index int) bool {
txs, err := a.GetTxGroup(index) txs, err := a.GetTxGroup(index)
if err != nil { if err != nil {
clog.Error("crossLimits", "get tx group failed", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("crossLimits", "get tx group failed", err, "hash", hex.EncodeToString(tx.Hash()))
return false return false
} }
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
package executor package executor
import ( import (
"encoding/hex"
"github.com/33cn/chain33/account" "github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/db" "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
...@@ -28,7 +29,7 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt, ...@@ -28,7 +29,7 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
} }
toAddr := address.ExecAddress(string(a.tx.Execer)) toAddr := address.ExecAddress(string(a.tx.Execer))
clog.Debug("paracross.AssetTransfer not isPara", "execer", string(a.tx.Execer), clog.Debug("paracross.AssetTransfer not isPara", "execer", string(a.tx.Execer),
"txHash", common.Bytes2Hex(a.tx.Hash())) "txHash", hex.EncodeToString(a.tx.Hash()))
return accDB.ExecTransfer(a.fromaddr, toAddr, execAddr, transfer.Amount) return accDB.ExecTransfer(a.fromaddr, toAddr, execAddr, transfer.Amount)
} }
...@@ -46,7 +47,7 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt, ...@@ -46,7 +47,7 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
return nil, errors.Wrap(err, "assetTransferCoins call NewParaAccount failed") return nil, errors.Wrap(err, "assetTransferCoins call NewParaAccount failed")
} }
clog.Debug("paracross.AssetTransfer isPara", "execer", string(a.tx.Execer), clog.Debug("paracross.AssetTransfer isPara", "execer", string(a.tx.Execer),
"txHash", common.Bytes2Hex(a.tx.Hash())) "txHash", hex.EncodeToString(a.tx.Hash()))
return assetDepositBalance(paraAcc, transfer.To, transfer.Amount) return assetDepositBalance(paraAcc, transfer.To, transfer.Amount)
} }
...@@ -78,7 +79,7 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types ...@@ -78,7 +79,7 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types
return nil, errors.Wrap(err, "assetWithdrawCoins call NewParaAccount failed") return nil, errors.Wrap(err, "assetWithdrawCoins call NewParaAccount failed")
} }
clog.Debug("paracross.assetWithdrawCoins isPara", "execer", string(a.tx.Execer), clog.Debug("paracross.assetWithdrawCoins isPara", "execer", string(a.tx.Execer),
"txHash", common.Bytes2Hex(a.tx.Hash())) "txHash", hex.EncodeToString(a.tx.Hash()))
return assetWithdrawBalance(paraAcc, a.fromaddr, withdraw.Amount) return assetWithdrawBalance(paraAcc, a.fromaddr, withdraw.Amount)
} }
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
package executor package executor
import ( import (
"encoding/hex"
"github.com/33cn/chain33/client" "github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
...@@ -58,7 +59,7 @@ func GetBlock(api client.QueueProtocolAPI, blockHash []byte) (*types.BlockDetail ...@@ -58,7 +59,7 @@ func GetBlock(api client.QueueProtocolAPI, blockHash []byte) (*types.BlockDetail
blockDetails, err := api.GetBlockByHashes(&types.ReqHashes{Hashes: [][]byte{blockHash}}) blockDetails, err := api.GetBlockByHashes(&types.ReqHashes{Hashes: [][]byte{blockHash}})
if err != nil { if err != nil {
clog.Error("paracross.Commit getBlockHeader", "db", err, clog.Error("paracross.Commit getBlockHeader", "db", err,
"commit tx hash", common.Bytes2Hex(blockHash)) "commit tx hash", hex.EncodeToString(blockHash))
return nil, err return nil, err
} }
if len(blockDetails.Items) != 1 { if len(blockDetails.Items) != 1 {
...@@ -66,7 +67,7 @@ func GetBlock(api client.QueueProtocolAPI, blockHash []byte) (*types.BlockDetail ...@@ -66,7 +67,7 @@ func GetBlock(api client.QueueProtocolAPI, blockHash []byte) (*types.BlockDetail
return nil, pt.ErrParaBlockHashNoMatch return nil, pt.ErrParaBlockHashNoMatch
} }
if blockDetails.Items[0] == nil { if blockDetails.Items[0] == nil {
clog.Error("paracross.Commit getBlockHeader", "commit tx hash net found", common.Bytes2Hex(blockHash)) clog.Error("paracross.Commit getBlockHeader", "commit tx hash net found", hex.EncodeToString(blockHash))
return nil, pt.ErrParaBlockHashNoMatch return nil, pt.ErrParaBlockHashNoMatch
} }
return blockDetails.Items[0], nil return blockDetails.Items[0], nil
...@@ -94,7 +95,7 @@ func GetTx(api client.QueueProtocolAPI, txHash []byte) (*types.TransactionDetail ...@@ -94,7 +95,7 @@ func GetTx(api client.QueueProtocolAPI, txHash []byte) (*types.TransactionDetail
txs, err := api.GetTransactionByHash(&types.ReqHashes{Hashes: [][]byte{txHash}}) txs, err := api.GetTransactionByHash(&types.ReqHashes{Hashes: [][]byte{txHash}})
if err != nil { if err != nil {
clog.Error("paracross.Commit GetTx", "db", err, clog.Error("paracross.Commit GetTx", "db", err,
"commit tx hash", common.Bytes2Hex(txHash)) "commit tx hash", hex.EncodeToString(txHash))
return nil, err return nil, err
} }
if len(txs.Txs) != 1 { if len(txs.Txs) != 1 {
...@@ -102,7 +103,7 @@ func GetTx(api client.QueueProtocolAPI, txHash []byte) (*types.TransactionDetail ...@@ -102,7 +103,7 @@ func GetTx(api client.QueueProtocolAPI, txHash []byte) (*types.TransactionDetail
return nil, pt.ErrParaBlockHashNoMatch return nil, pt.ErrParaBlockHashNoMatch
} }
if txs.Txs == nil { if txs.Txs == nil {
clog.Error("paracross.Commit GetTx", "commit tx hash net found", common.Bytes2Hex(txHash)) clog.Error("paracross.Commit GetTx", "commit tx hash net found", hex.EncodeToString(txHash))
return nil, pt.ErrParaBlockHashNoMatch return nil, pt.ErrParaBlockHashNoMatch
} }
return txs.Txs[0], nil return txs.Txs[0], nil
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
package executor package executor
import ( import (
"github.com/33cn/chain33/common" "encoding/hex"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/pkg/errors" "github.com/pkg/errors"
...@@ -16,7 +17,7 @@ func (e *Paracross) Exec_Commit(payload *pt.ParacrossCommitAction, tx *types.Tra ...@@ -16,7 +17,7 @@ func (e *Paracross) Exec_Commit(payload *pt.ParacrossCommitAction, tx *types.Tra
a := newAction(e, tx) a := newAction(e, tx)
receipt, err := a.Commit(payload) receipt, err := a.Commit(payload)
if err != nil { if err != nil {
clog.Error("Paracross commit failed", "error", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("Paracross commit failed", "error", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, errors.Cause(err) return nil, errors.Cause(err)
} }
return receipt, nil return receipt, nil
...@@ -27,13 +28,13 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types. ...@@ -27,13 +28,13 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
clog.Debug("Paracross.Exec", "transfer", "") clog.Debug("Paracross.Exec", "transfer", "")
_, err := e.checkTxGroup(tx, index) _, err := e.checkTxGroup(tx, index)
if err != nil { if err != nil {
clog.Error("ParacrossActionAssetTransfer", "get tx group failed", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("ParacrossActionAssetTransfer", "get tx group failed", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, err return nil, err
} }
a := newAction(e, tx) a := newAction(e, tx)
receipt, err := a.AssetTransfer(payload) receipt, err := a.AssetTransfer(payload)
if err != nil { if err != nil {
clog.Error("Paracross AssetTransfer failed", "error", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("Paracross AssetTransfer failed", "error", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, errors.Cause(err) return nil, errors.Cause(err)
} }
return receipt, nil return receipt, nil
...@@ -44,13 +45,13 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types. ...@@ -44,13 +45,13 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
clog.Debug("Paracross.Exec", "withdraw", "") clog.Debug("Paracross.Exec", "withdraw", "")
_, err := e.checkTxGroup(tx, index) _, err := e.checkTxGroup(tx, index)
if err != nil { if err != nil {
clog.Error("ParacrossActionAssetWithdraw", "get tx group failed", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("ParacrossActionAssetWithdraw", "get tx group failed", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, err return nil, err
} }
a := newAction(e, tx) a := newAction(e, tx)
receipt, err := a.AssetWithdraw(payload) receipt, err := a.AssetWithdraw(payload)
if err != nil { if err != nil {
clog.Error("ParacrossActionAssetWithdraw failed", "error", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("ParacrossActionAssetWithdraw failed", "error", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, errors.Cause(err) return nil, errors.Cause(err)
} }
return receipt, nil return receipt, nil
......
...@@ -6,8 +6,8 @@ package executor ...@@ -6,8 +6,8 @@ package executor
import ( import (
"bytes" "bytes"
"encoding/hex"
"github.com/33cn/chain33/common"
log "github.com/33cn/chain33/common/log/log15" log "github.com/33cn/chain33/common/log/log15"
drivers "github.com/33cn/chain33/system/dapp" drivers "github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
...@@ -59,7 +59,7 @@ func (c *Paracross) checkTxGroup(tx *types.Transaction, index int) ([]*types.Tra ...@@ -59,7 +59,7 @@ func (c *Paracross) checkTxGroup(tx *types.Transaction, index int) ([]*types.Tra
if tx.GroupCount >= 2 { if tx.GroupCount >= 2 {
txs, err := c.GetTxGroup(index) txs, err := c.GetTxGroup(index)
if err != nil { if err != nil {
clog.Error("ParacrossActionAssetTransfer", "get tx group failed", err, "hash", common.Bytes2Hex(tx.Hash())) clog.Error("ParacrossActionAssetTransfer", "get tx group failed", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, err return nil, err
} }
return txs, nil return txs, nil
...@@ -117,7 +117,7 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types. ...@@ -117,7 +117,7 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.
if err != nil { if err != nil {
clog.Crit("paracross.Commit Load Tx failed", "para title", commit.Status.Title, clog.Crit("paracross.Commit Load Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return nil, err return nil, err
} }
...@@ -126,7 +126,7 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types. ...@@ -126,7 +126,7 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.
if err != nil { if err != nil {
clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title, clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash", "para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
common.Bytes2Hex(commit.Status.CrossTxHashs[i])) hex.EncodeToString(commit.Status.CrossTxHashs[i]))
return nil, err return nil, err
} }
if payload.Ty == pt.ParacrossActionAssetTransfer { if payload.Ty == pt.ParacrossActionAssetTransfer {
...@@ -161,7 +161,7 @@ func getCommitHeight(payload []byte) (int64, error) { ...@@ -161,7 +161,7 @@ func getCommitHeight(payload []byte) (int64, error) {
} }
func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel bool) (*types.KeyValue, error) { func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel bool) (*types.KeyValue, error) {
clog.Debug("para execLocal", "tx hash", common.Bytes2Hex(tx.Hash()), "action name", log.Lazy{Fn: tx.ActionName}) clog.Debug("para execLocal", "tx hash", hex.EncodeToString(tx.Hash()), "action name", log.Lazy{Fn: tx.ActionName})
key := calcLocalAssetKey(tx.Hash()) key := calcLocalAssetKey(tx.Hash())
if isDel { if isDel {
c.GetLocalDB().Set(key, nil) c.GetLocalDB().Set(key, nil)
...@@ -202,7 +202,7 @@ func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel ...@@ -202,7 +202,7 @@ func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel
err = c.GetLocalDB().Set(key, types.Encode(&asset)) err = c.GetLocalDB().Set(key, types.Encode(&asset))
if err != nil { if err != nil {
clog.Error("para execLocal", "set", common.Bytes2Hex(tx.Hash()), "failed", err) clog.Error("para execLocal", "set", hex.EncodeToString(tx.Hash()), "failed", err)
} }
return &types.KeyValue{Key: key, Value: types.Encode(&asset)}, nil return &types.KeyValue{Key: key, Value: types.Encode(&asset)}, nil
} }
...@@ -262,7 +262,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi ...@@ -262,7 +262,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi
} }
func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, success, isDel bool) (*types.KeyValue, error) { func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, success, isDel bool) (*types.KeyValue, error) {
clog.Debug("para execLocal", "tx hash", common.Bytes2Hex(tx.Hash())) clog.Debug("para execLocal", "tx hash", hex.EncodeToString(tx.Hash()))
key := calcLocalAssetKey(tx.Hash()) key := calcLocalAssetKey(tx.Hash())
var asset pt.ParacrossAsset var asset pt.ParacrossAsset
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package commands package commands
import ( import (
"encoding/hex"
"fmt" "fmt"
"strconv" "strconv"
"time" "time"
...@@ -425,7 +426,7 @@ func parseShowUTXOs4SpecifiedAmountRes(arg interface{}) (interface{}, error) { ...@@ -425,7 +426,7 @@ func parseShowUTXOs4SpecifiedAmountRes(arg interface{}) (interface{}, error) {
result := &PrivacyAccountResult{ result := &PrivacyAccountResult{
Txhash: common.ToHex(item.Txhash), Txhash: common.ToHex(item.Txhash),
OutIndex: item.Outindex, OutIndex: item.Outindex,
OnetimePubKey: common.Bytes2Hex(item.Onetimepubkey), OnetimePubKey: hex.EncodeToString(item.Onetimepubkey),
} }
ret = append(ret, result) ret = append(ret, result)
} }
......
...@@ -6,19 +6,17 @@ package privacy ...@@ -6,19 +6,17 @@ package privacy
import ( import (
"bytes" "bytes"
"encoding/hex"
"errors" "errors"
"fmt"
"io" "io"
"unsafe" "unsafe"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto" "github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto/sha3" "github.com/33cn/chain33/common/crypto/sha3"
"github.com/33cn/chain33/common/ed25519/edwards25519" "github.com/33cn/chain33/common/ed25519/edwards25519"
log "github.com/33cn/chain33/common/log/log15" log "github.com/33cn/chain33/common/log/log15"
sccrypto "github.com/NebulousLabs/Sia/crypto" sccrypto "github.com/NebulousLabs/Sia/crypto"
//"github.com/33cn/chain33/types"
"fmt"
) )
const ( const (
...@@ -72,7 +70,7 @@ func NewPrivacy() *Privacy { ...@@ -72,7 +70,7 @@ func NewPrivacy() *Privacy {
// NewPrivacyWithPrivKey create privacy from private key // NewPrivacyWithPrivKey create privacy from private key
func NewPrivacyWithPrivKey(privKey *[KeyLen32]byte) (privacy *Privacy, err error) { func NewPrivacyWithPrivKey(privKey *[KeyLen32]byte) (privacy *Privacy, err error) {
privacylog.Info("NewPrivacyWithPrivKey", "input prikey", common.Bytes2Hex(privKey[:])) privacylog.Info("NewPrivacyWithPrivKey", "input prikey", hex.EncodeToString(privKey[:]))
hash := sccrypto.HashAll(*privKey) hash := sccrypto.HashAll(*privKey)
privacy = &Privacy{} privacy = &Privacy{}
...@@ -84,8 +82,8 @@ func NewPrivacyWithPrivKey(privKey *[KeyLen32]byte) (privacy *Privacy, err error ...@@ -84,8 +82,8 @@ func NewPrivacyWithPrivKey(privKey *[KeyLen32]byte) (privacy *Privacy, err error
if err = generateKeyPairWithPrivKey((*[KeyLen32]byte)(unsafe.Pointer(&hashViewPriv[0])), &privacy.ViewPrivKey, &privacy.ViewPubkey); err != nil { if err = generateKeyPairWithPrivKey((*[KeyLen32]byte)(unsafe.Pointer(&hashViewPriv[0])), &privacy.ViewPrivKey, &privacy.ViewPubkey); err != nil {
return nil, err return nil, err
} }
privacylog.Info("NewPrivacyWithPrivKey", "the new privacy created with viewpub", common.Bytes2Hex(privacy.ViewPubkey[:])) privacylog.Info("NewPrivacyWithPrivKey", "the new privacy created with viewpub", hex.EncodeToString(privacy.ViewPubkey[:]))
privacylog.Info("NewPrivacyWithPrivKey", "the new privacy created with spendpub", common.Bytes2Hex(privacy.SpendPubkey[:])) privacylog.Info("NewPrivacyWithPrivKey", "the new privacy created with spendpub", hex.EncodeToString(privacy.SpendPubkey[:]))
return privacy, nil return privacy, nil
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
package executor package executor
import ( import (
"encoding/hex"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
...@@ -16,7 +18,7 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran ...@@ -16,7 +18,7 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran
if payload.Tokenname != types.BTY { if payload.Tokenname != types.BTY {
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
} }
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
coinsAccount := p.GetCoinsAccount() coinsAccount := p.GetCoinsAccount()
from := tx.From() from := tx.From()
receipt, err := coinsAccount.ExecWithdraw(address.ExecAddress(string(tx.Execer)), from, payload.Amount) receipt, err := coinsAccount.ExecWithdraw(address.ExecAddress(string(tx.Execer)), from, payload.Amount)
...@@ -56,7 +58,7 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr ...@@ -56,7 +58,7 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
if payload.Tokenname != types.BTY { if payload.Tokenname != types.BTY {
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
} }
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
receipt := &types.Receipt{KV: make([]*types.KeyValue, 0)} receipt := &types.Receipt{KV: make([]*types.KeyValue, 0)}
privacyInput := payload.Input privacyInput := payload.Input
for _, keyInput := range privacyInput.Keyinput { for _, keyInput := range privacyInput.Keyinput {
...@@ -98,7 +100,7 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran ...@@ -98,7 +100,7 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
if payload.Tokenname != types.BTY { if payload.Tokenname != types.BTY {
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
} }
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
coinsAccount := p.GetCoinsAccount() coinsAccount := p.GetCoinsAccount()
receipt, err := coinsAccount.ExecDeposit(tx.To, address.ExecAddress(string(tx.Execer)), payload.Amount) receipt, err := coinsAccount.ExecDeposit(tx.To, address.ExecAddress(string(tx.Execer)), payload.Amount)
if err != nil { if err != nil {
......
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
package executor package executor
import ( import (
"encoding/hex"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
ty "github.com/33cn/plugin/plugin/dapp/privacy/types" ty "github.com/33cn/plugin/plugin/dapp/privacy/types"
) )
func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
localDB := p.GetLocalDB() localDB := p.GetLocalDB()
for i, item := range receiptData.Logs { for i, item := range receiptData.Logs {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
package executor package executor
import ( import (
"encoding/hex"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
ty "github.com/33cn/plugin/plugin/dapp/privacy/types" ty "github.com/33cn/plugin/plugin/dapp/privacy/types"
...@@ -12,7 +14,7 @@ import ( ...@@ -12,7 +14,7 @@ import (
func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transaction, index int) (*types.LocalDBSet, error) { func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transaction, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
localDB := p.GetLocalDB() localDB := p.GetLocalDB()
for _, item := range receiptData.Logs { for _, item := range receiptData.Logs {
if item.Ty != ty.TyLogPrivacyOutput { if item.Ty != ty.TyLogPrivacyOutput {
......
...@@ -21,6 +21,7 @@ privacy执行器支持隐私交易的执行, ...@@ -21,6 +21,7 @@ privacy执行器支持隐私交易的执行,
import ( import (
"bytes" "bytes"
"encoding/hex"
"math/rand" "math/rand"
"sort" "sort"
"time" "time"
...@@ -198,7 +199,7 @@ func (p *privacy) ShowUTXOs4SpecifiedAmount(reqtoken *pty.ReqPrivacyToken) (type ...@@ -198,7 +199,7 @@ func (p *privacy) ShowUTXOs4SpecifiedAmount(reqtoken *pty.ReqPrivacyToken) (type
// CheckTx check transaction // CheckTx check transaction
func (p *privacy) CheckTx(tx *types.Transaction, index int) error { func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
var action pty.PrivacyAction var action pty.PrivacyAction
err := types.Decode(tx.Payload, &action) err := types.Decode(tx.Payload, &action)
if err != nil { if err != nil {
......
...@@ -6,6 +6,7 @@ package wallet ...@@ -6,6 +6,7 @@ package wallet
import ( import (
"bytes" "bytes"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"sort" "sort"
...@@ -599,7 +600,6 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *types.ReqCreateTransact ...@@ -599,7 +600,6 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *types.ReqCreateTransact
Ty: privacytypes.ActionPublic2Privacy, Ty: privacytypes.ActionPublic2Privacy,
Value: &privacytypes.PrivacyAction_Public2Privacy{Public2Privacy: value}, Value: &privacytypes.PrivacyAction_Public2Privacy{Public2Privacy: value},
} }
tx := &types.Transaction{ tx := &types.Transaction{
Execer: []byte(privacytypes.PrivacyX), Execer: []byte(privacytypes.PrivacyX),
Payload: types.Encode(action), Payload: types.Encode(action),
...@@ -678,7 +678,7 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *types.ReqCreateTransac ...@@ -678,7 +678,7 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *types.ReqCreateTransac
To: address.ExecAddress(privacytypes.PrivacyX), To: address.ExecAddress(privacytypes.PrivacyX),
} }
// 创建交易成功,将已经使用掉的UTXO冻结 // 创建交易成功,将已经使用掉的UTXO冻结
policy.saveFTXOInfo(tx, req.GetTokenname(), req.GetFrom(), common.Bytes2Hex(tx.Hash()), selectedUtxo) policy.saveFTXOInfo(tx, req.GetTokenname(), req.GetFrom(), hex.EncodeToString(tx.Hash()), selectedUtxo)
tx.Signature = &types.Signature{ tx.Signature = &types.Signature{
Signature: types.Encode(&privacytypes.PrivacySignatureParam{ Signature: types.Encode(&privacytypes.PrivacySignatureParam{
ActionType: action.Ty, ActionType: action.Ty,
...@@ -747,7 +747,7 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *types.ReqCreateTransact ...@@ -747,7 +747,7 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *types.ReqCreateTransact
To: req.GetTo(), To: req.GetTo(),
} }
// 创建交易成功,将已经使用掉的UTXO冻结 // 创建交易成功,将已经使用掉的UTXO冻结
policy.saveFTXOInfo(tx, req.GetTokenname(), req.GetFrom(), common.Bytes2Hex(tx.Hash()), selectedUtxo) policy.saveFTXOInfo(tx, req.GetTokenname(), req.GetFrom(), hex.EncodeToString(tx.Hash()), selectedUtxo)
tx.Signature = &types.Signature{ tx.Signature = &types.Signature{
Signature: types.Encode(&privacytypes.PrivacySignatureParam{ Signature: types.Encode(&privacytypes.PrivacySignatureParam{
ActionType: action.Ty, ActionType: action.Ty,
...@@ -1137,7 +1137,7 @@ func (policy *privacyPolicy) transPri2PriV2(privacykeyParirs *privacy.Privacy, r ...@@ -1137,7 +1137,7 @@ func (policy *privacyPolicy) transPri2PriV2(privacykeyParirs *privacy.Privacy, r
bizlog.Error("transPub2Pri", "SendTx ", err) bizlog.Error("transPub2Pri", "SendTx ", err)
return nil, err return nil, err
} }
policy.saveFTXOInfo(tx, reqPri2Pri.Tokenname, reqPri2Pri.Sender, common.Bytes2Hex(tx.Hash()), selectedUtxo) policy.saveFTXOInfo(tx, reqPri2Pri.Tokenname, reqPri2Pri.Sender, hex.EncodeToString(tx.Hash()), selectedUtxo)
return reply, nil return reply, nil
} }
...@@ -1263,7 +1263,7 @@ func (policy *privacyPolicy) transPri2PubV2(privacykeyParirs *privacy.Privacy, r ...@@ -1263,7 +1263,7 @@ func (policy *privacyPolicy) transPri2PubV2(privacykeyParirs *privacy.Privacy, r
bizlog.Error("transPri2PubV2", "SendTx error", err) bizlog.Error("transPri2PubV2", "SendTx error", err)
return nil, err return nil, err
} }
txhashstr := common.Bytes2Hex(tx.Hash()) txhashstr := hex.EncodeToString(tx.Hash())
policy.saveFTXOInfo(tx, reqPri2Pub.Tokenname, reqPri2Pub.Sender, txhashstr, selectedUtxo) policy.saveFTXOInfo(tx, reqPri2Pub.Tokenname, reqPri2Pub.Sender, txhashstr, selectedUtxo)
bizlog.Info("transPri2PubV2", "txhash", txhashstr) bizlog.Info("transPri2PubV2", "txhash", txhashstr)
return reply, nil return reply, nil
...@@ -1352,7 +1352,7 @@ func (policy *privacyPolicy) checkWalletStoreData() { ...@@ -1352,7 +1352,7 @@ func (policy *privacyPolicy) checkWalletStoreData() {
func (policy *privacyPolicy) addDelPrivacyTxsFromBlock(tx *types.Transaction, index int32, block *types.BlockDetail, newbatch db.Batch, addDelType int32) { func (policy *privacyPolicy) addDelPrivacyTxsFromBlock(tx *types.Transaction, index int32, block *types.BlockDetail, newbatch db.Batch, addDelType int32) {
txhash := tx.Hash() txhash := tx.Hash()
txhashstr := common.Bytes2Hex(txhash) txhashstr := hex.EncodeToString(txhash)
_, err := tx.Amount() _, err := tx.Amount()
if err != nil { if err != nil {
bizlog.Error("addDelPrivacyTxsFromBlock", "txhash", txhashstr, "addDelType", addDelType, "index", index, "tx.Amount() error", err) bizlog.Error("addDelPrivacyTxsFromBlock", "txhash", txhashstr, "addDelType", addDelType, "index", index, "tx.Amount() error", err)
......
...@@ -6,11 +6,11 @@ package wallet ...@@ -6,11 +6,11 @@ package wallet
import ( import (
"bytes" "bytes"
"encoding/hex"
"sync" "sync"
"time" "time"
"unsafe" "unsafe"
//_ "github.com/33cn/plugin/plugin"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto" "github.com/33cn/chain33/common/crypto"
...@@ -131,7 +131,7 @@ func (mock *PrivacyMock) CreateUTXOs(sender string, pubkeypair string, amount in ...@@ -131,7 +131,7 @@ func (mock *PrivacyMock) CreateUTXOs(sender string, pubkeypair string, amount in
} }
txhash := tx.Hash() txhash := tx.Hash()
txhashstr := common.Bytes2Hex(txhash) txhashstr := hex.EncodeToString(txhash)
var privateAction ty.PrivacyAction var privateAction ty.PrivacyAction
if err := types.Decode(tx.GetPayload(), &privateAction); err != nil { if err := types.Decode(tx.GetPayload(), &privateAction); err != nil {
return return
......
...@@ -6,9 +6,9 @@ package wallet ...@@ -6,9 +6,9 @@ package wallet
import ( import (
"bytes" "bytes"
"encoding/hex"
"encoding/json" "encoding/json"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/db" "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
wcom "github.com/33cn/chain33/wallet/common" wcom "github.com/33cn/chain33/wallet/common"
...@@ -343,7 +343,7 @@ func (store *privacyStore) moveUTXO2FTXO(tx *types.Transaction, token, sender, t ...@@ -343,7 +343,7 @@ func (store *privacyStore) moveUTXO2FTXO(tx *types.Transaction, token, sender, t
FTXOsInOneTx := &privacytypes.FTXOsSTXOsInOneTx{} FTXOsInOneTx := &privacytypes.FTXOsSTXOsInOneTx{}
newbatch := store.NewBatch(true) newbatch := store.NewBatch(true)
for _, txOutputInfo := range selectedUtxos { for _, txOutputInfo := range selectedUtxos {
key := calcUTXOKey4TokenAddr(token, sender, common.Bytes2Hex(txOutputInfo.utxoGlobalIndex.Txhash), int(txOutputInfo.utxoGlobalIndex.Outindex)) key := calcUTXOKey4TokenAddr(token, sender, hex.EncodeToString(txOutputInfo.utxoGlobalIndex.Txhash), int(txOutputInfo.utxoGlobalIndex.Outindex))
newbatch.Delete(key) newbatch.Delete(key)
utxo := &privacytypes.UTXO{ utxo := &privacytypes.UTXO{
Amount: txOutputInfo.amount, Amount: txOutputInfo.amount,
...@@ -470,7 +470,7 @@ func (store *privacyStore) updateScanInputUTXOs(utxoGlobalIndexs []*privacytypes ...@@ -470,7 +470,7 @@ func (store *privacyStore) updateScanInputUTXOs(utxoGlobalIndexs []*privacytypes
var token string var token string
var txhash string var txhash string
for _, utxoGlobal := range utxoGlobalIndexs { for _, utxoGlobal := range utxoGlobalIndexs {
accPrivacy, err := store.isUTXOExist(common.Bytes2Hex(utxoGlobal.Txhash), int(utxoGlobal.Outindex)) accPrivacy, err := store.isUTXOExist(hex.EncodeToString(utxoGlobal.Txhash), int(utxoGlobal.Outindex))
if err == nil && accPrivacy != nil { if err == nil && accPrivacy != nil {
utxo := &privacytypes.UTXO{ utxo := &privacytypes.UTXO{
Amount: accPrivacy.Amount, Amount: accPrivacy.Amount,
...@@ -482,9 +482,9 @@ func (store *privacyStore) updateScanInputUTXOs(utxoGlobalIndexs []*privacytypes ...@@ -482,9 +482,9 @@ func (store *privacyStore) updateScanInputUTXOs(utxoGlobalIndexs []*privacytypes
utxos = append(utxos, utxo) utxos = append(utxos, utxo)
owner = accPrivacy.Owner owner = accPrivacy.Owner
token = accPrivacy.Tokenname token = accPrivacy.Tokenname
txhash = common.Bytes2Hex(accPrivacy.Txhash) txhash = hex.EncodeToString(accPrivacy.Txhash)
} }
key := calcScanPrivacyInputUTXOKey(common.Bytes2Hex(utxoGlobal.Txhash), int(utxoGlobal.Outindex)) key := calcScanPrivacyInputUTXOKey(hex.EncodeToString(utxoGlobal.Txhash), int(utxoGlobal.Outindex))
newbatch.Delete(key) newbatch.Delete(key)
} }
if len(utxos) > 0 { if len(utxos) > 0 {
...@@ -509,7 +509,7 @@ func (store *privacyStore) moveUTXO2STXO(owner, token, txhash string, utxos []*p ...@@ -509,7 +509,7 @@ func (store *privacyStore) moveUTXO2STXO(owner, token, txhash string, utxos []*p
Txhash := utxo.UtxoBasic.UtxoGlobalIndex.Txhash Txhash := utxo.UtxoBasic.UtxoGlobalIndex.Txhash
Outindex := utxo.UtxoBasic.UtxoGlobalIndex.Outindex Outindex := utxo.UtxoBasic.UtxoGlobalIndex.Outindex
//删除存在的UTXO索引 //删除存在的UTXO索引
key := calcUTXOKey4TokenAddr(token, owner, common.Bytes2Hex(Txhash), int(Outindex)) key := calcUTXOKey4TokenAddr(token, owner, hex.EncodeToString(Txhash), int(Outindex))
newbatch.Delete(key) newbatch.Delete(key)
} }
...@@ -554,7 +554,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti ...@@ -554,7 +554,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
height := txDetal.Height height := txDetal.Height
txhashInbytes := tx.Hash() txhashInbytes := tx.Hash()
txhash := common.Bytes2Hex(txhashInbytes) txhash := hex.EncodeToString(txhashInbytes)
var privateAction privacytypes.PrivacyAction var privateAction privacytypes.PrivacyAction
if err := types.Decode(tx.GetPayload(), &privateAction); err != nil { if err := types.Decode(tx.GetPayload(), &privateAction); err != nil {
bizlog.Error("selectCurrentWalletPrivacyTx failed to decode payload") bizlog.Error("selectCurrentWalletPrivacyTx failed to decode payload")
...@@ -587,8 +587,8 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti ...@@ -587,8 +587,8 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
for _, info := range privacyInfo { for _, info := range privacyInfo {
bizlog.Debug("SelectCurrentWalletPrivacyTx", "individual privacyInfo's addr", *info.Addr) bizlog.Debug("SelectCurrentWalletPrivacyTx", "individual privacyInfo's addr", *info.Addr)
privacykeyParirs := info.PrivacyKeyPair privacykeyParirs := info.PrivacyKeyPair
bizlog.Debug("SelectCurrentWalletPrivacyTx", "individual ViewPubkey", common.Bytes2Hex(privacykeyParirs.ViewPubkey.Bytes()), bizlog.Debug("SelectCurrentWalletPrivacyTx", "individual ViewPubkey", hex.EncodeToString(privacykeyParirs.ViewPubkey.Bytes()),
"individual SpendPubkey", common.Bytes2Hex(privacykeyParirs.SpendPubkey.Bytes())) "individual SpendPubkey", hex.EncodeToString(privacykeyParirs.SpendPubkey.Bytes()))
var utxos []*privacytypes.UTXO var utxos []*privacytypes.UTXO
for indexoutput, output := range privacyOutput.Keyoutput { for indexoutput, output := range privacyOutput.Keyoutput {
...@@ -610,7 +610,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti ...@@ -610,7 +610,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
if types.ExecOk == txExecRes { if types.ExecOk == txExecRes {
// 先判断该UTXO的hash是否存在,不存在则写入 // 先判断该UTXO的hash是否存在,不存在则写入
accPrivacy, err := store.isUTXOExist(common.Bytes2Hex(txhashInbytes), indexoutput) accPrivacy, err := store.isUTXOExist(hex.EncodeToString(txhashInbytes), indexoutput)
if err == nil && accPrivacy != nil { if err == nil && accPrivacy != nil {
continue continue
} }
...@@ -696,7 +696,7 @@ func (store *privacyStore) setUTXO(addr, txhash *string, outindex int, dbStore * ...@@ -696,7 +696,7 @@ func (store *privacyStore) setUTXO(addr, txhash *string, outindex int, dbStore *
func (store *privacyStore) storeScanPrivacyInputUTXO(utxoGlobalIndexs []*privacytypes.UTXOGlobalIndex, newbatch db.Batch) { func (store *privacyStore) storeScanPrivacyInputUTXO(utxoGlobalIndexs []*privacytypes.UTXOGlobalIndex, newbatch db.Batch) {
for _, utxoGlobalIndex := range utxoGlobalIndexs { for _, utxoGlobalIndex := range utxoGlobalIndexs {
key1 := calcScanPrivacyInputUTXOKey(common.Bytes2Hex(utxoGlobalIndex.Txhash), int(utxoGlobalIndex.Outindex)) key1 := calcScanPrivacyInputUTXOKey(hex.EncodeToString(utxoGlobalIndex.Txhash), int(utxoGlobalIndex.Outindex))
utxoIndex := &privacytypes.UTXOGlobalIndex{ utxoIndex := &privacytypes.UTXOGlobalIndex{
Txhash: utxoGlobalIndex.Txhash, Txhash: utxoGlobalIndex.Txhash,
Outindex: utxoGlobalIndex.Outindex, Outindex: utxoGlobalIndex.Outindex,
...@@ -734,7 +734,7 @@ func (store *privacyStore) listSpendUTXOs(token, addr string) (*privacytypes.UTX ...@@ -734,7 +734,7 @@ func (store *privacyStore) listSpendUTXOs(token, addr string) (*privacytypes.UTX
} }
for _, ftxo := range ftxosInOneTx.Utxos { for _, ftxo := range ftxosInOneTx.Utxos {
utxohash := common.Bytes2Hex(ftxo.UtxoBasic.UtxoGlobalIndex.Txhash) utxohash := hex.EncodeToString(ftxo.UtxoBasic.UtxoGlobalIndex.Txhash)
value1, err := store.Get(calcUTXOKey(utxohash, int(ftxo.UtxoBasic.UtxoGlobalIndex.Outindex))) value1, err := store.Get(calcUTXOKey(utxohash, int(ftxo.UtxoBasic.UtxoGlobalIndex.Outindex)))
if err != nil { if err != nil {
continue continue
...@@ -879,7 +879,7 @@ func (store *privacyStore) moveFTXO2UTXO(key1 []byte, newbatch db.Batch) { ...@@ -879,7 +879,7 @@ func (store *privacyStore) moveFTXO2UTXO(key1 []byte, newbatch db.Batch) {
return return
} }
for _, ftxo := range ftxosInOneTx.Utxos { for _, ftxo := range ftxosInOneTx.Utxos {
utxohash := common.Bytes2Hex(ftxo.UtxoBasic.UtxoGlobalIndex.Txhash) utxohash := hex.EncodeToString(ftxo.UtxoBasic.UtxoGlobalIndex.Txhash)
outindex := int(ftxo.UtxoBasic.UtxoGlobalIndex.Outindex) outindex := int(ftxo.UtxoBasic.UtxoGlobalIndex.Outindex)
key := calcUTXOKey4TokenAddr(ftxosInOneTx.Tokenname, ftxosInOneTx.Sender, utxohash, outindex) key := calcUTXOKey4TokenAddr(ftxosInOneTx.Tokenname, ftxosInOneTx.Sender, utxohash, outindex)
value := calcUTXOKey(utxohash, int(ftxo.UtxoBasic.UtxoGlobalIndex.Outindex)) value := calcUTXOKey(utxohash, int(ftxo.UtxoBasic.UtxoGlobalIndex.Outindex))
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package wallet package wallet
import ( import (
"encoding/hex"
"unsafe" "unsafe"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
...@@ -28,7 +29,7 @@ func checkAmountValid(amount int64) bool { ...@@ -28,7 +29,7 @@ func checkAmountValid(amount int64) bool {
func makeViewSpendPubKeyPairToString(viewPubKey, spendPubKey []byte) string { func makeViewSpendPubKeyPairToString(viewPubKey, spendPubKey []byte) string {
pair := viewPubKey pair := viewPubKey
pair = append(pair, spendPubKey...) pair = append(pair, spendPubKey...)
return common.Bytes2Hex(pair) return hex.EncodeToString(pair)
} }
//将amount切分为1,2,5的组合,这样在进行amount混淆的时候就能够方便获取相同额度的utxo //将amount切分为1,2,5的组合,这样在进行amount混淆的时候就能够方便获取相同额度的utxo
......
...@@ -6,21 +6,19 @@ package executor ...@@ -6,21 +6,19 @@ package executor
import ( import (
"bytes" "bytes"
"math/big"
"strings" "strings"
"time" "time"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/golang/protobuf/proto"
"math/big"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/difficulty" "github.com/33cn/chain33/common/difficulty"
"github.com/33cn/chain33/common/merkle" "github.com/33cn/chain33/common/merkle"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
ty "github.com/33cn/plugin/plugin/dapp/relay/types" ty "github.com/33cn/plugin/plugin/dapp/relay/types"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/golang/protobuf/proto"
) )
type btcStore struct { type btcStore struct {
...@@ -284,8 +282,8 @@ func getRawTxHash(rawtx string) ([]byte, error) { ...@@ -284,8 +282,8 @@ func getRawTxHash(rawtx string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
h := common.DoubleHashH(data) h := common.Sha2Sum(data)
return h.Bytes(), nil return h, nil
} }
func getSiblingHash(sibling string) ([][]byte, error) { func getSiblingHash(sibling string) ([][]byte, error) {
...@@ -308,10 +306,17 @@ func btcHashStrRevers(str string) ([]byte, error) { ...@@ -308,10 +306,17 @@ func btcHashStrRevers(str string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
merkle := common.BytesToHash(data).Revers().Bytes() merkle := reverse(data)
return merkle, nil return merkle, nil
} }
func reverse(h []byte) []byte {
for i := 0; i < common.Sha256Len/2; i++ {
h[i], h[common.Sha256Len-1-i] = h[common.Sha256Len-1-i], h[i]
}
return h
}
func (b *btcStore) getHeadHeightList(req *ty.ReqRelayBtcHeaderHeightList) (types.Message, error) { func (b *btcStore) getHeadHeightList(req *ty.ReqRelayBtcHeaderHeightList) (types.Message, error) {
prefix := []byte(relayBTCHeaderHeightList) prefix := []byte(relayBTCHeaderHeightList)
key := calcBtcHeaderKeyHeightList(req.ReqHeight) key := calcBtcHeaderKeyHeightList(req.ReqHeight)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package executor package executor
import ( import (
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
...@@ -247,7 +248,7 @@ type tradeAction struct { ...@@ -247,7 +248,7 @@ type tradeAction struct {
} }
func newTradeAction(t *trade, tx *types.Transaction) *tradeAction { func newTradeAction(t *trade, tx *types.Transaction) *tradeAction {
hash := common.Bytes2Hex(tx.Hash()) hash := hex.EncodeToString(tx.Hash())
fromaddr := tx.From() fromaddr := tx.From()
return &tradeAction{t.GetCoinsAccount(), t.GetStateDB(), hash, fromaddr, return &tradeAction{t.GetCoinsAccount(), t.GetStateDB(), hash, fromaddr,
t.GetBlockTime(), t.GetHeight(), dapp.ExecAddress(string(tx.Execer))} t.GetBlockTime(), t.GetHeight(), dapp.ExecAddress(string(tx.Execer))}
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
package executor package executor
import ( import (
"encoding/hex"
"fmt" "fmt"
"github.com/33cn/chain33/common"
pty "github.com/33cn/plugin/plugin/dapp/unfreeze/types" pty "github.com/33cn/plugin/plugin/dapp/unfreeze/types"
) )
...@@ -18,7 +18,7 @@ var ( ...@@ -18,7 +18,7 @@ var (
) )
func unfreezeID(txHash []byte) []byte { func unfreezeID(txHash []byte) []byte {
return []byte(fmt.Sprintf("%s%s", id, common.Bytes2Hex(txHash))) return []byte(fmt.Sprintf("%s%s", id, hex.EncodeToString(txHash)))
} }
func initKey(init string) []byte { func initKey(init string) []byte {
......
...@@ -81,7 +81,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb dbm.DB) error { ...@@ -81,7 +81,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb dbm.DB) error {
} else { } else {
enc, _ := proto.Marshal(n.create()) enc, _ := proto.Marshal(n.create())
if !ok { if !ok {
hash = createHashNode(common.ShaKeccak256(enc)) hash = createHashNode(common.Sha3(enc))
} }
proofDb.Set(hash.GetHash(), enc) proofDb.Set(hash.GetHash(), enc)
} }
......
...@@ -51,7 +51,7 @@ func makeProvers(trie *Trie) []func(key []byte) *dbm.GoMemDB { ...@@ -51,7 +51,7 @@ func makeProvers(trie *Trie) []func(key []byte) *dbm.GoMemDB {
proof, _ := dbm.NewGoMemDB("gomemdb", "", 128) proof, _ := dbm.NewGoMemDB("gomemdb", "", 128)
if it := NewIterator(trie.NodeIterator(key)); it.Next() && bytes.Equal(key, it.Key) { if it := NewIterator(trie.NodeIterator(key)); it.Next() && bytes.Equal(key, it.Key) {
for _, p := range it.Prove() { for _, p := range it.Prove() {
proof.Set(common.ShaKeccak256(p), p) proof.Set(common.Sha3(p), p)
} }
} }
return proof return proof
...@@ -130,7 +130,7 @@ func TestBadProof(t *testing.T) { ...@@ -130,7 +130,7 @@ func TestBadProof(t *testing.T) {
proof.Delete(key) proof.Delete(key)
mutateByte(val) mutateByte(val)
proof.Set(common.ShaKeccak256(val), val) proof.Set(common.Sha3(val), val)
if _, _, err := VerifyProof(root, kv.k, proof); err == nil { if _, _, err := VerifyProof(root, kv.k, proof); err == nil {
t.Fatalf("prover %d: expected proof to fail for key %x", i, kv.k) t.Fatalf("prover %d: expected proof to fail for key %x", i, kv.k)
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package mpt package mpt
import ( import (
...@@ -101,7 +100,7 @@ func TestSecureGetKey(t *testing.T) { ...@@ -101,7 +100,7 @@ func TestSecureGetKey(t *testing.T) {
key := []byte("foo") key := []byte("foo")
value := []byte("bar") value := []byte("bar")
seckey := common.ShaKeccak256(key) seckey := common.Sha3(key)
if !bytes.Equal(trie.Get(key), value) { if !bytes.Equal(trie.Get(key), value) {
t.Errorf("Get did not return bar") t.Errorf("Get did not return bar")
......
...@@ -507,7 +507,7 @@ func (t *TrieEx) Get(key []byte) []byte { ...@@ -507,7 +507,7 @@ func (t *TrieEx) Get(key []byte) []byte {
// TryGet returns the value for key stored in the trie. // TryGet returns the value for key stored in the trie.
func (t *TrieEx) TryGet(key []byte) ([]byte, error) { func (t *TrieEx) TryGet(key []byte) ([]byte, error) {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
return t.Trie.TryGet(key) return t.Trie.TryGet(key)
} }
...@@ -522,7 +522,7 @@ func (t *TrieEx) Update(key, value []byte) { ...@@ -522,7 +522,7 @@ func (t *TrieEx) Update(key, value []byte) {
// TryUpdate set key with value in the trie // TryUpdate set key with value in the trie
func (t *TrieEx) TryUpdate(key, value []byte) error { func (t *TrieEx) TryUpdate(key, value []byte) error {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
return t.Trie.TryUpdate(key, value) return t.Trie.TryUpdate(key, value)
} }
...@@ -537,7 +537,7 @@ func (t *TrieEx) Delete(key []byte) { ...@@ -537,7 +537,7 @@ func (t *TrieEx) Delete(key []byte) {
// TryDelete removes any existing value for key from the trie. // TryDelete removes any existing value for key from the trie.
func (t *TrieEx) TryDelete(key []byte) error { func (t *TrieEx) TryDelete(key []byte) error {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
return t.Trie.TryDelete(key) return t.Trie.TryDelete(key)
} }
...@@ -600,7 +600,7 @@ func GetKVPair(db dbm.DB, storeGet *types.StoreGet) ([][]byte, error) { ...@@ -600,7 +600,7 @@ func GetKVPair(db dbm.DB, storeGet *types.StoreGet) ([][]byte, error) {
// GetKVPairProof 获取指定k:v pair的proof证明 // GetKVPairProof 获取指定k:v pair的proof证明
func GetKVPairProof(db dbm.DB, roothash []byte, key []byte) []byte { func GetKVPairProof(db dbm.DB, roothash []byte, key []byte) []byte {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
value, _, err := VerifyProof(common.BytesToHash(roothash), key, db) value, _, err := VerifyProof(common.BytesToHash(roothash), key, db)
if nil != err { if nil != err {
...@@ -642,7 +642,7 @@ func DelKVPair(db dbm.DB, storeDel *types.StoreGet) ([]byte, [][]byte, error) { ...@@ -642,7 +642,7 @@ func DelKVPair(db dbm.DB, storeDel *types.StoreGet) ([]byte, [][]byte, error) {
// VerifyKVPairProof 验证KVPair 的证明 // VerifyKVPairProof 验证KVPair 的证明
func VerifyKVPairProof(db dbm.DB, roothash []byte, keyvalue types.KeyValue, proof []byte) bool { func VerifyKVPairProof(db dbm.DB, roothash []byte, keyvalue types.KeyValue, proof []byte) bool {
if enableSecure { if enableSecure {
keyvalue.Key = common.ShaKeccak256(keyvalue.Key) keyvalue.Key = common.Sha3(keyvalue.Key)
} }
_, _, err := VerifyProof(common.BytesToHash(roothash), keyvalue.Key, db) _, _, err := VerifyProof(common.BytesToHash(roothash), keyvalue.Key, db)
return nil == err return nil == err
......
...@@ -612,7 +612,7 @@ func BenchmarkHash(b *testing.B) { ...@@ -612,7 +612,7 @@ func BenchmarkHash(b *testing.B) {
// Insert the accounts into the trie and hash it // Insert the accounts into the trie and hash it
trie := newEmpty() trie := newEmpty()
for i := 0; i < len(addresses); i++ { for i := 0; i < len(addresses); i++ {
trie.Update(common.ShaKeccak256(addresses[i][:]), accounts[i]) trie.Update(common.Sha3(addresses[i][:]), accounts[i])
} }
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
......
...@@ -81,7 +81,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb dbm.DB) error { ...@@ -81,7 +81,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb dbm.DB) error {
} else { } else {
enc, _ := rlp.EncodeToBytes(n) enc, _ := rlp.EncodeToBytes(n)
if !ok { if !ok {
hash = common.ShaKeccak256(enc) hash = common.Sha3(enc)
} }
proofDb.Set(hash, enc) proofDb.Set(hash, enc)
} }
......
...@@ -53,7 +53,7 @@ func makeProvers(trie *Trie) []func(key []byte) *dbm.GoMemDB { ...@@ -53,7 +53,7 @@ func makeProvers(trie *Trie) []func(key []byte) *dbm.GoMemDB {
proof, _ := dbm.NewGoMemDB("gomemdb", "", 128) proof, _ := dbm.NewGoMemDB("gomemdb", "", 128)
if it := NewIterator(trie.NodeIterator(key)); it.Next() && bytes.Equal(key, it.Key) { if it := NewIterator(trie.NodeIterator(key)); it.Next() && bytes.Equal(key, it.Key) {
for _, p := range it.Prove() { for _, p := range it.Prove() {
proof.Set(common.ShaKeccak256(p), p) proof.Set(common.Sha3(p), p)
} }
} }
return proof return proof
...@@ -132,7 +132,7 @@ func TestBadProof(t *testing.T) { ...@@ -132,7 +132,7 @@ func TestBadProof(t *testing.T) {
proof.Delete(key) proof.Delete(key)
mutateByte(val) mutateByte(val)
proof.Set(common.ShaKeccak256(val), val) proof.Set(common.Sha3(val), val)
if _, _, err := VerifyProof(root, kv.k, proof); err == nil { if _, _, err := VerifyProof(root, kv.k, proof); err == nil {
t.Fatalf("prover %d: expected proof to fail for key %x", i, kv.k) t.Fatalf("prover %d: expected proof to fail for key %x", i, kv.k)
......
...@@ -101,7 +101,7 @@ func TestSecureGetKey(t *testing.T) { ...@@ -101,7 +101,7 @@ func TestSecureGetKey(t *testing.T) {
key := []byte("foo") key := []byte("foo")
value := []byte("bar") value := []byte("bar")
seckey := common.ShaKeccak256(key) seckey := common.Sha3(key)
if !bytes.Equal(trie.Get(key), value) { if !bytes.Equal(trie.Get(key), value) {
t.Errorf("Get did not return bar") t.Errorf("Get did not return bar")
......
...@@ -507,7 +507,7 @@ func (t *TrieEx) Get(key []byte) []byte { ...@@ -507,7 +507,7 @@ func (t *TrieEx) Get(key []byte) []byte {
// TryGet returns the value for key stored in the trie. // TryGet returns the value for key stored in the trie.
func (t *TrieEx) TryGet(key []byte) ([]byte, error) { func (t *TrieEx) TryGet(key []byte) ([]byte, error) {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
return t.Trie.TryGet(key) return t.Trie.TryGet(key)
} }
...@@ -522,7 +522,7 @@ func (t *TrieEx) Update(key, value []byte) { ...@@ -522,7 +522,7 @@ func (t *TrieEx) Update(key, value []byte) {
// TryUpdate set key with value in the trie // TryUpdate set key with value in the trie
func (t *TrieEx) TryUpdate(key, value []byte) error { func (t *TrieEx) TryUpdate(key, value []byte) error {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
return t.Trie.TryUpdate(key, value) return t.Trie.TryUpdate(key, value)
} }
...@@ -537,7 +537,7 @@ func (t *TrieEx) Delete(key []byte) { ...@@ -537,7 +537,7 @@ func (t *TrieEx) Delete(key []byte) {
// TryDelete removes any existing value for key from the trie. // TryDelete removes any existing value for key from the trie.
func (t *TrieEx) TryDelete(key []byte) error { func (t *TrieEx) TryDelete(key []byte) error {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
return t.Trie.TryDelete(key) return t.Trie.TryDelete(key)
} }
...@@ -600,7 +600,7 @@ func GetKVPair(db dbm.DB, storeGet *types.StoreGet) ([][]byte, error) { ...@@ -600,7 +600,7 @@ func GetKVPair(db dbm.DB, storeGet *types.StoreGet) ([][]byte, error) {
// GetKVPairProof 获取指定k:v pair的proof证明 // GetKVPairProof 获取指定k:v pair的proof证明
func GetKVPairProof(db dbm.DB, roothash []byte, key []byte) []byte { func GetKVPairProof(db dbm.DB, roothash []byte, key []byte) []byte {
if enableSecure { if enableSecure {
key = common.ShaKeccak256(key) key = common.Sha3(key)
} }
value, _, err := VerifyProof(common.BytesToHash(roothash), key, db) value, _, err := VerifyProof(common.BytesToHash(roothash), key, db)
if nil != err { if nil != err {
...@@ -642,7 +642,7 @@ func DelKVPair(db dbm.DB, storeDel *types.StoreGet) ([]byte, [][]byte, error) { ...@@ -642,7 +642,7 @@ func DelKVPair(db dbm.DB, storeDel *types.StoreGet) ([]byte, [][]byte, error) {
// VerifyKVPairProof 验证KVPair 的证明 // VerifyKVPairProof 验证KVPair 的证明
func VerifyKVPairProof(db dbm.DB, roothash []byte, keyvalue types.KeyValue, proof []byte) bool { func VerifyKVPairProof(db dbm.DB, roothash []byte, keyvalue types.KeyValue, proof []byte) bool {
if enableSecure { if enableSecure {
keyvalue.Key = common.ShaKeccak256(keyvalue.Key) keyvalue.Key = common.Sha3(keyvalue.Key)
} }
_, _, err := VerifyProof(common.BytesToHash(roothash), keyvalue.Key, db) _, _, err := VerifyProof(common.BytesToHash(roothash), keyvalue.Key, db)
return nil == err return nil == err
......
...@@ -600,14 +600,14 @@ func BenchmarkHash(b *testing.B) { ...@@ -600,14 +600,14 @@ func BenchmarkHash(b *testing.B) {
nonce = uint64(random.Int63()) nonce = uint64(random.Int63())
balance = new(big.Int).Rand(random, new(big.Int).Exp(Big2, Big256, nil)) balance = new(big.Int).Rand(random, new(big.Int).Exp(Big2, Big256, nil))
root = emptyRoot root = emptyRoot
code = common.ShaKeccak256(nil) code = common.Sha3(nil)
) )
accounts[i], _ = rlp.EncodeToBytes([]interface{}{nonce, balance, root, code}) accounts[i], _ = rlp.EncodeToBytes([]interface{}{nonce, balance, root, code})
} }
// Insert the accounts into the trie and hash it // Insert the accounts into the trie and hash it
trie := newEmpty() trie := newEmpty()
for i := 0; i < len(addresses); i++ { for i := 0; i < len(addresses); i++ {
trie.Update(common.ShaKeccak256(addresses[i][:]), accounts[i]) trie.Update(common.Sha3(addresses[i][:]), accounts[i])
} }
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
......
...@@ -107,7 +107,7 @@ func HashToAddress(version byte, in []byte) *Address { ...@@ -107,7 +107,7 @@ func HashToAddress(version byte, in []byte) *Address {
a.Pubkey = make([]byte, len(in)) a.Pubkey = make([]byte, len(in))
copy(a.Pubkey[:], in[:]) copy(a.Pubkey[:], in[:])
a.Version = version a.Version = version
a.Hash160 = common.Rimp160(in) a.SetBytes(common.Rimp160(in))
return a return a
} }
...@@ -191,12 +191,17 @@ func NewAddrFromString(hs string) (a *Address, e error) { ...@@ -191,12 +191,17 @@ func NewAddrFromString(hs string) (a *Address, e error) {
//Address 地址 //Address 地址
type Address struct { type Address struct {
Version byte Version byte
Hash160 []byte // For a stealth address: it's HASH160 Hash160 [20]byte // For a stealth address: it's HASH160
Checksum []byte // Unused for a stealth address Checksum []byte // Unused for a stealth address
Pubkey []byte // Unused for a stealth address Pubkey []byte // Unused for a stealth address
Enc58str string Enc58str string
} }
//SetBytes 设置地址的bytes
func (a *Address) SetBytes(b []byte) {
copy(a.Hash160[:], b)
}
func (a *Address) String() string { func (a *Address) String() string {
if a.Enc58str == "" { if a.Enc58str == "" {
var ad [25]byte var ad [25]byte
......
...@@ -15,6 +15,36 @@ import ( ...@@ -15,6 +15,36 @@ import (
//Sha256Len sha256 bytes len //Sha256Len sha256 bytes len
const Sha256Len = 32 const Sha256Len = 32
//Hash type
type Hash [Sha256Len]byte
//BytesToHash []byte -> hash
func BytesToHash(b []byte) Hash {
var h Hash
h.SetBytes(b)
return h
}
//HexToHash hex -> hash
func HexToHash(s string) Hash {
b, err := FromHex(s)
if err != nil {
panic(err)
}
return BytesToHash(b)
}
//Bytes Get the []byte representation of the underlying hash
func (h Hash) Bytes() []byte { return h[:] }
//SetBytes Sets the hash to the value of b. If b is larger than len(h), 'b' will be cropped (from the left).
func (h *Hash) SetBytes(b []byte) {
if len(b) > len(h) {
b = b[len(b)-Sha256Len:]
}
copy(h[Sha256Len-len(b):], b)
}
//ToHex []byte -> hex //ToHex []byte -> hex
func ToHex(b []byte) string { func ToHex(b []byte) string {
hex := hex.EncodeToString(b) hex := hex.EncodeToString(b)
......
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