-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rahul0tripathi/ft-rpc-methods
RPC server
- Loading branch information
Showing
11 changed files
with
1,404 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
const ( | ||
_headerCaller = "X-Caller" | ||
) | ||
|
||
type Caller struct{} | ||
|
||
func SetResponseHeaderMw(next echo.HandlerFunc) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
c.Response().Header().Set("Content-Type", "application/json") | ||
return next(c) | ||
} | ||
} | ||
|
||
func SetCallerContextMw(next echo.HandlerFunc) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
caller := c.Request().Header.Get(_headerCaller) | ||
if common.IsHexAddress(caller) { | ||
ctx := context.WithValue(c.Request().Context(), Caller{}, common.HexToAddress(caller)) | ||
c.SetRequest(c.Request().WithContext(ctx)) | ||
} | ||
|
||
return next(c) | ||
} | ||
} |
Oops, something went wrong.