Skip to content

Commit

Permalink
[lint] fix ineffassign #708
Browse files Browse the repository at this point in the history
  • Loading branch information
u5surf committed Apr 11, 2019
1 parent 8d38f12 commit a835435
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/proto/discovery/pingpong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func TestSerialize(test *testing.T) {
buf2 = pong1.ConstructPongMessage()

msg2, err := proto.GetMessagePayload(buf2)
if err != nil {
test.Error("GetMessagePayload Failed!")
}
pong, err := GetPongMessage(msg2)
if err != nil {
test.Error("Pong failed!")
Expand Down
15 changes: 11 additions & 4 deletions api/service/explorer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,19 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
}
db := s.storage.GetDB()
fromInt, err := strconv.Atoi(from)
if err != nil {
json.NewEncoder(w).Encode(data.Blocks)
return
}
var toInt int
if to == "" {
bytes, err := db.Get([]byte(BlockHeightKey))
if err == nil {
toInt, err = strconv.Atoi(string(bytes))
}
toInt, err = func() (int, error) {
bytes, err := db.Get([]byte(BlockHeightKey))
if err == nil {
return strconv.Atoi(string(bytes))
}
return toInt, err
}()
} else {
toInt, err = strconv.Atoi(to)
}
Expand Down
18 changes: 18 additions & 0 deletions consensus/consensus_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err)
}
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}

copy(consensusLeader.blockHash[:], hashBytes[:])

Expand Down Expand Up @@ -140,8 +146,14 @@ func TestProcessMessageValidatorPrepared(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err)
}
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}

copy(consensusLeader.blockHash[:], hashBytes[:])

Expand Down Expand Up @@ -216,8 +228,14 @@ func TestProcessMessageValidatorCommitted(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err)
}
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}

copy(consensusLeader.blockHash[:], hashBytes[:])

Expand Down
5 changes: 5 additions & 0 deletions node/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func (node *Node) QueryStakeInfo() *structs.StakeInfoReturnValue {

state, err := node.blockchain.State()

if err != nil {
utils.GetLogInstance().Error("Failed to get blockchain state", "error", err)
return nil
}

stakingContractAddress := crypto.CreateAddress(deployerAddress, uint64(0))
tx := types.NewTransaction(
state.GetNonce(deployerAddress),
Expand Down
4 changes: 4 additions & 0 deletions node/demo_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (node *Node) GetResult(priKey string) (players []string, balances []*big.In

demoContractAddress := node.DemoContractAddress
key, err := crypto.HexToECDSA(priKey)
if err != nil {
utils.GetLogInstance().Error("Failed to parse private key", "error", err)
}

nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(key.PublicKey))

tx := types.NewTransaction(
Expand Down
7 changes: 6 additions & 1 deletion test/p2pchat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ func main() {
}

if err != nil {
fmt.Printf("pubsub error: %v", err)
fmt.Printf("pub error: %v", err)
panic(err)
}

sub, err := ps.Subscribe("pubsubtestchannel")

if err != nil {
fmt.Printf("sub error: %v", err)
panic(err)
}

go writePubsub(ps)
go readPubsub(sub)

Expand Down

0 comments on commit a835435

Please sign in to comment.