/
evm_types.go
69 lines (54 loc) · 1.2 KB
/
evm_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package evm
import (
"io"
"github.com/ipfs/go-cid"
xerrors "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi"
cbg "github.com/whyrusleeping/cbor-gen"
)
type ConstructorParams struct {
Creator [20]byte
Initcode []byte
}
type ResurrectParams = ConstructorParams
type GetStorageAtParams struct {
StorageKey [32]byte
}
type DelegateCallParams struct {
Code cid.Cid
Input []byte
Caller [20]byte
Value abi.TokenAmount
}
type GetBytecodeReturn struct {
Cid *cid.Cid
}
func (bc *GetBytecodeReturn) UnmarshalCBOR(r io.Reader) error {
if bc == nil {
return xerrors.Errorf("cannot unmarshal into nil pointer")
}
br := cbg.GetPeeker(r)
// reset fields
bc.Cid = nil
// Check if it's null
if byte, err := br.ReadByte(); err != nil {
return err
} else if byte == cbg.CborNull[0] {
return nil
} else if err := br.UnreadByte(); err != nil {
return err
}
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.OldPtr: %w", err)
}
bc.Cid = &c
return nil
}
func (bc *GetBytecodeReturn) MarshalCBOR(w io.Writer) error {
if bc == nil || bc.Cid == nil {
_, err := w.Write(cbg.CborNull)
return err
}
return cbg.WriteCid(w, *bc.Cid)
}