-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: fix typos, refactor folders structure
- Loading branch information
Showing
13 changed files
with
187 additions
and
191 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/rarimo/evm-airdrop-svc/contracts" | ||
"github.com/rarimo/evm-airdrop-svc/internal/config" | ||
"github.com/rarimo/evm-airdrop-svc/internal/data" | ||
zk "github.com/rarimo/zkverifier-kit" | ||
"gitlab.com/distributed_lab/logan/v3" | ||
) | ||
|
||
type ctxKey int | ||
|
||
const ( | ||
logCtxKey ctxKey = iota | ||
airdropsQCtxKey | ||
airdropConfigCtxKey | ||
verifierCtxKey | ||
airdropParamsCtxKey | ||
broadcasterCtxKey | ||
erc20PermitCtxKey | ||
erc20PermitTransferCtxKey | ||
priceApiConfigCtxKey | ||
) | ||
|
||
func CtxLog(entry *logan.Entry) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, logCtxKey, entry) | ||
} | ||
} | ||
|
||
func Log(r *http.Request) *logan.Entry { | ||
return r.Context().Value(logCtxKey).(*logan.Entry) | ||
} | ||
|
||
func CtxAirdropsQ(q *data.AirdropsQ) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, airdropsQCtxKey, q) | ||
} | ||
} | ||
|
||
func AirdropsQ(r *http.Request) *data.AirdropsQ { | ||
return r.Context().Value(airdropsQCtxKey).(*data.AirdropsQ).New() | ||
} | ||
|
||
func CtxAirdropConfig(entry config.AirdropConfig) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, airdropConfigCtxKey, entry) | ||
} | ||
} | ||
|
||
func AirdropConfig(r *http.Request) config.AirdropConfig { | ||
return r.Context().Value(airdropConfigCtxKey).(config.AirdropConfig) | ||
} | ||
|
||
func CtxAirdropParams(params config.GlobalParams) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, airdropParamsCtxKey, params) | ||
} | ||
} | ||
|
||
func AirdropParams(r *http.Request) config.GlobalParams { | ||
return r.Context().Value(airdropParamsCtxKey).(config.GlobalParams) | ||
} | ||
|
||
func CtxVerifier(entry *zk.Verifier) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, verifierCtxKey, entry) | ||
} | ||
} | ||
|
||
func Verifier(r *http.Request) *zk.Verifier { | ||
return r.Context().Value(verifierCtxKey).(*zk.Verifier) | ||
} | ||
|
||
func Broadcaster(r *http.Request) config.Broadcaster { | ||
return r.Context().Value(broadcasterCtxKey).(config.Broadcaster) | ||
} | ||
|
||
func CtxBroadcaster(entry config.Broadcaster) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, broadcasterCtxKey, entry) | ||
} | ||
} | ||
|
||
func CtxERC20Permit(entry *contracts.ERC20Permit) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, erc20PermitCtxKey, entry) | ||
} | ||
} | ||
|
||
func ERC20Permit(r *http.Request) *contracts.ERC20Permit { | ||
return r.Context().Value(erc20PermitCtxKey).(*contracts.ERC20Permit) | ||
} | ||
|
||
func CtxERC20PermitTransfer(entry *contracts.ERC20TransferWithPermit) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, erc20PermitTransferCtxKey, entry) | ||
} | ||
} | ||
|
||
func ERC20PermitTransfer(r *http.Request) *contracts.ERC20TransferWithPermit { | ||
return r.Context().Value(erc20PermitTransferCtxKey).(*contracts.ERC20TransferWithPermit) | ||
} | ||
|
||
func CtxPriceApiConfig(entry config.PriceApiConfig) func(context.Context) context.Context { | ||
return func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, priceApiConfigCtxKey, entry) | ||
} | ||
} | ||
|
||
func PriceApiConfig(r *http.Request) config.PriceApiConfig { | ||
return r.Context().Value(priceApiConfigCtxKey).(config.PriceApiConfig) | ||
} |
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,13 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/rarimo/evm-airdrop-svc/internal/service/api" | ||
"github.com/rarimo/evm-airdrop-svc/internal/service/api/models" | ||
"gitlab.com/distributed_lab/ape" | ||
) | ||
|
||
func GetAirdropParams(w http.ResponseWriter, r *http.Request) { | ||
ape.Render(w, models.NewAirdropParams(api.AirdropParams(r))) | ||
} |
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
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.