feat: minor improvements to Ethereum delegated siggys
This commit is contained in:
parent
1ea57740aa
commit
972e68a8c1
@ -12,13 +12,11 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
gocrypto "github.com/filecoin-project/go-crypto"
|
gocrypto "github.com/filecoin-project/go-crypto"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
builtintypes "github.com/filecoin-project/go-state-types/builtin"
|
builtintypes "github.com/filecoin-project/go-state-types/builtin"
|
||||||
typescrypto "github.com/filecoin-project/go-state-types/crypto"
|
typescrypto "github.com/filecoin-project/go-state-types/crypto"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,6 +61,7 @@ func EthTxArgsFromMessage(msg *types.Message) (EthTxArgs, error) {
|
|||||||
to *EthAddress
|
to *EthAddress
|
||||||
params []byte
|
params []byte
|
||||||
paramsReader = bytes.NewReader(msg.Params)
|
paramsReader = bytes.NewReader(msg.Params)
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
if msg.Version != 0 {
|
if msg.Version != 0 {
|
||||||
@ -72,11 +71,10 @@ func EthTxArgsFromMessage(msg *types.Message) (EthTxArgs, error) {
|
|||||||
if msg.To == builtintypes.EthereumAddressManagerActorAddr {
|
if msg.To == builtintypes.EthereumAddressManagerActorAddr {
|
||||||
switch msg.Method {
|
switch msg.Method {
|
||||||
case builtintypes.MethodsEAM.CreateExternal:
|
case builtintypes.MethodsEAM.CreateExternal:
|
||||||
var create abi.CborBytes
|
params, err = cbg.ReadByteArray(paramsReader, uint64(len(msg.Params)))
|
||||||
if err := create.UnmarshalCBOR(paramsReader); err != nil {
|
if err != nil {
|
||||||
return EthTxArgs{}, err
|
return EthTxArgs{}, xerrors.Errorf("failed to read params byte array: %w", err)
|
||||||
}
|
}
|
||||||
params = create
|
|
||||||
default:
|
default:
|
||||||
return EthTxArgs{}, fmt.Errorf("unsupported EAM method")
|
return EthTxArgs{}, fmt.Errorf("unsupported EAM method")
|
||||||
}
|
}
|
||||||
@ -103,11 +101,6 @@ func EthTxArgsFromMessage(msg *types.Message) (EthTxArgs, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return EthTxArgs{}, xerrors.Errorf("failed to read params byte array: %w", err)
|
return EthTxArgs{}, xerrors.Errorf("failed to read params byte array: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(params) == 0 {
|
|
||||||
// Otherwise, we don't get a guaranteed round-trip.
|
|
||||||
return EthTxArgs{}, xerrors.Errorf("cannot invoke contracts with empty parameters from an eth-account")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +108,11 @@ func EthTxArgsFromMessage(msg *types.Message) (EthTxArgs, error) {
|
|||||||
return EthTxArgs{}, xerrors.Errorf("extra data found in params")
|
return EthTxArgs{}, xerrors.Errorf("extra data found in params")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(params) == 0 && msg.Method != builtintypes.MethodSend {
|
||||||
|
// Otherwise, we don't get a guaranteed round-trip.
|
||||||
|
return EthTxArgs{}, xerrors.Errorf("msgs with empty parameters from an eth-account must be Sends (MethodNum: %d)", msg.Method)
|
||||||
|
}
|
||||||
|
|
||||||
return EthTxArgs{
|
return EthTxArgs{
|
||||||
ChainID: build.Eip155ChainId,
|
ChainID: build.Eip155ChainId,
|
||||||
Nonce: int(msg.Nonce),
|
Nonce: int(msg.Nonce),
|
||||||
@ -143,12 +141,13 @@ func (tx *EthTxArgs) ToUnsignedMessage(from address.Address) (*types.Message, er
|
|||||||
if len(tx.Input) == 0 {
|
if len(tx.Input) == 0 {
|
||||||
return nil, xerrors.New("cannot call CreateExternal without params")
|
return nil, xerrors.New("cannot call CreateExternal without params")
|
||||||
}
|
}
|
||||||
inputParams := abi.CborBytes(tx.Input)
|
|
||||||
params, err = actors.SerializeParams(&inputParams)
|
buf := new(bytes.Buffer)
|
||||||
if err != nil {
|
if err = cbg.WriteByteArray(buf, tx.Input); err != nil {
|
||||||
return nil, fmt.Errorf("failed to serialize Create params: %w", err)
|
return nil, xerrors.Errorf("failed to serialize Create params: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params = buf.Bytes()
|
||||||
} else {
|
} else {
|
||||||
to, err = tx.To.ToFilecoinAddress()
|
to, err = tx.To.ToFilecoinAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user