Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(state)!: Adding fee parameter to CoreAccessor operations #1484

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions api/gateway/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ type submitTxRequest struct {
type submitPFDRequest struct {
NamespaceID string `json:"namespace_id"`
Data string `json:"data"`
Fee int64 `json:"fee"`
GasLimit uint64 `json:"gas_limit"`
}

type transferRequest struct {
To string `json:"to"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
GasLimit uint64 `json:"gas_limit"`
}

Expand All @@ -57,6 +59,7 @@ type transferRequest struct {
type delegationRequest struct {
To string `json:"to"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
GasLimit uint64 `json:"gas_limit"`
}

Expand All @@ -65,13 +68,15 @@ type redelegationRequest struct {
From string `json:"from"`
To string `json:"to"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
GasLimit uint64 `json:"gas_limit"`
}

// unbondRequest represents a request to begin unbonding
type unbondRequest struct {
From string `json:"from"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
GasLimit uint64 `json:"gas_limit"`
}

Expand All @@ -80,6 +85,7 @@ type cancelUnbondRequest struct {
From string `json:"from"`
Amount int64 `json:"amount"`
Height int64 `json:"height"`
Fee int64 `json:"fee"`
GasLimit uint64 `json:"gas_limit"`
}

Expand Down Expand Up @@ -177,8 +183,9 @@ func (h *Handler) handleSubmitPFD(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, submitPFDEndpoint, err)
return
}
fee := types.NewInt(req.Fee)
// perform request
txResp, err := h.state.SubmitPayForData(r.Context(), nID, data, req.GasLimit)
txResp, err := h.state.SubmitPayForData(r.Context(), nID, data, fee, req.GasLimit)
if err != nil {
writeError(w, http.StatusInternalServerError, submitPFDEndpoint, err)
return
Expand Down Expand Up @@ -212,8 +219,9 @@ func (h *Handler) handleTransfer(w http.ResponseWriter, r *http.Request) {
addr = valAddr.Bytes()
}
amount := types.NewInt(req.Amount)
fee := types.NewInt(req.Fee)

txResp, err := h.state.Transfer(r.Context(), addr, amount, req.GasLimit)
txResp, err := h.state.Transfer(r.Context(), addr, amount, fee, req.GasLimit)
if err != nil {
writeError(w, http.StatusInternalServerError, transferEndpoint, err)
return
Expand Down Expand Up @@ -242,8 +250,9 @@ func (h *Handler) handleDelegation(w http.ResponseWriter, r *http.Request) {
return
}
amount := types.NewInt(req.Amount)
fee := types.NewInt(req.Fee)

txResp, err := h.state.Delegate(r.Context(), addr, amount, req.GasLimit)
txResp, err := h.state.Delegate(r.Context(), addr, amount, fee, req.GasLimit)
if err != nil {
writeError(w, http.StatusInternalServerError, delegationEndpoint, err)
return
Expand Down Expand Up @@ -272,8 +281,9 @@ func (h *Handler) handleUndelegation(w http.ResponseWriter, r *http.Request) {
return
}
amount := types.NewInt(req.Amount)
fee := types.NewInt(req.Fee)

txResp, err := h.state.Undelegate(r.Context(), addr, amount, req.GasLimit)
txResp, err := h.state.Undelegate(r.Context(), addr, amount, fee, req.GasLimit)
if err != nil {
writeError(w, http.StatusInternalServerError, undelegationEndpoint, err)
return
Expand Down Expand Up @@ -303,7 +313,8 @@ func (h *Handler) handleCancelUnbonding(w http.ResponseWriter, r *http.Request)
}
amount := types.NewInt(req.Amount)
height := types.NewInt(req.Height)
txResp, err := h.state.CancelUnbondingDelegation(r.Context(), addr, amount, height, req.GasLimit)
fee := types.NewInt(req.Fee)
txResp, err := h.state.CancelUnbondingDelegation(r.Context(), addr, amount, height, fee, req.GasLimit)
if err != nil {
writeError(w, http.StatusInternalServerError, cancelUnbondingEndpoint, err)
return
Expand Down Expand Up @@ -337,8 +348,9 @@ func (h *Handler) handleRedelegation(w http.ResponseWriter, r *http.Request) {
return
}
amount := types.NewInt(req.Amount)
fee := types.NewInt(req.Fee)

txResp, err := h.state.BeginRedelegate(r.Context(), srcAddr, dstAddr, amount, req.GasLimit)
txResp, err := h.state.BeginRedelegate(r.Context(), srcAddr, dstAddr, amount, fee, req.GasLimit)
if err != nil {
writeError(w, http.StatusInternalServerError, beginRedelegationEndpoint, err)
return
Expand Down
18 changes: 12 additions & 6 deletions docs/adr/adr-009-public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,17 @@ SyncHead(ctx context.Context) (*header.ExtendedHeader, error)
SubmitPayForData(
ctx context.Context,
nID namespace.ID,
data []byte,
data []byte,
fee types.Int,
gasLimit uint64,
) (*state.TxResponse, error)
// Transfer sends the given amount of coins from default wallet of the node
// to the given account address.
Transfer(
ctx context.Context,
to types.Address,
amount types.Int,
to types.Address,
amount types.Int,
fee types.Int,
gasLimit uint64,
) (*state.TxResponse, error)

Expand All @@ -275,7 +277,8 @@ yet.
Delegate(
ctx context.Context,
delAddr state.ValAddress,
amount state.Int,
amount state.Int,
fee types.Int,
gasLim uint64,
) (*state.TxResponse, error)
// BeginRedelegate sends a user's delegated tokens to a new validator for redelegation.
Expand All @@ -284,6 +287,7 @@ yet.
srcValAddr,
dstValAddr state.ValAddress,
amount state.Int,
fee types.Int,
gasLim uint64,
) (*state.TxResponse, error)
// Undelegate undelegates a user's delegated tokens, unbonding them from the
Expand All @@ -292,6 +296,7 @@ yet.
ctx context.Context,
delAddr state.ValAddress,
amount state.Int,
fee types.Int,
gasLim uint64,
) (*state.TxResponse, error)

Expand All @@ -300,8 +305,9 @@ yet.
CancelUnbondingDelegation(
ctx context.Context,
valAddr state.ValAddress,
amount,
height state.Int,
amount types.Int,
height types.Int,
fee types.Int,
gasLim uint64,
) (*state.TxResponse, error)

Expand Down
59 changes: 29 additions & 30 deletions nodebuilder/state/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading