Addressed comments
This commit is contained in:
parent
0738de17f4
commit
a9bcdb2a0a
|
@ -20,7 +20,7 @@ func registerQueryRoutes(ctx context.CoreContext, r *mux.Router, cdc *wire.Codec
|
||||||
).Methods("GET")
|
).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
// bondingStatusHandlerFn - http request handler to query delegator bonding status
|
// http request handler to query delegator bonding status
|
||||||
func bondingStatusHandlerFn(storeName string, cdc *wire.Codec, ctx context.CoreContext) http.HandlerFunc {
|
func bondingStatusHandlerFn(storeName string, cdc *wire.Codec, ctx context.CoreContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// read parameters
|
// read parameters
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -16,33 +17,26 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerTxRoutes(ctx context.CoreContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
func registerTxRoutes(ctx context.CoreContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||||
r.HandleFunc("/stake/bondunbond", bondUnbondRequestHandlerFn(cdc, kb, ctx)).Methods("POST")
|
r.HandleFunc(
|
||||||
|
"/stake/delegations",
|
||||||
|
editDelegationsRequestHandlerFn(cdc, kb, ctx),
|
||||||
|
).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
type bond struct {
|
type editDelegationsBody struct {
|
||||||
Amount sdk.Coin `json:"amount"`
|
|
||||||
Candidate sdk.Address `json:"candidate"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type unbond struct {
|
|
||||||
Shares string `json:"shares"`
|
|
||||||
Candidate sdk.Address `json:"candidate"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type bondUnbondBody struct {
|
|
||||||
// fees is not used currently
|
// fees is not used currently
|
||||||
// Fees sdk.Coin `json="fees"`
|
// Fees sdk.Coin `json="fees"`
|
||||||
LocalAccountName string `json:"name"`
|
LocalAccountName string `json:"name"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
ChainID string `json:"chain_id"`
|
ChainID string `json:"chain_id"`
|
||||||
Sequence int64 `json:"sequence"`
|
Sequence int64 `json:"sequence"`
|
||||||
Bond []bond `json:"bond"`
|
Delegate []stake.MsgDelegate `json:"delegate"`
|
||||||
Unbond []unbond `json:"unbond"`
|
Unbond []stake.MsgUnbond `json:"unbond"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func bondUnbondRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreContext) http.HandlerFunc {
|
func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var m bondUnbondBody
|
var m editDelegationsBody
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -64,13 +58,21 @@ func bondUnbondRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.Co
|
||||||
}
|
}
|
||||||
|
|
||||||
// build messages
|
// build messages
|
||||||
messages := make([]sdk.Msg, 0, len(m.Bond)+len(m.Unbond))
|
messages := make([]sdk.Msg, 0, len(m.Delegate)+len(m.Unbond))
|
||||||
for _, bond := range m.Bond {
|
for _, msg := range m.Delegate {
|
||||||
msg := stake.NewMsgDelegate(info.Address(), bond.Candidate, bond.Amount)
|
if !bytes.Equal(info.Address(), msg.DelegatorAddr) {
|
||||||
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
w.Write([]byte("Must use own delegator address"))
|
||||||
|
return
|
||||||
|
}
|
||||||
messages = append(messages, msg)
|
messages = append(messages, msg)
|
||||||
}
|
}
|
||||||
for _, unbond := range m.Unbond {
|
for _, msg := range m.Unbond {
|
||||||
msg := stake.NewMsgUnbond(info.Address(), unbond.Candidate, unbond.Shares)
|
if !bytes.Equal(info.Address(), msg.DelegatorAddr) {
|
||||||
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
w.Write([]byte("Must use own delegator address"))
|
||||||
|
return
|
||||||
|
}
|
||||||
messages = append(messages, msg)
|
messages = append(messages, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,8 @@ func (msg MsgEditCandidacy) ValidateBasic() sdk.Error {
|
||||||
|
|
||||||
// MsgDelegate - struct for bonding transactions
|
// MsgDelegate - struct for bonding transactions
|
||||||
type MsgDelegate struct {
|
type MsgDelegate struct {
|
||||||
DelegatorAddr sdk.Address `json:"delegator"`
|
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||||
ValidatorAddr sdk.Address `json:"candidate"`
|
ValidatorAddr sdk.Address `json:"validator_addr"`
|
||||||
Bond sdk.Coin `json:"bond"`
|
Bond sdk.Coin `json:"bond"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ func (msg MsgDelegate) ValidateBasic() sdk.Error {
|
||||||
|
|
||||||
// MsgUnbond - struct for unbonding transactions
|
// MsgUnbond - struct for unbonding transactions
|
||||||
type MsgUnbond struct {
|
type MsgUnbond struct {
|
||||||
DelegatorAddr sdk.Address `json:"delegator"`
|
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||||
ValidatorAddr sdk.Address `json:"candidate"`
|
ValidatorAddr sdk.Address `json:"validator_addr"`
|
||||||
Shares string `json:"shares"`
|
Shares string `json:"shares"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue