lotus/chain/gen/genesis/util.go

45 lines
1.0 KiB
Go
Raw Normal View History

2020-02-11 20:48:03 +00:00
package genesis
import (
"context"
2020-02-11 20:48:03 +00:00
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
2022-06-14 15:00:51 +00:00
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
2020-02-11 20:48:03 +00:00
"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
}
2022-05-15 19:26:52 +00:00
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{
2020-02-11 20:48:03 +00:00
To: to,
From: from,
Method: method,
Params: params,
GasLimit: 1_000_000_000_000_000,
2020-02-11 20:48:03 +00:00
Value: value,
2022-05-15 19:26:52 +00:00
Nonce: 0,
2020-02-11 20:48:03 +00:00
})
if err != nil {
return nil, xerrors.Errorf("doExec apply message failed: %w", err)
}
if ret.ExitCode != 0 {
2020-02-17 07:59:53 +00:00
return nil, xerrors.Errorf("failed to call method: %w", ret.ActorErr)
2020-02-11 20:48:03 +00:00
}
return ret.Return, nil
}