From 50dd57f9e93b34abc14d957a83f647ca489e43aa Mon Sep 17 00:00:00 2001 From: Piotr Macek Date: Thu, 1 Sep 2022 08:29:41 +0200 Subject: [PATCH] Wrap faucet errors and add faucet logging --- plugins/faucet/connector.go | 6 +++++- plugins/faucet/faucet.go | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/faucet/connector.go b/plugins/faucet/connector.go index 74573123f3..db0c328440 100644 --- a/plugins/faucet/connector.go +++ b/plugins/faucet/connector.go @@ -1,6 +1,8 @@ package faucet import ( + "fmt" + "github.com/iotaledger/hive.go/core/types/confirmation" "github.com/pkg/errors" @@ -31,8 +33,10 @@ func (f *FaucetConnector) UnspentOutputs(addresses ...address.Address) (unspentO unspentOutputs = make(map[address.Address]map[utxo.OutputID]*wallet.Output) for _, addr := range addresses { + fmt.Println("> Getting unspent outputs for ", addr.Base58()) f.indexer.CachedAddressOutputMappings(addr.Address()).Consume(func(mapping *indexer.AddressOutputMapping) { f.tangle.Ledger.Storage.CachedOutput(mapping.OutputID()).Consume(func(output utxo.Output) { + fmt.Println("> > Found output ", output.String()) if typedOutput, ok := output.(devnetvm.Output); ok { f.tangle.Ledger.Storage.CachedOutputMetadata(typedOutput.ID()).Consume(func(outputMetadata *ledger.OutputMetadata) { if !outputMetadata.IsSpent() { @@ -57,7 +61,7 @@ func (f *FaucetConnector) UnspentOutputs(addresses ...address.Address) (unspentO }) }) } - + fmt.Printf("%+v\n", unspentOutputs) return } diff --git a/plugins/faucet/faucet.go b/plugins/faucet/faucet.go index a3c0825e36..f10b4116cb 100644 --- a/plugins/faucet/faucet.go +++ b/plugins/faucet/faucet.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/cockroachdb/errors" "github.com/iotaledger/hive.go/core/bitmask" "github.com/iotaledger/hive.go/core/identity" @@ -66,7 +67,7 @@ func (f *Faucet) handleFaucetRequest(p *faucet.Payload, ctx context.Context) (*d sendoptions.Context(ctx), ) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "failed to send first transaction from %s to %s", f.Seed().Address(0).Base58(), f.Seed().Address(1).Base58()) } // send funds to requester @@ -78,5 +79,5 @@ func (f *Faucet) handleFaucetRequest(p *faucet.Payload, ctx context.Context) (*d sendoptions.WaitForConfirmation(true), sendoptions.Context(ctx), ) - return tx, err + return tx, errors.Wrapf(err, "failed to send second transaction from %s to %s", f.Seed().Address(1).Base58(), p.Address().Base58()) }