Skip to content

Commit

Permalink
fix 193: qcp.Hash tag return hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
TokenxyWZY committed Jun 26, 2019
1 parent 84a8d01 commit 899d1d2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions baseabci/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func (app *BaseApp) runTxStd(ctx ctx.Context, tx *txs.TxStd, txStdFromChainID st
result.Tags = result.Tags.AppendTag(qcp.QcpFrom, txQcp.From).
AppendTag(qcp.QcpTo, txQcp.To).
AppendTag(qcp.QcpSequence, strconv.FormatInt(txQcp.Sequence, 10)).
AppendTags(types.NewTags(qcp.QcpHash, crypto.Sha256(txQcp.BuildSignatureBytes())))
AppendTags(types.NewTags(qcp.QcpHash, qcp.GenQcpTxHash(txQcp)))
}
}

Expand Down Expand Up @@ -824,7 +824,7 @@ func (app *BaseApp) deliverTxQcp(ctx ctx.Context, tx *txs.TxQcp) (result types.R

txQcp := saveCrossChainResult(ctx, crossTxQcp, true, nil)
result.Tags = result.Tags.AppendTag(qcp.QcpSequence, strconv.FormatInt(txQcp.Sequence, 10)).
AppendTags(types.NewTags(qcp.QcpHash, crypto.Sha256(txQcp.BuildSignatureBytes())))
AppendTags(types.NewTags(qcp.QcpHash, qcp.GenQcpTxHash(txQcp)))
}

}()
Expand Down
12 changes: 9 additions & 3 deletions baseabci/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package baseabci
import (
"errors"
"fmt"
"math/rand"
"os"
"testing"

"github.com/QOSGroup/qbase/account"
"github.com/QOSGroup/qbase/context"
"github.com/QOSGroup/qbase/store"
"github.com/QOSGroup/qbase/txs"
"github.com/QOSGroup/qbase/types"
"github.com/stretchr/testify/require"
"math/rand"
"os"
"testing"

go_amino "github.com/tendermint/go-amino"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -417,6 +418,11 @@ func TestCrossStdTx(t *testing.T) {

for i, stdTxBz := range txss {
res := app.DeliverTx(stdTxBz)

for _, p := range res.GetTags() {
fmt.Println(string(p.GetKey()), string(p.GetValue()))
}

if i >= 5 {
require.NotEqual(t, uint32(0), uint32(res.Code))
} else {
Expand Down
12 changes: 12 additions & 0 deletions qcp/qcp.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package qcp

import (
"encoding/hex"

"github.com/QOSGroup/qbase/txs"
"github.com/tendermint/tendermint/crypto"
)

const (
QcpFrom = "qcp.from"
QcpTo = "qcp.to"
QcpSequence = "qcp.sequence"
QcpHash = "qcp.hash"
)

func GenQcpTxHash(tx *txs.TxQcp) string {
bz := crypto.Sha256(tx.BuildSignatureBytes())
return hex.EncodeToString(bz)
}

0 comments on commit 899d1d2

Please sign in to comment.