Incremental deal payments
This commit is contained in:
@@ -96,8 +96,9 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.A
|
||||
}
|
||||
|
||||
head := a.Chain.GetHeaviestTipSet()
|
||||
vouchers := deals.VoucherSpec(blocksDuration, total, head.Height(), extra)
|
||||
|
||||
payment, err := a.PaychNewPayment(ctx, self, miner, total, extra, head.Height()+blocksDuration, head.Height()+blocksDuration)
|
||||
payment, err := a.PaychNewPayment(ctx, self, miner, vouchers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -110,7 +111,7 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.A
|
||||
PayChActor: payment.Channel,
|
||||
Payer: self,
|
||||
ChannelMessage: payment.ChannelMessage,
|
||||
Vouchers: []*types.SignedVoucher{payment.Voucher},
|
||||
Vouchers: payment.Vouchers,
|
||||
},
|
||||
MinerAddress: miner,
|
||||
ClientAddress: self,
|
||||
|
||||
+25
-11
@@ -42,8 +42,11 @@ func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (u
|
||||
return a.PaychMgr.AllocateLane(ch)
|
||||
}
|
||||
|
||||
func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address, amount types.BigInt, extra *types.ModVerifyParams, tl uint64, minClose uint64) (*api.PaymentInfo, error) {
|
||||
func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []api.VoucherSpec) (*api.PaymentInfo, error) {
|
||||
amount := vouchers[len(vouchers)-1].Amount
|
||||
|
||||
// TODO: Fix free fund tracking in PaychGet
|
||||
// TODO: validate voucher spec before locking funds
|
||||
ch, err := a.PaychGet(ctx, from, to, amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -54,17 +57,24 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sv, err := a.paychVoucherCreate(ctx, ch.Channel, types.SignedVoucher{
|
||||
Amount: amount,
|
||||
Lane: lane,
|
||||
svs := make([]*types.SignedVoucher, len(vouchers))
|
||||
|
||||
Extra: extra,
|
||||
TimeLock: tl,
|
||||
MinCloseHeight: minClose,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for i, v := range vouchers {
|
||||
sv, err := a.paychVoucherCreate(ctx, ch.Channel, types.SignedVoucher{
|
||||
Amount: v.Amount,
|
||||
Lane: lane,
|
||||
|
||||
Extra: v.Extra,
|
||||
TimeLock: v.TimeLock,
|
||||
MinCloseHeight: v.MinClose,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
svs[i] = sv
|
||||
}
|
||||
|
||||
var pchCid *cid.Cid
|
||||
if ch.ChannelMessage != cid.Undef {
|
||||
pchCid = &ch.ChannelMessage
|
||||
@@ -73,7 +83,7 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
|
||||
return &api.PaymentInfo{
|
||||
Channel: ch.Channel,
|
||||
ChannelMessage: pchCid,
|
||||
Voucher: sv,
|
||||
Vouchers: svs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -126,6 +136,10 @@ func (a *PaychAPI) PaychClose(ctx context.Context, addr address.Address) (cid.Ci
|
||||
return smsg.Cid(), nil
|
||||
}
|
||||
|
||||
func (a *PaychAPI) PaychLaneState(ctx context.Context, ch address.Address, lane uint64) (actors.LaneState, error) {
|
||||
return a.PaychMgr.LaneState(ctx, ch, lane)
|
||||
}
|
||||
|
||||
func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *types.SignedVoucher) error {
|
||||
return a.PaychMgr.CheckVoucherValid(ctx, ch, sv)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user