-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change the way we get transaction initiator
- Loading branch information
1 parent
fe273cb
commit f11136b
Showing
6 changed files
with
69 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package transaction | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethersphere/bee/pkg/crypto" | ||
"github.com/ethersphere/bee/pkg/swarm" | ||
) | ||
|
||
type validator struct { | ||
backend Backend | ||
signer types.Signer | ||
} | ||
|
||
func NewValidator(backend Backend, chainID int64) validator { | ||
return validator{ | ||
backend: backend, | ||
signer: types.NewEIP155Signer(big.NewInt(chainID)), | ||
} | ||
} | ||
|
||
func (s validator) MatchesSender(ctx context.Context, tx string, networkID uint64, senderOverlay swarm.Address) (bool, error) { | ||
incomingTx := common.HexToHash(tx) | ||
|
||
nTx, isPending, err := s.backend.TransactionByHash(ctx, incomingTx) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if isPending { | ||
return false, fmt.Errorf("transaction still pending") | ||
} | ||
|
||
sender, err := types.Sender(nil, nTx) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
expectedRemoteBzzAddress := crypto.NewOverlayFromEthereumAddress(sender.Bytes(), networkID) | ||
|
||
return expectedRemoteBzzAddress.Equal(senderOverlay), nil | ||
} |