fix: allow EthCall.From to be nil (#9556)

This commit is contained in:
Steven Allen
2022-11-09 19:47:25 +02:00
committed by vyzo
parent b3b9da5bbc
commit 49da019bd0
2 changed files with 18 additions and 8 deletions
+1 -1
View File
@@ -159,7 +159,7 @@ func NewEthBlock() EthBlock {
}
type EthCall struct {
From EthAddress `json:"from"`
From *EthAddress `json:"from"`
To *EthAddress `json:"to"`
Gas EthUint64 `json:"gas"`
GasPrice EthBigInt `json:"gasPrice"`
+17 -7
View File
@@ -505,13 +505,23 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx api.EthByte
}
func (a *EthModule) ethCallToFilecoinMessage(ctx context.Context, tx api.EthCall) (*types.Message, error) {
// The from address must be translatable to an f4 address.
from, err := tx.From.ToFilecoinAddress()
if err != nil {
return nil, fmt.Errorf("failed to translate sender address (%s): %w", tx.From.String(), err)
}
if p := from.Protocol(); p != address.Delegated {
return nil, fmt.Errorf("expected a class 4 address, got: %d: %w", p, err)
var err error
var from address.Address
if tx.From == nil {
// Send from the filecoin "system" address.
from, err = (api.EthAddress{}).ToFilecoinAddress()
if err != nil {
return nil, fmt.Errorf("failed to construct the ethereum system address: %w", err)
}
} else {
// The from address must be translatable to an f4 address.
from, err = tx.From.ToFilecoinAddress()
if err != nil {
return nil, fmt.Errorf("failed to translate sender address (%s): %w", tx.From.String(), err)
}
if p := from.Protocol(); p != address.Delegated {
return nil, fmt.Errorf("expected a class 4 address, got: %d: %w", p, err)
}
}
var params []byte