finish up initial api calls
This commit is contained in:
parent
f8000066be
commit
c986267a2e
@ -549,11 +549,46 @@ func (a *FullNodeAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, s
|
||||
}
|
||||
|
||||
func (a *FullNodeAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*types.SignedVoucher, error) {
|
||||
panic("nyi")
|
||||
ci, err := a.PaychMgr.GetChannelInfo(pch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nonce, err := a.PaychMgr.NextNonceForLane(ctx, pch, lane)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// REVIEW ME: The amount passed into this method is the absolute value on
|
||||
// the channel. I think that a common usecase here might be 'i want to pay
|
||||
// person X an additional 4 FIL'. If they just pass '4' for the amount,
|
||||
// and the channel already has sent some amount, they wont actually be
|
||||
// sending four additional filecoin.
|
||||
sv := &types.SignedVoucher{
|
||||
Lane: lane,
|
||||
Nonce: nonce,
|
||||
Amount: amt,
|
||||
}
|
||||
|
||||
vb, err := sv.SigningBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sig, err := a.WalletSign(ctx, ci.ControlAddr, vb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sv.Signature = sig
|
||||
|
||||
// REVIEWME: Should we immediately add this to the voucher store? or leave that to the caller?
|
||||
|
||||
return sv, nil
|
||||
}
|
||||
|
||||
func (a *FullNodeAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*types.SignedVoucher, error) {
|
||||
panic("nyi")
|
||||
return a.PaychMgr.ListVouchers(ctx, pch)
|
||||
}
|
||||
|
||||
var _ api.FullNode = &FullNodeAPI{}
|
||||
|
@ -189,3 +189,27 @@ func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *types
|
||||
|
||||
return pm.store.AddVoucher(ch, sv)
|
||||
}
|
||||
|
||||
func (pm *Manager) ListVouchers(ctx context.Context, ch address.Address) ([]*types.SignedVoucher, error) {
|
||||
// TODO: just having a passthrough method like this feels odd. Seems like
|
||||
// there should be some filtering we're doing here
|
||||
return pm.store.VouchersForPaych(ch)
|
||||
}
|
||||
|
||||
func (pm *Manager) NextNonceForLane(ctx context.Context, ch address.Address, lane uint64) (uint64, error) {
|
||||
vouchers, err := pm.store.VouchersForPaych(ch)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var maxnonce uint64
|
||||
for _, v := range vouchers {
|
||||
if v.Lane == lane {
|
||||
if v.Nonce > maxnonce {
|
||||
maxnonce = v.Nonce
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return maxnonce, nil
|
||||
}
|
||||
|
@ -107,9 +107,21 @@ func (ps *Store) ListChannels() ([]address.Address, error) {
|
||||
}
|
||||
|
||||
func (ps *Store) AddVoucher(ch address.Address, sv *types.SignedVoucher) error {
|
||||
panic("nyi")
|
||||
ci, err := ps.getChannelInfo(ch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ci.Vouchers = append(ci.Vouchers, sv)
|
||||
|
||||
return ps.putChannelInfo(ci)
|
||||
}
|
||||
|
||||
func (ps *Store) VouchersForPaych(addr address.Address) ([]*types.SignedVoucher, error) {
|
||||
panic("nyi")
|
||||
func (ps *Store) VouchersForPaych(ch address.Address) ([]*types.SignedVoucher, error) {
|
||||
ci, err := ps.getChannelInfo(ch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ci.Vouchers, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user