Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Nov 29, 2023
1 parent 247b706 commit 5329e39
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
19 changes: 8 additions & 11 deletions plugins/recover/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"

airdrop "github.com/bnb-chain/node/plugins/recover"
)
Expand Down Expand Up @@ -83,17 +81,16 @@ func SignAndPrint(ctx context.CLIContext, builder authtxb.TxBuilder, msg sdk.Msg
}

var tx auth.StdTx
if err = builder.Codec.UnmarshalBinaryLengthPrefixed(txBytes, &tx); err == nil {
json, err := builder.Codec.MarshalJSON(tx)
if err == nil {
fmt.Printf("TX JSON: %s\n", json)
}
err = builder.Codec.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
if err != nil {

Check failure on line 85 in plugins/recover/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / lint

SA9003: empty branch (staticcheck)

}
json, err := builder.Codec.MarshalJSON(tx)
if err != nil {
return err
}
hexBytes := make([]byte, len(txBytes)*2)
hex.Encode(hexBytes, txBytes)
txHash := cmn.HexBytes(tmhash.Sum(txBytes)).String()
fmt.Printf("Transaction hash: %s, Transaction hex: %s\n", txHash, hexBytes)

fmt.Printf("TX JSON: %s\n", json)
fmt.Println("Sign Message: ", string(stdMsg.Bytes()))
fmt.Println("Sign Message Hash: ", hex.EncodeToString(crypto.Sha256(stdMsg.Bytes())))
sig := tx.GetSignatures()[0]
Expand Down
2 changes: 1 addition & 1 deletion plugins/tokens/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
SwapID: swapID,
})
if !result.IsOK() {
logger.Error("Refound error", "swapId", swapID)
logger.Error("Refund error", "swapId", swapID)
continue
}
i++
Expand Down
10 changes: 8 additions & 2 deletions plugins/tokens/timelock/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package timelock

import (
"bytes"
"encoding/hex"
"fmt"
"strconv"

Expand All @@ -18,9 +19,14 @@ func KeyRecordSubSpace(addr sdk.AccAddress) []byte {

func ParseKeyRecord(key []byte) (sdk.AccAddress, int64, error) {
key = bytes.TrimPrefix(key, []byte("record:"))
addr := sdk.AccAddress(key[:sdk.AddrLen])
accKeyStr := key[:sdk.AddrLen*2]
accKeyBytes, err := hex.DecodeString(string(accKeyStr))
if err != nil {
return []byte{}, 0, err
}
addr := sdk.AccAddress(accKeyBytes)

id, err := strconv.ParseInt(string(key[sdk.AddrLen+1:]), 10, 64)
id, err := strconv.ParseInt(string(key[sdk.AddrLen*2+1:]), 10, 64)
if err != nil {
return []byte{}, 0, err
}
Expand Down
32 changes: 32 additions & 0 deletions plugins/tokens/timelock/keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package timelock

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestParseKeyRecord(t *testing.T) {
account, err := sdk.AccAddressFromHex("5B38Da6a701c568545dCfcB03FcB875f56beddC4")
if err != nil {
t.Fatal(err)
return
}
accId := int64(1513)
key := KeyRecord(account, accId)

acc, id, err := ParseKeyRecord([]byte(key))
if err != nil {
t.Fatal(err)
return
}

if !acc.Equals(account) {
t.Fatal("parse account error")
return
}
if id != accId {
t.Fatal("parse id error")
return
}
}

0 comments on commit 5329e39

Please sign in to comment.