Skip to content

Commit

Permalink
feat: airdrop (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
konojunya authored Oct 18, 2023
1 parent 2370f57 commit 9ff8d7c
Show file tree
Hide file tree
Showing 25 changed files with 5,374 additions and 19 deletions.
3 changes: 3 additions & 0 deletions packages/airdrop/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC_URL=
WALLET_SECRET_KEY=
CONTRACT_ADDRESS=
2 changes: 2 additions & 0 deletions packages/airdrop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list.csv
bin/
17 changes: 17 additions & 0 deletions packages/airdrop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# airdrop cli

## support chain

- Ethereum mainnet

## support types

- CryptoPokers

## CSV Structure

```csv
address,amount
0x000000000000,1
0x000000000001,2
```
29 changes: 29 additions & 0 deletions packages/airdrop/di/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package di

import (
"context"

"github.com/google/wire"
"github.com/kelseyhightower/envconfig"
)

type Config struct {
RpcUrl string `envconfig:"RPC_URL" default:"https://eth-mainnet.g.alchemy.com/v2/7q07HgmNB4AvgtnWTJF0uKgXmHIPpC-e"`
WalletSecretKey string `envconfig:"WALLET_SECRET_KEY"`
ContractAddress string `envconfig:"CONTRACT_ADDRESS"`
}

func loadConfig(_ context.Context) (*Config, error) {
var cfg Config
if err := envconfig.Process("", &cfg); err != nil {
return nil, err
}

return &cfg, nil
}

func providerConfig(ctx context.Context) (*Config, error) {
return loadConfig(ctx)
}

var providerSet = wire.NewSet(providerConfig)
21 changes: 21 additions & 0 deletions packages/airdrop/di/wire.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build wireinject

package di

import (
"context"

"github.com/google/wire"
)

type App struct {
Config *Config
}

func NewApp(ctx context.Context) (*App, error) {
wire.Build(
providerSet,
wire.Struct(new(App), "*"),
)
return nil, nil
}
30 changes: 30 additions & 0 deletions packages/airdrop/di/wire_gen.go

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

73 changes: 73 additions & 0 deletions packages/airdrop/gateway/alchemy/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package alchemy

import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
"path"
)

type Client struct {
rpcUrl string
}

func NewClient(rpcUrl string) *Client {
return &Client{rpcUrl: rpcUrl}
}

type GetNFTsRequest struct {
Owner string
ContractAddress string
// pageKey string
}

type GetNFTsResponse struct {
OwnedNfts []struct {
Id struct {
TokenId string `json:"tokenId"`
} `json:"id"`
Title string `json:"title"`
} `json:"ownedNfts"`
}

func (c *Client) GetNFTs(ctx context.Context, payload GetNFTsRequest) (*GetNFTsResponse, error) {
url, err := url.Parse(c.rpcUrl)
if err != nil {
return nil, err
}

url.Path = path.Join(url.Path, "getNFTs")

q := url.Query()
q.Add("owner", payload.Owner)
q.Add("contractAddresses[]", payload.ContractAddress)
q.Add("withMetadata", "true")

url.RawQuery = q.Encode()

req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, err
}

req.Header.Add("access", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}

defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

var r GetNFTsResponse
if err = json.Unmarshal(body, &r); err != nil {
return nil, err
}

return &r, nil
}
2,991 changes: 2,991 additions & 0 deletions packages/airdrop/gateway/onchain/CryptoPokers/CryptoPokers.go

Large diffs are not rendered by default.

Loading

0 comments on commit 9ff8d7c

Please sign in to comment.