mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-02 03:07:37 +00:00
## Why this should be merged To be able to generate RLP code using type aliases (defined e.g. in `coreth`). This can and should be PR-ed upstream as well I think. ## How this works Call `types.Unalias()` at the start of `buildContext.makeOp()`. The alternative of adding a `case` to the switch statement adds unnecessary recursive calls while `types.Unalias()` is a no-op if not an alias. ## How this was tested New `rlpgen` unit test with aliases of well-known types that have special handling—these make their proper handling easy to spot when inspecting generated code. A recursive alias in the same test also demonstrates full alias resolution. --------- Co-authored-by: Arran Schlosberg <me@arranschlosberg.com>
43 lines
838 B
Text
43 lines
838 B
Text
package test
|
|
|
|
import "github.com/ava-labs/libevm/rlp"
|
|
import "github.com/holiman/uint256"
|
|
import "io"
|
|
|
|
func (obj *Test) EncodeRLP(_w io.Writer) error {
|
|
w := rlp.NewEncoderBuffer(_w)
|
|
_tmp0 := w.List()
|
|
if obj.BigAlias.Sign() == -1 {
|
|
return rlp.ErrNegativeBigInt
|
|
}
|
|
w.WriteBigInt(&obj.BigAlias)
|
|
w.WriteUint256(&obj.Uint256Alias)
|
|
w.ListEnd(_tmp0)
|
|
return w.Flush()
|
|
}
|
|
|
|
func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
|
|
var _tmp0 Test
|
|
{
|
|
if _, err := dec.List(); err != nil {
|
|
return err
|
|
}
|
|
// BigAlias:
|
|
_tmp1, err := dec.BigInt()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_tmp0.BigAlias = (*_tmp1)
|
|
// Uint256Alias:
|
|
var _tmp2 uint256.Int
|
|
if err := dec.ReadUint256(&_tmp2); err != nil {
|
|
return err
|
|
}
|
|
_tmp0.Uint256Alias = _tmp2
|
|
if err := dec.ListEnd(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
*obj = _tmp0
|
|
return nil
|
|
}
|