Commit 814910ce authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

fix: correctly check and decode transaction hash (#1810)

parent 7a8dea9a
...@@ -10,6 +10,7 @@ package node ...@@ -10,6 +10,7 @@ package node
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io" "io"
...@@ -18,6 +19,7 @@ import ( ...@@ -18,6 +19,7 @@ import (
"net" "net"
"net/http" "net/http"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -288,7 +290,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -288,7 +290,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
txHash, err := getTxHash(stateStore, logger, o) txHash, err := getTxHash(stateStore, logger, o)
if err != nil { if err != nil {
return nil, errors.New("no transaction hash provided or found") return nil, fmt.Errorf("invalid transaction hash: %w", err)
} }
senderMatcher := transaction.NewMatcher(swapBackend, types.NewEIP155Signer(big.NewInt(chainID))) senderMatcher := transaction.NewMatcher(swapBackend, types.NewEIP155Signer(big.NewInt(chainID)))
...@@ -754,16 +756,29 @@ func getTxHash(stateStore storage.StateStorer, logger logging.Logger, o Options) ...@@ -754,16 +756,29 @@ func getTxHash(stateStore storage.StateStorer, logger logging.Logger, o Options)
if o.Standalone { if o.Standalone {
return nil, nil // in standalone mode tx hash is not used return nil, nil // in standalone mode tx hash is not used
} }
if len(o.Transaction) == 32 {
logger.Info("using the provided transaction hash") if o.Transaction != "" {
return []byte(o.Transaction), nil txHashTrimmed := strings.TrimPrefix(o.Transaction, "0x")
if len(txHashTrimmed) != 64 {
return nil, errors.New("invalid length")
}
txHash, err := hex.DecodeString(txHashTrimmed)
if err != nil {
return nil, err
}
logger.Infof("using the provided transaction hash %x", txHash)
return txHash, nil
} }
var txHash common.Hash var txHash common.Hash
key := chequebook.ChequebookDeploymentKey key := chequebook.ChequebookDeploymentKey
if err := stateStore.Get(key, &txHash); err != nil { if err := stateStore.Get(key, &txHash); err != nil {
if errors.Is(err, storage.ErrNotFound) {
return nil, errors.New("chequebook deployment transaction hash not found. Please specify the transaction hash manually.")
}
return nil, err return nil, err
} }
logger.Infof("using the chequebook transaction hash %x", txHash)
return txHash.Bytes(), nil return txHash.Bytes(), nil
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment