-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new methods and types for FEVM #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package abi | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
cbg "github.com/whyrusleeping/cbor-gen" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type CborBytes []byte | ||
|
||
func (t *CborBytes) MarshalCBOR(w io.Writer) error { | ||
if len(*t) > cbg.ByteArrayMaxLen { | ||
return xerrors.Errorf("byte array was too long") | ||
} | ||
|
||
if err := cbg.WriteMajorTypeHeader(w, cbg.MajByteString, uint64(len(*t))); err != nil { | ||
return err | ||
} | ||
|
||
_, err := w.Write((*t)[:]) | ||
return err | ||
} | ||
|
||
func (t *CborBytes) UnmarshalCBOR(r io.Reader) error { | ||
|
||
br := cbg.GetPeeker(r) | ||
maj, extra, err := cbg.CborReadHeader(br) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if extra > cbg.ByteArrayMaxLen { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably too small (e.g., it won't fit an entire smart contract). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, if so we have a more serious problem -- this limit applies to pretty much every type in Filecoin (as implemented by Golang clients), including the (what happens here in GST is less important since it's only used for UX) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Steven is confused. Steven will go back to the caverns of rust. (the max here is ~2MiB and isn't a problem) |
||
return fmt.Errorf("byte array too large (%d)", extra) | ||
} | ||
if maj != cbg.MajByteString { | ||
return fmt.Errorf("expected byte array") | ||
} | ||
|
||
if extra > 0 { | ||
ret := make([]byte, extra) | ||
if _, err := io.ReadFull(br, ret[:]); err != nil { | ||
return err | ||
} | ||
|
||
*t = ret | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package eam | ||
|
||
import ( | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/builtin" | ||
) | ||
|
||
var Methods = map[abi.MethodNum]builtin.MethodMeta{ | ||
1: {"Constructor", *new(func(*abi.EmptyValue) *abi.EmptyValue)}, // Constructor | ||
2: {"Create", *new(func(*CreateParams) *CreateReturn)}, // Create | ||
3: {"Create2", *new(func(*Create2Params) *Create2Return)}, // Create2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package embryo | ||
|
||
import ( | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/builtin" | ||
) | ||
|
||
// Placeholder has no methods, not even a constructor | ||
var Methods = map[abi.MethodNum]builtin.MethodMeta{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ethaccount | ||
|
||
import ( | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/builtin" | ||
) | ||
|
||
var Methods = map[abi.MethodNum]builtin.MethodMeta{ | ||
1: {"Constructor", *new(func(value *abi.EmptyValue) *abi.EmptyValue)}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package evm | ||
|
||
import ( | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/big" | ||
"github.com/filecoin-project/go-state-types/builtin" | ||
typegen "github.com/whyrusleeping/cbor-gen" | ||
) | ||
|
||
var Methods = map[abi.MethodNum]builtin.MethodMeta{ | ||
1: {"Constructor", *new(func(*ConstructorParams) *abi.EmptyValue)}, | ||
2: {"InvokeContract", *new(func(bytes *abi.CborBytes) *abi.CborBytes)}, | ||
3: {"GetBytecode", *new(func(*abi.EmptyValue) *typegen.CborCid)}, | ||
4: {"GetStorageAt", *new(func(*GetStorageAtParams) *big.Int)}, | ||
5: {"InvokeContractDelegate", *new(func(params *DelegateCallParams) *abi.CborBytes)}, | ||
6: {"GetBytecodeHash", *new(func(*abi.EmptyValue) *typegen.CborCid)}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider putting this into cbor-gen (and using cborgen's ReadByteArray/WriteByteArray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...future...improvement...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whyrusleeping/cbor-gen#75