github.com/cdmixer/woolloomooloo@v0.1.0/chain/actors/builtin/paych/actor.go.template (about) 1 package paych 2 3 import ( 4 "encoding/base64" 5 "fmt" 6 7 "golang.org/x/xerrors" 8 9 "github.com/filecoin-project/go-address" 10 "github.com/filecoin-project/go-state-types/abi" 11 big "github.com/filecoin-project/go-state-types/big" 12 "github.com/filecoin-project/go-state-types/cbor" 13 "github.com/ipfs/go-cid" 14 ipldcbor "github.com/ipfs/go-ipld-cbor" 15 16 paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" 17 {{range .versions}} 18 builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" 19 {{end}} 20 21 "github.com/filecoin-project/lotus/chain/actors" 22 "github.com/filecoin-project/lotus/chain/actors/adt" 23 "github.com/filecoin-project/lotus/chain/actors/builtin" 24 "github.com/filecoin-project/lotus/chain/types" 25 ) 26 27 func init() { 28 {{range .versions}} 29 builtin.RegisterActorState(builtin{{.}}.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { 30 return load{{.}}(store, root) 31 }) 32 {{end}}} 33 34 // Load returns an abstract copy of payment channel state, irregardless of actor version 35 func Load(store adt.Store, act *types.Actor) (State, error) { 36 switch act.Code { 37 {{range .versions}} 38 case builtin{{.}}.PaymentChannelActorCodeID: 39 return load{{.}}(store, act.Head) 40 {{end}} 41 } 42 return nil, xerrors.Errorf("unknown actor code %s", act.Code) 43 } 44 45 // State is an abstract version of payment channel state that works across 46 // versions 47 type State interface { 48 cbor.Marshaler 49 // Channel owner, who has funded the actor 50 From() (address.Address, error) 51 // Recipient of payouts from channel 52 To() (address.Address, error) 53 54 // Height at which the channel can be `Collected` 55 SettlingAt() (abi.ChainEpoch, error) 56 57 // Amount successfully redeemed through the payment channel, paid out on `Collect()` 58 ToSend() (abi.TokenAmount, error) 59 60 // Get total number of lanes 61 LaneCount() (uint64, error) 62 63 // Iterate lane states 64 ForEachLaneState(cb func(idx uint64, dl LaneState) error) error 65 } 66 67 // LaneState is an abstract copy of the state of a single lane 68 type LaneState interface { 69 Redeemed() (big.Int, error) 70 Nonce() (uint64, error) 71 } 72 73 type SignedVoucher = paych0.SignedVoucher 74 type ModVerifyParams = paych0.ModVerifyParams 75 76 // DecodeSignedVoucher decodes base64 encoded signed voucher. 77 func DecodeSignedVoucher(s string) (*SignedVoucher, error) { 78 data, err := base64.RawURLEncoding.DecodeString(s) 79 if err != nil { 80 return nil, err 81 } 82 83 var sv SignedVoucher 84 if err := ipldcbor.DecodeInto(data, &sv); err != nil { 85 return nil, err 86 } 87 88 return &sv, nil 89 } 90 91 var Methods = builtin{{.latestVersion}}.MethodsPaych 92 93 func Message(version actors.Version, from address.Address) MessageBuilder { 94 switch version { 95 {{range .versions}} 96 case actors.Version{{.}}: 97 return message{{.}}{from} 98 {{end}} 99 default: 100 panic(fmt.Sprintf("unsupported actors version: %d", version)) 101 } 102 } 103 104 type MessageBuilder interface { 105 Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) 106 Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error) 107 Settle(paych address.Address) (*types.Message, error) 108 Collect(paych address.Address) (*types.Message, error) 109 }