Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ignite/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: commercionetwork/faucet
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Aug 31, 2022

  1. Copy the full SHA
    9bc61b8 View commit details
  2. Copy the full SHA
    3aa9353 View commit details
  3. Copy the full SHA
    60cca3f View commit details
  4. Update README.md

    fabtagliaferro authored Aug 31, 2022
    Copy the full SHA
    31c0155 View commit details
6 changes: 6 additions & 0 deletions commercionetwork_faucet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Execute the faucet with `go run .` while in a terminal in this folder.

This program has been tested with a `ignite chain serve` local network launched from a `commercionetwork` repo folder.


OpenApi: http://localhost:8181/
36 changes: 36 additions & 0 deletions commercionetwork_faucet/commercionetworkfaucet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"net/http"

"github.com/ignite/cli/ignite/pkg/cosmosfaucet"

"github.com/ignite/cli/ignite/pkg/chaincmd"
chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cmd := chaincmd.New("commercionetworkd")

runner, err := chaincmdrunner.New(ctx, cmd)
if err != nil {
panic(err)
}

comDenom := "ucommercio"

faucet, err := cosmosfaucet.New(ctx, runner,
cosmosfaucet.Account("bob", "special chest leaf section reunion inflict busy blouse inflict kid alcohol hazard embody mosquito green turkey street very lab forest gain disease hollow bomb", "com"),
cosmosfaucet.Coin(1000, 2000, comDenom),
cosmosfaucet.ChainID("commercionetwork"),
)
if err != nil {
panic(err)
}

http.ListenAndServe(":8181", faucet)
}
1 change: 1 addition & 0 deletions ignite/pkg/chaincmd/chaincmd.go
Original file line number Diff line number Diff line change
@@ -526,6 +526,7 @@ func (c ChainCmd) BankSendCommand(fromAddress, toAddress, amount string) step.Op
toAddress,
amount,
optionBroadcastMode, flags.BroadcastSync,
"--fees=10000ucommercio",
optionYes,
)

4 changes: 4 additions & 0 deletions ignite/pkg/cosmosfaucet/http.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,10 @@ func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request) {
router.Handle("/", cors.Default().Handler(http.HandlerFunc(f.faucetHandler))).
Methods(http.MethodPost)

router.Handle("/give", cors.Default().Handler(http.HandlerFunc(f.comFaucetHandler))).
Queries("addr", "{addr}", "amount", "{amount}").
Methods(http.MethodGet)

router.Handle("/info", cors.Default().Handler(http.HandlerFunc(f.faucetInfoHandler))).
Methods(http.MethodGet)

51 changes: 51 additions & 0 deletions ignite/pkg/cosmosfaucet/http_com_faucet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cosmosfaucet

import (
"context"
"net/http"

"github.com/gorilla/mux"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// package initialization for correct validation of commercionetwork addresses
func init() {
configTestPrefixes()
}

func configTestPrefixes() {
AccountAddressPrefix := "did:com:"
AccountPubKeyPrefix := AccountAddressPrefix + "pub"
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
config.Seal()
}

func (f Faucet) comFaucetHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

address, err := sdk.AccAddressFromBech32(vars["addr"])
if err != nil {
responseError(w, http.StatusBadRequest, err)
return
}

var coins []sdk.Coin
coin, err := sdk.ParseCoinNormalized(vars["amount"] + "ucommercio")
if err != nil {
responseError(w, http.StatusBadRequest, err)
return
}
coins = append(coins, coin)

// try performing the transfer
if err := f.Transfer(r.Context(), address.String(), coins); err != nil {
if err == context.Canceled {
return
}
responseError(w, http.StatusInternalServerError, err)
} else {
responseSuccess(w)
}
}
28 changes: 28 additions & 0 deletions ignite/pkg/cosmosfaucet/openapi/openapi.yml.tmpl
Original file line number Diff line number Diff line change
@@ -33,6 +33,34 @@ paths:
schema:
$ref: "#/definitions/SendResponse"

/give:
get:
summary: "Send com tokens to addr account"
produces:
- "application/json"
parameters:
- in: query
name: addr
description: address that should receive the tokens
required: true
schema:
type: string
- in: query
name: amount
description: the amount of com tokens that should be sent by the faucet
required: true
schema:
type: int
responses:
"400":
description: "Bad request"
"500":
description: "Internal error"
"200":
description: "All coins are successfully sent\n\nAfter making a sample execution, visit the following link to see the difference in sample account's balance: {{ .APIAddress }}/bank/balances/cosmos1uzv4v9g9xln2qx2vtqhz99yxum33calja5vruz"
schema:
$ref: "#/definitions/SendResponse"

definitions:
SendRequest:
type: "object"