refactor: move collect inside paych manager
This commit is contained in:
parent
fb0afbf3b0
commit
a6100b7e46
@ -116,25 +116,7 @@ func (a *PaychAPI) PaychSettle(ctx context.Context, addr address.Address) (cid.C
|
||||
}
|
||||
|
||||
func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error) {
|
||||
|
||||
ci, err := a.PaychMgr.GetChannelInfo(addr)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
msg := &types.Message{
|
||||
To: addr,
|
||||
From: ci.Control,
|
||||
Value: types.NewInt(0),
|
||||
Method: builtin.MethodsPaych.Collect,
|
||||
}
|
||||
|
||||
smsg, err := a.MpoolPushMessage(ctx, msg)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
return smsg.Cid(), nil
|
||||
return a.PaychMgr.Collect(ctx, addr)
|
||||
}
|
||||
|
||||
func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error {
|
||||
|
@ -242,3 +242,11 @@ func (pm *Manager) Settle(ctx context.Context, addr address.Address) (cid.Cid, e
|
||||
}
|
||||
return ca.settle(ctx, addr)
|
||||
}
|
||||
|
||||
func (pm *Manager) Collect(ctx context.Context, addr address.Address) (cid.Cid, error) {
|
||||
ca, err := pm.accessorByAddress(addr)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
return ca.collect(ctx, addr)
|
||||
}
|
||||
|
@ -417,3 +417,27 @@ func (ca *channelAccessor) settle(ctx context.Context, ch address.Address) (cid.
|
||||
|
||||
return smgs.Cid(), err
|
||||
}
|
||||
|
||||
func (ca *channelAccessor) collect(ctx context.Context, ch address.Address) (cid.Cid, error) {
|
||||
ca.lk.Lock()
|
||||
defer ca.lk.Unlock()
|
||||
|
||||
ci, err := ca.store.ByAddress(ch)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
msg := &types.Message{
|
||||
To: ch,
|
||||
From: ci.Control,
|
||||
Value: types.NewInt(0),
|
||||
Method: builtin.MethodsPaych.Collect,
|
||||
}
|
||||
|
||||
smsg, err := ca.api.MpoolPushMessage(ctx, msg)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
return smsg.Cid(), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user