Skip to content

Commit

Permalink
Several cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Oct 23, 2023
1 parent 2570992 commit 1b159cc
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 75 deletions.
17 changes: 3 additions & 14 deletions components/faucet/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,10 @@ func provide(c *dig.Container) error {
ctxRequest, cancelRequest := context.WithTimeout(Component.Daemon().ContextStopped(), inxRequestTimeout)
defer cancelRequest()

// simple outputs are basic outputs without timelocks, expiration, native tokens, storage deposit return unlocks conditions.
falseCondition := false
// the restricted address only returns simple outputs, which are basic outputs without timelocks,
// expiration, native tokens, storage deposit return unlocks conditions.
query := &apimodels.BasicOutputsQuery{
AddressBech32: faucetAddressRestricted.Bech32(deps.NodeBridge.APIProvider().CommittedAPI().ProtocolParameters().Bech32HRP()),
IndexerTimelockParams: apimodels.IndexerTimelockParams{
HasTimelock: &falseCondition,
},
IndexerExpirationParams: apimodels.IndexerExpirationParams{
HasExpiration: &falseCondition,
},
IndexerStorageDepositParams: apimodels.IndexerStorageDepositParams{
HasStorageDepositReturn: &falseCondition,
},
IndexerNativeTokenParams: apimodels.IndexerNativeTokenParams{
HasNativeToken: &falseCondition,
},
}

result, err := indexer.Outputs(ctxRequest, query)
Expand All @@ -172,6 +160,7 @@ func provide(c *dig.Container) error {
if err != nil {
return nil, err
}

outputIDs := result.Response.Items.MustOutputIDs()

for i := range outputs {
Expand Down
2 changes: 1 addition & 1 deletion components/faucet/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func enforceMaxOneDotPerURL(next echo.HandlerFunc) echo.HandlerFunc {
}

func addFaucetOutputToQueue(c echo.Context) (*faucet.EnqueueResponse, error) {
request := &faucetEnqueueRequest{}
request := &faucet.EnqueueRequest{}
if err := c.Bind(request); err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "Invalid Request! Error: %s", err)
}
Expand Down
7 changes: 0 additions & 7 deletions components/faucet/types.go

This file was deleted.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (
github.com/iotaledger/hive.go/lo v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/hive.go/logger v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/hive.go/runtime v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d
github.com/labstack/echo/v4 v4.11.2
go.uber.org/dig v1.17.1
golang.org/x/time v0.3.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292c580b/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b h1:MDZhTZTVDiydXcW5j4TA7HixVCyAdToIMPhHfJee7cE=
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3 h1:7+fCfCWDtt2Ejs0F/hatDh+BUHiiM0a+ZSBWuVRUknQ=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3/go.mod h1:9MAg2H+eUQZoTAnnYa7wBHtPQS+ahOXsEqYexp2vAYY=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2 h1:xC5hFWN5wSGvEFjPWUWdmlj6UuYJOo72T0r0AfbzRUs=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2/go.mod h1:8CiEU9nM9q37wtYBnElactUR6RiZ2IGXX7RRtswRuVI=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159 h1:Ef2eDsbsIAtcAr4SwGkV3RUkAdyCMbn0rhFSiGHLXIk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0 h1:/8pbFXhTSroJvjJMfJqfHjzoT9N8B4LUY3SbKruD5MM=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0/go.mod h1:My1SB4vZj42EgTDNJ/dgW8lUpLNmvtzu8f89J5y2kP0=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd h1:hh5mAnnaZHOYAi4CIqR9K/mv786ex9AQgpisbJ4ZMow=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd/go.mod h1:MK0SHfNicBmcaZb3qS3tA8NEJIWKNbcNtNNKuSDKqXY=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d h1:vGfZmcCCloTzim6TysS3fXxc9xsTfXoVB6bsedZgp7A=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
Expand Down
22 changes: 15 additions & 7 deletions pkg/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ type InfoResponse struct {
Bech32HRP iotago.NetworkPrefix `json:"bech32Hrp"`
}

// EnqueueRequest defines the request for a POST RouteFaucetEnqueue REST API call.
type EnqueueRequest struct {
// The bech32 address.
Address string `json:"address"`
}

// EnqueueResponse defines the response of a POST RouteFaucetEnqueue REST API call.
type EnqueueResponse struct {
// The bech32 address.
Expand All @@ -127,7 +133,8 @@ type Faucet struct {
// used to fetch metadata of a transaction from the node.
fetchTransactionMetadataFunc FetchTransactionMetadataFunc
// used to collect the unlockable outputs and the balance of the faucet.
collectUnlockableFaucetOutputsAndBalanceFunc CollectUnlockableFaucetOutputsAndBalanceFunc
// write lock must be acquired outside.
collectUnlockableFaucetOutputsAndBalanceFuncWithoutLocking CollectUnlockableFaucetOutputsAndBalanceFunc
// used to compute the unlockable balance of an address.
computeUnlockableAddressBalanceFunc ComputeUnlockableAddressBalanceFunc
// used to create a signed transaction payload and send it to a block issuer.
Expand Down Expand Up @@ -297,7 +304,8 @@ func New(
},
}

faucet.collectUnlockableFaucetOutputsAndBalanceFunc = func() ([]UTXOBasicOutput, iotago.BaseToken, error) {
// write lock must be acquired outside.
faucet.collectUnlockableFaucetOutputsAndBalanceFuncWithoutLocking = func() ([]UTXOBasicOutput, iotago.BaseToken, error) {
// get all outputs of the faucet
unspentOutputs, err := collectUnlockableFaucetOutputsFunc()
if err != nil {
Expand Down Expand Up @@ -698,14 +706,14 @@ func (f *Faucet) sendFaucetBlock(ctx context.Context, unspentOutputs []UTXOBasic

// computeAndSetFaucetBalance computes the faucet balance minus the storage deposit for a single basic output.
func (f *Faucet) computeAndSetFaucetBalance() error {
_, balance, err := f.collectUnlockableFaucetOutputsAndBalanceFunc()
f.Lock()
defer f.Unlock()

_, balance, err := f.collectUnlockableFaucetOutputsAndBalanceFuncWithoutLocking()
if err != nil {
return err
}

f.Lock()
defer f.Unlock()

f.faucetBalance = balance

return nil
Expand Down Expand Up @@ -751,7 +759,7 @@ func (f *Faucet) collectRequestsAndSendFaucetBlock(ctx context.Context) error {
f.LogDebugf("collected %d requests", len(batchedRequests))

processRequests := func() ([]UTXOBasicOutput, []*queueItem, error) {
unspentOutputs, balance, err := f.collectUnlockableFaucetOutputsAndBalanceFunc()
unspentOutputs, balance, err := f.collectUnlockableFaucetOutputsAndBalanceFuncWithoutLocking()
if err != nil {
return nil, nil, err
}
Expand Down
41 changes: 13 additions & 28 deletions tools/faucetspam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,33 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/iotaledger/inx-faucet/pkg/faucet"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/tpkg"
)

const (
url = "https://faucet.tanglekit.de/api/enqueue"
//url = "http://localhost:14265/api/plugins/faucet/enqueue"
)

// faucetEnqueueRequest defines the request for a POST RouteFaucetEnqueue REST API call.
type faucetEnqueueRequest struct {
// The bech32 address.
Address string `json:"address"`
}
url = "http://localhost:8088/api/enqueue"

// FaucetEnqueueResponse defines the response of a POST RouteFaucetEnqueue REST API call.
type FaucetEnqueueResponse struct {
// The bech32 address.
Address string `json:"address"`
// The number of waiting requests in the queue.
WaitingRequests int `json:"waitingRequests"`
}
network = iotago.PrefixTestnet
)

func main() {

for i := 0; i < 1; i++ {
pubKey, privKey, err := ed25519.GenerateKey(nil)
if err != nil {
panic(err)
}
for i := 0; i < 1000; i++ {
pubKey := ed25519.PublicKey(tpkg.RandBytes(32))

addr := iotago.Ed25519AddressFromPubKey(pubKey)

fmt.Println("Your ed25519 private key: ", hex.EncodeToString(privKey))
fmt.Println("Your ed25519 public key: ", hex.EncodeToString(pubKey))
fmt.Println("Your ed25519 address: ", hex.EncodeToString(addr[:]))
fmt.Println("Your bech32 address: ", addr.Bech32("atoi"))
fmt.Println("Your bech32 address: ", addr.Bech32(network))

jsonValue, _ := json.Marshal(&faucetEnqueueRequest{
Address: addr.Bech32("atoi"),
jsonValue, _ := json.Marshal(&faucet.EnqueueRequest{
Address: addr.Bech32(network),
})

resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonValue))
Expand All @@ -61,12 +46,12 @@ func main() {
panic(fmt.Errorf("http status code: %d", resp.StatusCode))
}

responseBytes, err := ioutil.ReadAll(resp.Body)
responseBytes, err := io.ReadAll(resp.Body)
if err != nil {
panic(fmt.Errorf("unable to read response: %w", err))
}

res := FaucetEnqueueResponse{}
res := faucet.EnqueueResponse{}
err = json.Unmarshal(responseBytes, &res)
if err != nil {
panic(fmt.Errorf("unable to unmarshal response: %w", err))
Expand Down
6 changes: 3 additions & 3 deletions tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231020115340-13da292c580b // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292c580b // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159 // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/labstack/echo/v4 v4.11.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292c580b/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b h1:MDZhTZTVDiydXcW5j4TA7HixVCyAdToIMPhHfJee7cE=
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3 h1:7+fCfCWDtt2Ejs0F/hatDh+BUHiiM0a+ZSBWuVRUknQ=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3/go.mod h1:9MAg2H+eUQZoTAnnYa7wBHtPQS+ahOXsEqYexp2vAYY=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2 h1:xC5hFWN5wSGvEFjPWUWdmlj6UuYJOo72T0r0AfbzRUs=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2/go.mod h1:8CiEU9nM9q37wtYBnElactUR6RiZ2IGXX7RRtswRuVI=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159 h1:Ef2eDsbsIAtcAr4SwGkV3RUkAdyCMbn0rhFSiGHLXIk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0 h1:/8pbFXhTSroJvjJMfJqfHjzoT9N8B4LUY3SbKruD5MM=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0/go.mod h1:My1SB4vZj42EgTDNJ/dgW8lUpLNmvtzu8f89J5y2kP0=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd h1:hh5mAnnaZHOYAi4CIqR9K/mv786ex9AQgpisbJ4ZMow=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd/go.mod h1:MK0SHfNicBmcaZb3qS3tA8NEJIWKNbcNtNNKuSDKqXY=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d h1:vGfZmcCCloTzim6TysS3fXxc9xsTfXoVB6bsedZgp7A=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
Expand Down

0 comments on commit 1b159cc

Please sign in to comment.