lotus/paychmgr/state.go
raulk cdf3812e40
NV18: Filecoin EVM runtime + Actor Events + EthAccount + EAM + f4 addressing (#9998)
Co-authored-by: Steven Allen <steven@stebalien.com>
Co-authored-by: Raul Kripalani <raulk@users.noreply.github.com>
Co-authored-by: Kevin Li <ychiaoli18@users.noreply.github.com>
Co-authored-by: vyzo <vyzo@hackzen.org>
Co-authored-by: Ian Davis <nospam@iandavis.com>
Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com>
Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com>
Co-authored-by: Jennifer Wang <jiayingw703@gmail.com>
Co-authored-by: Geoff Stuart <geoff.vball@gmail.com>
Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai>
Co-authored-by: Shrenuj Bansal <108157875+shrenujbansal@users.noreply.github.com>
Co-authored-by: Geoff Stuart <geoffrey.stuart@protocol.ai>
Co-authored-by: Aayush Rajasekaran <aayushrajasekaran@Aayushs-MacBook-Pro.local>
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>
2023-01-13 19:11:13 +00:00

87 lines
1.7 KiB
Go

package paychmgr
import (
"context"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
"github.com/filecoin-project/lotus/chain/types"
)
type stateAccessor struct {
sm stateManagerAPI
}
func (ca *stateAccessor) loadPaychActorState(ctx context.Context, ch address.Address) (*types.Actor, paych.State, error) {
return ca.sm.GetPaychState(ctx, ch, nil)
}
func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Address, dir uint64) (*ChannelInfo, error) {
_, st, err := ca.loadPaychActorState(ctx, ch)
if err != nil {
return nil, err
}
// Load channel "From" account actor state
f, err := st.From()
if err != nil {
return nil, err
}
from, err := ca.sm.ResolveToDeterministicAddress(ctx, f, nil)
if err != nil {
return nil, err
}
t, err := st.To()
if err != nil {
return nil, err
}
to, err := ca.sm.ResolveToDeterministicAddress(ctx, t, nil)
if err != nil {
return nil, err
}
nextLane, err := ca.nextLaneFromState(ctx, st)
if err != nil {
return nil, err
}
ci := &ChannelInfo{
Channel: &ch,
Direction: dir,
NextLane: nextLane,
}
if dir == DirOutbound {
ci.Control = from
ci.Target = to
} else {
ci.Control = to
ci.Target = from
}
return ci, nil
}
func (ca *stateAccessor) nextLaneFromState(ctx context.Context, st paych.State) (uint64, error) {
laneCount, err := st.LaneCount()
if err != nil {
return 0, err
}
if laneCount == 0 {
return 0, nil
}
maxID := uint64(0)
if err := st.ForEachLaneState(func(idx uint64, _ paych.LaneState) error {
if idx > maxID {
maxID = idx
}
return nil
}); err != nil {
return 0, err
}
return maxID + 1, nil
}