[lint] fix ineffassign #708

pull/713/head
u5surf 6 years ago
parent 8d38f12425
commit a835435b4a
  1. 3
      api/proto/discovery/pingpong_test.go
  2. 15
      api/service/explorer/service.go
  3. 18
      consensus/consensus_validator_test.go
  4. 5
      node/contract.go
  5. 4
      node/demo_contract.go
  6. 7
      test/p2pchat/chat.go

@ -89,6 +89,9 @@ func TestSerialize(test *testing.T) {
buf2 = pong1.ConstructPongMessage() buf2 = pong1.ConstructPongMessage()
msg2, err := proto.GetMessagePayload(buf2) msg2, err := proto.GetMessagePayload(buf2)
if err != nil {
test.Error("GetMessagePayload Failed!")
}
pong, err := GetPongMessage(msg2) pong, err := GetPongMessage(msg2)
if err != nil { if err != nil {
test.Error("Pong failed!") test.Error("Pong failed!")

@ -146,12 +146,19 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
} }
db := s.storage.GetDB() db := s.storage.GetDB()
fromInt, err := strconv.Atoi(from) fromInt, err := strconv.Atoi(from)
if err != nil {
json.NewEncoder(w).Encode(data.Blocks)
return
}
var toInt int var toInt int
if to == "" { if to == "" {
bytes, err := db.Get([]byte(BlockHeightKey)) toInt, err = func() (int, error) {
if err == nil { bytes, err := db.Get([]byte(BlockHeightKey))
toInt, err = strconv.Atoi(string(bytes)) if err == nil {
} return strconv.Atoi(string(bytes))
}
return toInt, err
}()
} else { } else {
toInt, err = strconv.Atoi(to) toInt, err = strconv.Atoi(to)
} }

@ -79,8 +79,14 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err) test.Fatalf("Cannot craeate consensus: %v", err)
} }
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}
copy(consensusLeader.blockHash[:], hashBytes[:]) copy(consensusLeader.blockHash[:], hashBytes[:])
@ -140,8 +146,14 @@ func TestProcessMessageValidatorPrepared(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err) test.Fatalf("Cannot craeate consensus: %v", err)
} }
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}
copy(consensusLeader.blockHash[:], hashBytes[:]) copy(consensusLeader.blockHash[:], hashBytes[:])
@ -216,8 +228,14 @@ func TestProcessMessageValidatorCommitted(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err) test.Fatalf("Cannot craeate consensus: %v", err)
} }
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}
copy(consensusLeader.blockHash[:], hashBytes[:]) copy(consensusLeader.blockHash[:], hashBytes[:])

@ -75,6 +75,11 @@ func (node *Node) QueryStakeInfo() *structs.StakeInfoReturnValue {
state, err := node.blockchain.State() 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)) stakingContractAddress := crypto.CreateAddress(deployerAddress, uint64(0))
tx := types.NewTransaction( tx := types.NewTransaction(
state.GetNonce(deployerAddress), state.GetNonce(deployerAddress),

@ -130,6 +130,10 @@ func (node *Node) GetResult(priKey string) (players []string, balances []*big.In
demoContractAddress := node.DemoContractAddress demoContractAddress := node.DemoContractAddress
key, err := crypto.HexToECDSA(priKey) 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)) nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(key.PublicKey))
tx := types.NewTransaction( tx := types.NewTransaction(

@ -136,12 +136,17 @@ func main() {
} }
if err != nil { if err != nil {
fmt.Printf("pubsub error: %v", err) fmt.Printf("pub error: %v", err)
panic(err) panic(err)
} }
sub, err := ps.Subscribe("pubsubtestchannel") sub, err := ps.Subscribe("pubsubtestchannel")
if err != nil {
fmt.Printf("sub error: %v", err)
panic(err)
}
go writePubsub(ps) go writePubsub(ps)
go readPubsub(sub) go readPubsub(sub)

Loading…
Cancel
Save