Skip to content

Commit

Permalink
add payment channel CLI and finish up commands
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Aug 13, 2019
1 parent c986267 commit 12acee5
Show file tree
Hide file tree
Showing 9 changed files with 466 additions and 33 deletions.
3 changes: 2 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ type FullNode interface {
PaychCreate(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, error)
PaychList(context.Context) ([]address.Address, error)
PaychStatus(context.Context, address.Address) (*PaychStatus, error)
PaychClose(context.Context, address.Address) error
PaychClose(context.Context, address.Address) (cid.Cid, error)
PaychVoucherCheckValid(context.Context, address.Address, *types.SignedVoucher) error
PaychVoucherCheckSpendable(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error)
PaychVoucherCreate(context.Context, address.Address, types.BigInt, uint64) (*types.SignedVoucher, error)
PaychVoucherAdd(context.Context, address.Address, *types.SignedVoucher) error
PaychVoucherList(context.Context, address.Address) ([]*types.SignedVoucher, error)
PaychVoucherSubmit(context.Context, address.Address, *types.SignedVoucher) (cid.Cid, error)
}

// Full API is a low-level interface to the Filecoin network storage miner node
Expand Down
9 changes: 7 additions & 2 deletions api/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ type FullNodeStruct struct {
PaychCreate func(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
PaychStatus func(context.Context, address.Address) (*PaychStatus, error) `perm:"read"`
PaychClose func(context.Context, address.Address) error `perm:"sign"`
PaychClose func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"`
PaychVoucherCheck func(context.Context, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckValid func(context.Context, address.Address, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckSpendable func(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"`
PaychVoucherAdd func(context.Context, address.Address, *types.SignedVoucher) error `perm:"write"`
PaychVoucherCreate func(context.Context, address.Address, types.BigInt, uint64) (*types.SignedVoucher, error) `perm:"sign"`
PaychVoucherList func(context.Context, address.Address) ([]*types.SignedVoucher, error) `perm:"write"`
PaychVoucherSubmit func(context.Context, address.Address, *types.SignedVoucher) (cid.Cid, error) `perm:"sign"`
}
}

Expand Down Expand Up @@ -282,10 +283,14 @@ func (c *FullNodeStruct) PaychVoucherList(ctx context.Context, pch address.Addre
return c.Internal.PaychVoucherList(ctx, pch)
}

func (c *FullNodeStruct) PaychClose(ctx context.Context, a address.Address) error {
func (c *FullNodeStruct) PaychClose(ctx context.Context, a address.Address) (cid.Cid, error) {
return c.Internal.PaychClose(ctx, a)
}

func (c *FullNodeStruct) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *types.SignedVoucher) (cid.Cid, error) {
return c.Internal.PaychVoucherSubmit(ctx, ch, sv)
}

func (c *StorageMinerStruct) ActorAddresses(ctx context.Context) ([]address.Address, error) {
return c.Internal.ActorAddresses(ctx)
}
Expand Down
25 changes: 25 additions & 0 deletions chain/types/voucher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"encoding/base64"

"github.com/filecoin-project/go-lotus/chain/address"
cbor "github.com/ipfs/go-ipld-cbor"
)
Expand Down Expand Up @@ -31,6 +33,29 @@ func (sv *SignedVoucher) SigningBytes() ([]byte, error) {
return cbor.DumpObject(osv)
}

func (sv *SignedVoucher) EncodedString() (string, error) {
data, err := cbor.DumpObject(sv)
if err != nil {
return "", err
}

return base64.RawURLEncoding.EncodeToString(data), nil
}

func DecodeSignedVoucher(s string) (*SignedVoucher, error) {
data, err := base64.RawURLEncoding.DecodeString(s)
if err != nil {
return nil, err
}

var sv SignedVoucher
if err := cbor.DecodeInto(data, &sv); err != nil {
return nil, err
}

return &sv, nil
}

type Merge struct {
Lane uint64
Nonce uint64
Expand Down
18 changes: 14 additions & 4 deletions chain/call.go → chain/vm/call.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package chain
package vm

import (
"context"

"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/store"
"github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/chain/vm"
"golang.org/x/xerrors"
)

Expand All @@ -19,7 +18,7 @@ func Call(ctx context.Context, cs *store.ChainStore, msg *types.Message, ts *typ
return nil, err
}

vmi, err := vm.NewVM(state, ts.Height(), ts.Blocks()[0].Miner, cs)
vmi, err := NewVM(state, ts.Height(), ts.Blocks()[0].Miner, cs)
if err != nil {
return nil, xerrors.Errorf("failed to set up vm: %w", err)
}
Expand All @@ -40,10 +39,21 @@ func Call(ctx context.Context, cs *store.ChainStore, msg *types.Message, ts *typ
}
}

fromActor, err := vmi.cstate.GetActor(msg.From)
if err != nil {
return nil, err
}

msg.Nonce = fromActor.Nonce

// TODO: maybe just use the invoker directly?
ret, err := vmi.ApplyMessage(ctx, msg)
if err != nil {
return nil, xerrors.Errorf("apply message failed: %w", err)
}

if ret.ActorErr != nil {
log.Warnf("chain call failed: %s", ret.ActorErr)
}
return &ret.MessageReceipt, err
return &ret.MessageReceipt, nil
}
7 changes: 4 additions & 3 deletions cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ func ReqContext(cctx *cli.Context) context.Context {
var Commands = []*cli.Command{
chainCmd,
clientCmd,
createMinerCmd,
minerCmd,
mpoolCmd,
netCmd,
paychCmd,
sendCmd,
stateCmd,
versionCmd,
walletCmd,
createMinerCmd,
stateCmd,
sendCmd,
}
Loading

0 comments on commit 12acee5

Please sign in to comment.