-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
util.go
44 lines (36 loc) · 1.03 KB
/
util.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
package genesis
import (
"context"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
)
func mustEnc(i cbg.CBORMarshaler) []byte {
enc, err := actors.SerializeParams(i)
if err != nil {
panic(err) // ok
}
return enc
}
func doExecValue(ctx context.Context, vm vm.Interface, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) {
ret, err := vm.ApplyImplicitMessage(ctx, &types.Message{
To: to,
From: from,
Method: method,
Params: params,
GasLimit: 1_000_000_000_000_000,
Value: value,
Nonce: 0,
})
if err != nil {
return nil, xerrors.Errorf("doExec apply message failed: %w", err)
}
if ret.ExitCode != 0 {
return nil, xerrors.Errorf("failed to call method: %w", ret.ActorErr)
}
return ret.Return, nil
}