2020-08-06 01:52:43 +00:00
|
|
|
package full
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-08-06 01:52:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/beacon"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BeaconAPI struct {
|
|
|
|
fx.In
|
|
|
|
|
2020-09-09 18:37:12 +00:00
|
|
|
Beacon beacon.Schedule
|
2020-08-06 01:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *BeaconAPI) BeaconGetEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) {
|
2020-09-09 18:37:12 +00:00
|
|
|
b := a.Beacon.BeaconForEpoch(epoch)
|
|
|
|
rr := b.MaxBeaconRoundForEpoch(epoch)
|
|
|
|
e := b.Entry(ctx, rr)
|
2020-08-06 01:52:43 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case be, ok := <-e:
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("beacon get returned no value")
|
|
|
|
}
|
|
|
|
if be.Err != nil {
|
|
|
|
return nil, be.Err
|
|
|
|
}
|
|
|
|
return &be.Entry, nil
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
|
|
|
}
|