Skip to content

Commit f1d85fc

Browse files
committed
fix crash when checking account
1 parent 130fe3e commit f1d85fc

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

REST/EPAccount.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package REST
22

33
import (
4+
"fmt"
45
"github.com/bazo-blockchain/bazo-client/client"
5-
"github.com/bazo-blockchain/bazo-client/network"
6-
"github.com/bazo-blockchain/bazo-miner/protocol"
76
"github.com/gorilla/mux"
87
"math/big"
98
"net/http"
@@ -16,22 +15,13 @@ func GetAccountEndpoint(w http.ResponseWriter, req *http.Request) {
1615
logger.Printf("Incoming acc request for id: %v", param)
1716

1817
var address [64]byte
19-
var addressHash [32]byte
2018

2119
pubKeyInt, _ := new(big.Int).SetString(param, 16)
2220

23-
if len(param) == 64 {
24-
copy(addressHash[:], pubKeyInt.Bytes())
25-
26-
network.AccReq(false, addressHash)
27-
28-
accI, _ := network.Fetch(network.AccChan)
29-
acc := accI.(*protocol.Account)
30-
31-
address = acc.Address
32-
} else if len(param) == 128 {
21+
if len(param) == 128 {
3322
copy(address[:], pubKeyInt.Bytes())
34-
addressHash = protocol.SerializeHashContent(address)
23+
} else {
24+
logger.Fatal(fmt.Sprintf("provided invalid address %x\n", param))
3525
}
3626

3727
acc, lastTenTx, err := client.GetAccount(address)

client/account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ func GetAccount(address [64]byte) (*Account, []*FundsTxJson, error) {
3131
//Set default params
3232
activeParameters = miner.NewDefaultParameters()
3333

34-
network.AccReq(false, protocol.SerializeHashContent(account.Address))
34+
network.AccReq(false, account.Address)
3535
if accI, _ := network.Fetch(network.AccChan); accI != nil {
3636
if acc := accI.(*protocol.Account); acc != nil {
3737
account.IsCreated = true
3838
account.IsStaking = acc.IsStaking
3939

40-
network.AccReq(true, protocol.SerializeHashContent(account.Address))
40+
network.AccReq(true, account.Address)
4141
if rootAccI, _ := network.Fetch(network.AccChan); rootAccI != nil {
4242
if rootAcc := rootAccI.(*protocol.Account); rootAcc != nil {
4343
account.IsRoot = true

network/requests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ func TxReq(txType uint8, txHash [32]byte) error {
4343
return nil
4444
}
4545

46-
func AccReq(root bool, addressHash [32]byte) error {
46+
func AccReq(root bool, address [64]byte) error {
4747
p := peers.getRandomPeer()
4848
if p == nil {
4949
return errors.New("Couldn't get a connection, request not transmitted.")
5050
}
5151

5252
var packet []byte
5353
if root {
54-
packet = p2p.BuildPacket(p2p.ROOTACC_REQ, addressHash[:])
54+
packet = p2p.BuildPacket(p2p.ROOTACC_REQ, address[:])
5555
} else {
56-
packet = p2p.BuildPacket(p2p.ACC_REQ, addressHash[:])
56+
packet = p2p.BuildPacket(p2p.ACC_REQ, address[:])
5757
}
5858

5959
sendData(p, packet)

network/responses.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ func txRes(p *peer, payload []byte, txType uint8) {
6464

6565
func accRes(p *peer, payload []byte) {
6666
var acc *protocol.Account
67-
acc = acc.Decode(payload)
67+
acc, err := acc.Decode(payload)
68+
if err != nil {
69+
logger.Fatal(err)
70+
}
6871

6972
AccChan <- acc
7073
}

0 commit comments

Comments
 (0)