/
EPAccount.go
52 lines (40 loc) 路 1.23 KB
/
EPAccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package REST
import (
"github.com/bazo-blockchain/bazo-client/client"
"github.com/bazo-blockchain/bazo-client/network"
"github.com/bazo-blockchain/bazo-miner/protocol"
"github.com/gorilla/mux"
"math/big"
"net/http"
)
func GetAccountEndpoint(w http.ResponseWriter, req *http.Request) {
params := mux.Vars(req)
param := params["id"]
logger.Printf("Incoming acc request for id: %v", param)
var address [64]byte
var addressHash [32]byte
pubKeyInt, _ := new(big.Int).SetString(param, 16)
if len(param) == 64 {
copy(addressHash[:], pubKeyInt.Bytes())
network.AccReq(false, addressHash)
accI, _ := network.Fetch(network.AccChan)
acc := accI.(*protocol.Account)
address = acc.Address
} else if len(param) == 128 {
copy(address[:], pubKeyInt.Bytes())
addressHash = protocol.SerializeHashContent(address)
}
acc, lastTenTx, err := client.GetAccount(address)
if err != nil {
SendJsonResponse(w, JsonResponse{http.StatusInternalServerError, err.Error(), nil})
} else {
var content []Content
content = append(content, Content{"account", acc})
for _, tx := range lastTenTx {
if tx != nil {
content = append(content, Content{"inbound", tx})
}
}
SendJsonResponse(w, JsonResponse{http.StatusOK, "", content})
}
}