Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/simple api perm comment #4655

Merged
merged 3 commits into from
Dec 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 6 additions & 49 deletions venus-devtool/api-gen/proxygen.go
Original file line number Diff line number Diff line change
@@ -12,15 +12,11 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"text/template"
"unicode"

"github.com/filecoin-project/go-jsonrpc/auth"
_ "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/venus/app/client/funcrule"
"golang.org/x/xerrors"
)

@@ -36,49 +32,12 @@ var (
VenusV1ApiFile = path.Join(VenusAPIPath, "chain/v1", GenAPIFileName)
)

// Rule[perm:read,ignore:true]
var rulePattern = `Rule\[(?P<rule>.*)\]`

type ruleKey = string

const (
rkPerm ruleKey = "perm"
rkIgnore ruleKey = "ignore"
rkPerm ruleKey = "perm"
)

var defaultPerm = []string{"perm", "read"}
var regRule, _ = regexp.Compile(rulePattern)

func parseRule(comment string) (*funcrule.Rule, map[string][]string) {
rule := new(funcrule.Rule)
match := regRule.FindStringSubmatch(comment)
tags := map[string][]string{}
if len(match) == 2 {
pairs := strings.Split(match[1], ",")
for _, v := range pairs {
pair := strings.Split(v, ":")
if len(pair) != 2 {
continue
}
switch pair[0] {
case rkPerm:
tags[rkPerm] = pair
rule.Perm = auth.Permission(pair[1])
case rkIgnore:
ig, err := strconv.ParseBool(pair[1])
if err != nil {
panic("the rule tag is invalid format")
}
rule.Ignore = ig
}
}
} else {
rule.Perm = "read"
tags[rkPerm] = defaultPerm
}
return rule, tags
}

type methodMeta struct {
node ast.Node
ftype *ast.FuncType
@@ -372,13 +331,11 @@ func methodMetaFromInterface(rootPath string, pkg, outpkg string) (*meta, error)

// try to parse tag info
if len(filteredComments) > 0 {
cmt := filteredComments[0].List[len(filteredComments[0].List)-1].Text
rule, tags := parseRule(cmt)
info.Methods[mname].Tags[rkPerm] = tags[rkPerm]
// remove ignore method
if rule.Ignore {
ignoreMethods[ifname] = append(ignoreMethods[ifname], mname)
}
lastComment := filteredComments[len(filteredComments)-1]
// eg. cmt = `//perm:read`
cmt := lastComment.List[len(lastComment.List)-1].Text
cmt = strings.Replace(cmt, "//", "", 1)
info.Methods[mname].Tags[rkPerm] = strings.Split(cmt, ":")
}
}
}
24 changes: 21 additions & 3 deletions venus-devtool/compatible/actors/main.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/urfave/cli/v2"
@@ -145,18 +146,35 @@ var replicaCmd = &cli.Command{
return fmt.Errorf("find chain/actors: %w", err)
}

reg := regexp.MustCompile(`v[0-9]+.go`)

files, err := listFilesInDir(srcDir, func(path string, d fs.DirEntry) bool {
if d.IsDir() {
return true
}

// need adt.go diff_adt.go
if strings.Contains(path, "adt.go") {
return false
}

// skip test file
if strings.HasSuffix(path, "test.go") {
return true
}

// diff.go diff_deadlines.go version.go params.go utils.go util.go
if !strings.Contains(path, "diff") && !strings.HasSuffix(path, "version.go") &&
!strings.HasSuffix(path, "params.go") && !strings.Contains(path, "util") {
if strings.HasSuffix(path, "main.go") || strings.Contains(path, "template") ||
strings.Contains(path, "message") {
return true
}

dir := filepath.Dir(path)
arr := strings.Split(dir, "/")
if strings.HasSuffix(path, fmt.Sprintf("%s.go", arr[len(arr)-1])) {
return true
}

if reg.MatchString(d.Name()) {
return true
}

2 changes: 2 additions & 0 deletions venus-shared/actors/adt/adt.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FETCHED FROM LOTUS: adt/adt.go

package adt

import (
2 changes: 2 additions & 0 deletions venus-shared/actors/adt/store.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FETCHED FROM LOTUS: adt/store.go

package adt

import (
2 changes: 2 additions & 0 deletions venus-shared/actors/aerrors/error.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FETCHED FROM LOTUS: aerrors/error.go

package aerrors

import (
2 changes: 2 additions & 0 deletions venus-shared/actors/aerrors/wrap.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FETCHED FROM LOTUS: aerrors/wrap.go

package aerrors

import (
31 changes: 31 additions & 0 deletions venus-shared/actors/builtin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// FETCHED FROM LOTUS: builtin/README.md

# Actors

This package contains shims for abstracting over different actor versions.

## Design

Shims in this package follow a few common design principles.

### Structure Agnostic

Shims interfaces defined in this package should (ideally) not change even if the
structure of the underlying data changes. For example:

* All shims store an internal "store" object. That way, state can be moved into
a separate object without needing to add a store to the function signature.
* All functions must return an error, even if unused for now.

### Minimal

These interfaces should be expanded only as necessary to reduce maintenance burden.

### Queries, not field assessors.

When possible, functions should query the state instead of simply acting as
field assessors. These queries are more likely to remain stable across
specs-actor upgrades than specific state fields.

Note: there is a trade-off here. Avoid implementing _complicated_ query logic
inside these shims, as it will need to be replicated in every shim.
12 changes: 4 additions & 8 deletions venus-shared/api/chain/v0/blockstore.go
Original file line number Diff line number Diff line change
@@ -9,12 +9,8 @@ import (
)

type IBlockStore interface {
// Rule[perm:read]
ChainReadObj(ctx context.Context, ocid cid.Cid) ([]byte, error)
// Rule[perm:admin]
ChainDeleteObj(ctx context.Context, obj cid.Cid) error
// Rule[perm:read]
ChainHasObj(ctx context.Context, obj cid.Cid) (bool, error)
// Rule[perm:read]
ChainStatObj(ctx context.Context, obj cid.Cid, base cid.Cid) (chain2.ObjStat, error)
ChainReadObj(ctx context.Context, cid cid.Cid) ([]byte, error) //perm:read
ChainDeleteObj(ctx context.Context, obj cid.Cid) error //perm:admin
ChainHasObj(ctx context.Context, obj cid.Cid) (bool, error) //perm:read
ChainStatObj(ctx context.Context, obj cid.Cid, base cid.Cid) (chain2.ObjStat, error) //perm:read
}
207 changes: 69 additions & 138 deletions venus-shared/api/chain/v0/chain.go

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions venus-shared/api/chain/v0/discovery.go

This file was deleted.

14 changes: 0 additions & 14 deletions venus-shared/api/chain/v0/fullnode.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/*
in api interface, you can add comment tags to the function
Note:
Rule[perm:admin,ignore:true]
perm: read,write,sign,admin
jwt token permission check
ignore: bool
the func in the api whether needs to be added to the client for external exposure
TODO:
1. Support global FUNC injection
*/
package v0

//go:generate go run github.com/golang/mock/mockgen@v1.6.0 -destination=./mock/full.go -package=mock . FullNode
@@ -19,7 +6,6 @@ package v0
type FullNode interface {
IBlockStore
IChain
IDiscovery
IMarket
IMining
IMessagePool
6 changes: 2 additions & 4 deletions venus-shared/api/chain/v0/jwtauth.go
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ import (
)

type IJwtAuthAPI interface {
// Rule[perm:read]
Verify(ctx context.Context, host, token string) ([]auth.Permission, error)
// Rule[perm:admin]
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error)
Verify(ctx context.Context, host, token string) ([]auth.Permission, error) //perm:read
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error) //perm:admin
}
3 changes: 1 addition & 2 deletions venus-shared/api/chain/v0/market.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,5 @@ import (
)

type IMarket interface {
// Rule[perm:read]
StateMarketParticipants(ctx context.Context, tsk chain.TipSetKey) (map[string]chain2.MarketBalance, error) //perm:admin
StateMarketParticipants(ctx context.Context, tsk chain.TipSetKey) (map[string]chain2.MarketBalance, error) //perm:read
}
6 changes: 2 additions & 4 deletions venus-shared/api/chain/v0/mining.go
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ import (
)

type IMining interface {
// Rule[perm:read]
MinerGetBaseInfo(ctx context.Context, maddr address.Address, round abi.ChainEpoch, tsk chain.TipSetKey) (*chain2.MiningBaseInfo, error)
// Rule[perm:write]
MinerCreateBlock(ctx context.Context, bt *chain2.BlockTemplate) (*chain.BlockMsg, error)
MinerGetBaseInfo(ctx context.Context, maddr address.Address, round abi.ChainEpoch, tsk chain.TipSetKey) (*chain2.MiningBaseInfo, error) //perm:read
MinerCreateBlock(ctx context.Context, bt *chain2.BlockTemplate) (*chain.BlockMsg, error) //perm:write
}
66 changes: 22 additions & 44 deletions venus-shared/api/chain/v0/mpool.go
Original file line number Diff line number Diff line change
@@ -13,48 +13,26 @@ import (
)

type IMessagePool interface {
// Rule[perm:admin]
MpoolDeleteByAdress(ctx context.Context, addr address.Address) error
// Rule[perm:admin]
MpoolPublishByAddr(context.Context, address.Address) error
// Rule[perm:admin]
MpoolPublishMessage(ctx context.Context, smsg *chain.SignedMessage) error
// Rule[perm:write]
MpoolPush(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error)
// Rule[perm:read]
MpoolGetConfig(context.Context) (*messagepool.MpoolConfig, error)
// Rule[perm:admin]
MpoolSetConfig(ctx context.Context, cfg *messagepool.MpoolConfig) error
// Rule[perm:read]
MpoolSelect(context.Context, chain.TipSetKey, float64) ([]*chain.SignedMessage, error)
// Rule[perm:read]
MpoolSelects(context.Context, chain.TipSetKey, []float64) ([][]*chain.SignedMessage, error)
// Rule[perm:read]
MpoolPending(ctx context.Context, tsk chain.TipSetKey) ([]*chain.SignedMessage, error)
// Rule[perm:write]
MpoolClear(ctx context.Context, local bool) error
// Rule[perm:write]
MpoolPushUntrusted(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error)
// Rule[perm:sign]
MpoolPushMessage(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec) (*chain.SignedMessage, error)
// Rule[perm:write]
MpoolBatchPush(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error)
// Rule[perm:write]
MpoolBatchPushUntrusted(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error)
// Rule[perm:sign]
MpoolBatchPushMessage(ctx context.Context, msgs []*chain.Message, spec *chain2.MessageSendSpec) ([]*chain.SignedMessage, error)
// Rule[perm:read]
MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error)
// Rule[perm:read]
MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error)
// Rule[perm:read]
GasEstimateMessageGas(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec, tsk chain.TipSetKey) (*chain.Message, error)
// Rule[perm:read]
GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*chain2.EstimateMessage, fromNonce uint64, tsk chain.TipSetKey) ([]*chain2.EstimateResult, error)
// Rule[perm:read]
GasEstimateFeeCap(ctx context.Context, msg *chain.Message, maxqueueblks int64, tsk chain.TipSetKey) (big.Int, error)
// Rule[perm:read]
GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk chain.TipSetKey) (big.Int, error)
// Rule[perm:read]
GasEstimateGasLimit(ctx context.Context, msgIn *chain.Message, tsk chain.TipSetKey) (int64, error)
MpoolDeleteByAdress(ctx context.Context, addr address.Address) error //perm:admin
MpoolPublishByAddr(context.Context, address.Address) error //perm:admin
MpoolPublishMessage(ctx context.Context, smsg *chain.SignedMessage) error //perm:admin
MpoolPush(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error) //perm:write
MpoolGetConfig(context.Context) (*messagepool.MpoolConfig, error) //perm:read
MpoolSetConfig(ctx context.Context, cfg *messagepool.MpoolConfig) error //perm:admin
MpoolSelect(context.Context, chain.TipSetKey, float64) ([]*chain.SignedMessage, error) //perm:read
MpoolSelects(context.Context, chain.TipSetKey, []float64) ([][]*chain.SignedMessage, error) //perm:read
MpoolPending(ctx context.Context, tsk chain.TipSetKey) ([]*chain.SignedMessage, error) //perm:read
MpoolClear(ctx context.Context, local bool) error //perm:write
MpoolPushUntrusted(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error) //perm:write
MpoolPushMessage(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec) (*chain.SignedMessage, error) //perm:sign
MpoolBatchPush(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error) //perm:write
MpoolBatchPushUntrusted(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error) //perm:write
MpoolBatchPushMessage(ctx context.Context, msgs []*chain.Message, spec *chain2.MessageSendSpec) ([]*chain.SignedMessage, error) //perm:sign
MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) //perm:read
MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error) //perm:read
GasEstimateMessageGas(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec, tsk chain.TipSetKey) (*chain.Message, error) //perm:read
GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*chain2.EstimateMessage, fromNonce uint64, tsk chain.TipSetKey) ([]*chain2.EstimateResult, error) //perm:read
GasEstimateFeeCap(ctx context.Context, msg *chain.Message, maxqueueblks int64, tsk chain.TipSetKey) (big.Int, error) //perm:read
GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk chain.TipSetKey) (big.Int, error) //perm:read
GasEstimateGasLimit(ctx context.Context, msgIn *chain.Message, tsk chain.TipSetKey) (int64, error) //perm:read
}
39 changes: 13 additions & 26 deletions venus-shared/api/chain/v0/multisig.go
Original file line number Diff line number Diff line change
@@ -15,30 +15,17 @@ type IMultiSig interface {
// MsigCreate creates a multisig wallet
// It takes the following params: <required number of senders>, <approving addresses>, <unlock duration>
//<initial balance>, <sender address of the create msg>, <gas price>
// Rule[perm:sign]
MsigCreate(context.Context, uint64, []address.Address, abi.ChainEpoch, chain.BigInt, address.Address, chain.BigInt) (cid.Cid, error)
// Rule[perm:sign]
MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error)
// Rule[perm:sign]
MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (cid.Cid, error)
// Rule[perm:sign]
MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (cid.Cid, error)
// Rule[perm:sign]
MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (cid.Cid, error)
// Rule[perm:sign]
MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error)
// Rule[perm:sign]
MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error)
// Rule[perm:sign]
MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (cid.Cid, error)
// Rule[perm:sign]
MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (cid.Cid, error)
// Rule[perm:sign]
MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error)
// Rule[perm:sign]
MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error)
// Rule[perm:sign]
MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (cid.Cid, error)
// Rule[perm:read]
MsigGetVested(ctx context.Context, addr address.Address, start chain.TipSetKey, end chain.TipSetKey) (chain.BigInt, error)
MsigCreate(context.Context, uint64, []address.Address, abi.ChainEpoch, chain.BigInt, address.Address, chain.BigInt) (cid.Cid, error) //perm:sign
MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error) //perm:sign
MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (cid.Cid, error) //perm:sign
MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (cid.Cid, error) //perm:sign
MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (cid.Cid, error) //perm:sign
MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) //perm:sign
MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) //perm:sign
MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) //perm:sign
MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (cid.Cid, error) //perm:sign
MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error) //perm:sign
MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error) //perm:sign
MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (cid.Cid, error) //perm:sign
MsigGetVested(ctx context.Context, addr address.Address, start chain.TipSetKey, end chain.TipSetKey) (chain.BigInt, error) //perm:read
}
30 changes: 10 additions & 20 deletions venus-shared/api/chain/v0/network.go
Original file line number Diff line number Diff line change
@@ -13,24 +13,14 @@ import (
)

type INetwork interface {
// Rule[perm:admin]
NetworkGetBandwidthStats(ctx context.Context) metrics.Stats
// Rule[perm:admin]
NetworkGetPeerAddresses(ctx context.Context) []ma.Multiaddr
// Rule[perm:admin]
NetworkGetPeerID(ctx context.Context) peer.ID
// Rule[perm:read]
NetworkFindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo
// Rule[perm:read]
NetworkGetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error)
// Rule[perm:read]
NetworkFindPeer(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error)
// Rule[perm:read]
NetworkConnect(ctx context.Context, addrs []string) (<-chan net.ConnectionResult, error)
// Rule[perm:read]
NetworkPeers(ctx context.Context, verbose, latency, streams bool) (*net.SwarmConnInfos, error)
// Rule[perm:read]
Version(context.Context) (chain2.Version, error)
// Rule[perm:read]
NetAddrsListen(context.Context) (peer.AddrInfo, error)
NetworkGetBandwidthStats(ctx context.Context) metrics.Stats //perm:admin
NetworkGetPeerAddresses(ctx context.Context) []ma.Multiaddr //perm:admin
NetworkGetPeerID(ctx context.Context) peer.ID //perm:admin
NetworkFindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo //perm:read
NetworkGetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error) //perm:read
NetworkFindPeer(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error) //perm:read
NetworkConnect(ctx context.Context, addrs []string) (<-chan net.ConnectionResult, error) //perm:read
NetworkPeers(ctx context.Context, verbose, latency, streams bool) (*net.SwarmConnInfos, error) //perm:read
Version(context.Context) (chain2.Version, error) //perm:read
NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read
}
48 changes: 16 additions & 32 deletions venus-shared/api/chain/v0/paych.go
Original file line number Diff line number Diff line change
@@ -16,84 +16,68 @@ type IPaychan interface {
// @from: the payment channel sender
// @to: the payment channel recipient
// @amt: the deposits funds in the payment channel
// Rule[perm:sign]
PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paych.ChannelInfo, error)
PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paych.ChannelInfo, error) //perm:sign
// PaychAvailableFunds get the status of an outbound payment channel
// @pch: payment channel address
// Rule[perm:sign]
PaychAvailableFunds(ctx context.Context, ch address.Address) (*chain2.ChannelAvailableFunds, error)
PaychAvailableFunds(ctx context.Context, ch address.Address) (*chain2.ChannelAvailableFunds, error) //perm:sign
// PaychAvailableFundsByFromTo get the status of an outbound payment channel
// @from: the payment channel sender
// @to: he payment channel recipient
// Rule[perm:sign]
PaychAvailableFundsByFromTo(ctx context.Context, from, to address.Address) (*chain2.ChannelAvailableFunds, error)
PaychAvailableFundsByFromTo(ctx context.Context, from, to address.Address) (*chain2.ChannelAvailableFunds, error) //perm:sign
// PaychGetWaitReady waits until the create channel / add funds message with the sentinel
// @sentinel: given message CID arrives.
// @ch: the returned channel address can safely be used against the Manager methods.
// Rule[perm:sign]
PaychGetWaitReady(ctx context.Context, sentinel cid.Cid) (address.Address, error)
PaychGetWaitReady(ctx context.Context, sentinel cid.Cid) (address.Address, error) //perm:sign
// PaychAllocateLane Allocate late creates a lane within a payment channel so that calls to
// CreatePaymentVoucher will automatically make vouchers only for the difference in total
// Rule[perm:sign]
PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error)
PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error) //perm:sign
// PaychNewPayment aggregate vouchers into a new lane
// @from: the payment channel sender
// @to: the payment channel recipient
// @vouchers: the outstanding (non-redeemed) vouchers
// Rule[perm:sign]
PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paych.VoucherSpec) (*paych.PaymentInfo, error)
PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paych.VoucherSpec) (*paych.PaymentInfo, error) //perm:sign
// PaychList list the addresses of all channels that have been created
// Rule[perm:read]
PaychList(ctx context.Context) ([]address.Address, error)
PaychList(ctx context.Context) ([]address.Address, error) //perm:read
// PaychStatus get the payment channel status
// @pch: payment channel address
// Rule[perm:read]
PaychStatus(ctx context.Context, pch address.Address) (*paych.Status, error)
PaychStatus(ctx context.Context, pch address.Address) (*paych.Status, error) //perm:read
// PaychSettle update payment channel status to settle
// After a settlement period (currently 12 hours) either party to the payment channel can call collect on chain
// @pch: payment channel address
// Rule[perm:sign]
PaychSettle(ctx context.Context, addr address.Address) (cid.Cid, error)
PaychSettle(ctx context.Context, addr address.Address) (cid.Cid, error) //perm:sign
// PaychCollect update payment channel status to collect
// Collect sends the value of submitted vouchers to the channel recipient (the provider),
// and refunds the remaining channel balance to the channel creator (the client).
// @pch: payment channel address
// Rule[perm:sign]
PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error)
PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error) //perm:sign

// PaychVoucherCheckValid checks if the given voucher is valid (is or could become spendable at some point).
// If the channel is not in the store, fetches the channel from state (and checks that
// the channel To address is owned by the wallet).
// @pch: payment channel address
// @sv: voucher
// Rule[perm:read]
PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error
PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error //perm:read
// PaychVoucherCheckSpendable checks if the given voucher is currently spendable
// @pch: payment channel address
// @sv: voucher
// Rule[perm:read]
PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error)
PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) //perm:read
// PaychVoucherAdd adds a voucher for an inbound channel.
// If the channel is not in the store, fetches the channel from state (and checks that
// the channel To address is owned by the wallet).
// Rule[perm:write]
PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta big.Int) (big.Int, error)
PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta big.Int) (big.Int, error) //perm:write
// PaychVoucherCreate creates a new signed voucher on the given payment channel
// with the given lane and amount. The value passed in is exactly the value
// that will be used to create the voucher, so if previous vouchers exist, the
// actual additional value of this voucher will only be the difference between
// the two.
// If there are insufficient funds in the channel to create the voucher,
// returns a nil voucher and the shortfall.
// Rule[perm:sign]
PaychVoucherCreate(ctx context.Context, pch address.Address, amt big.Int, lane uint64) (*paych.VoucherCreateResult, error)
PaychVoucherCreate(ctx context.Context, pch address.Address, amt big.Int, lane uint64) (*paych.VoucherCreateResult, error) //perm:sign
// PaychVoucherList list vouchers in payment channel
// @pch: payment channel address
// Rule[perm:write]
PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error)
PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) //perm:write
// PaychVoucherSubmit Submit voucher to chain to update payment channel state
// @pch: payment channel address
// @sv: voucher in payment channel
// Rule[perm:sign]
PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error)
PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) //perm:sign
}
4 changes: 0 additions & 4 deletions venus-shared/api/chain/v0/proxy_gen.go
24 changes: 8 additions & 16 deletions venus-shared/api/chain/v0/syncer.go
Original file line number Diff line number Diff line change
@@ -10,20 +10,12 @@ import (
)

type ISyncer interface {
// Rule[perm:write]
ChainSyncHandleNewTipSet(ctx context.Context, ci *chain.ChainInfo) error
// Rule[perm:admin]
SetConcurrent(ctx context.Context, concurrent int64) error
// Rule[perm:read]
SyncerTracker(ctx context.Context) *chain2.TargetTracker
// Rule[perm:read]
Concurrent(ctx context.Context) int64
// Rule[perm:read]
ChainTipSetWeight(ctx context.Context, tsk chain.TipSetKey) (big.Int, error)
// Rule[perm:write]
SyncSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error
// Rule[perm:read]
StateCall(ctx context.Context, msg *chain.Message, tsk chain.TipSetKey) (*chain2.InvocResult, error)
// Rule[perm:read]
SyncState(ctx context.Context) (*chain2.SyncState, error)
ChainSyncHandleNewTipSet(ctx context.Context, ci *chain.ChainInfo) error //perm:write
SetConcurrent(ctx context.Context, concurrent int64) error //perm:admin
SyncerTracker(ctx context.Context) *chain2.TargetTracker //perm:read
Concurrent(ctx context.Context) int64 //perm:read
ChainTipSetWeight(ctx context.Context, tsk chain.TipSetKey) (big.Int, error) //perm:read
SyncSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error //perm:write
StateCall(ctx context.Context, msg *chain.Message, tsk chain.TipSetKey) (*chain2.InvocResult, error) //perm:read
SyncState(ctx context.Context) (*chain2.SyncState, error) //perm:read
}
45 changes: 15 additions & 30 deletions venus-shared/api/chain/v0/wallet.go
Original file line number Diff line number Diff line change
@@ -12,34 +12,19 @@ import (
)

type IWallet interface {
// Rule[perm:sign]
WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error)
// Rule[perm:admin]
WalletExport(addr address.Address, password string) (*wallet.KeyInfo, error)
// Rule[perm:admin]
WalletImport(key *wallet.KeyInfo) (address.Address, error)
// Rule[perm:write]
WalletHas(ctx context.Context, addr address.Address) (bool, error)
// Rule[perm:write]
WalletNewAddress(protocol address.Protocol) (address.Address, error)
// Rule[perm:read]
WalletBalance(ctx context.Context, addr address.Address) (abi.TokenAmount, error) //not exists in remote
// Rule[perm:write]
WalletDefaultAddress(ctx context.Context) (address.Address, error) //not exists in remote
// Rule[perm:admin]
WalletAddresses(ctx context.Context) []address.Address
// Rule[perm:write]
WalletSetDefault(ctx context.Context, addr address.Address) error //not exists in remote
// Rule[perm:sign]
WalletSignMessage(ctx context.Context, k address.Address, msg *chain.Message) (*chain.SignedMessage, error)
// Rule[perm:admin]
LockWallet(ctx context.Context) error
// Rule[perm:admin]
UnLockWallet(ctx context.Context, password []byte) error
// Rule[perm:admin]
SetPassword(Context context.Context, password []byte) error
// Rule[perm:admin]
HasPassword(Context context.Context) bool
// Rule[perm:admin]
WalletState(Context context.Context) int
WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error) //perm:sign
WalletExport(addr address.Address, password string) (*wallet.KeyInfo, error) //perm:admin
WalletImport(key *wallet.KeyInfo) (address.Address, error) //perm:admin
WalletHas(ctx context.Context, addr address.Address) (bool, error) //perm:write
WalletNewAddress(protocol address.Protocol) (address.Address, error) //perm:write
WalletBalance(ctx context.Context, addr address.Address) (abi.TokenAmount, error) //perm:read
WalletDefaultAddress(ctx context.Context) (address.Address, error) //perm:write
WalletAddresses(ctx context.Context) []address.Address //perm:admin
WalletSetDefault(ctx context.Context, addr address.Address) error //perm:write
WalletSignMessage(ctx context.Context, k address.Address, msg *chain.Message) (*chain.SignedMessage, error) //perm:sign
LockWallet(ctx context.Context) error //perm:admin
UnLockWallet(ctx context.Context, password []byte) error //perm:admin
SetPassword(Context context.Context, password []byte) error //perm:admin
HasPassword(Context context.Context) bool //perm:admin
WalletState(Context context.Context) int //perm:admin
}
12 changes: 4 additions & 8 deletions venus-shared/api/chain/v1/blockstore.go
Original file line number Diff line number Diff line change
@@ -9,12 +9,8 @@ import (
)

type IBlockStore interface {
// Rule[perm:read]
ChainReadObj(ctx context.Context, ocid cid.Cid) ([]byte, error)
// Rule[perm:admin]
ChainDeleteObj(ctx context.Context, obj cid.Cid) error
// Rule[perm:read]
ChainHasObj(ctx context.Context, obj cid.Cid) (bool, error)
// Rule[perm:read]
ChainStatObj(ctx context.Context, obj cid.Cid, base cid.Cid) (chain2.ObjStat, error)
ChainReadObj(ctx context.Context, cid cid.Cid) ([]byte, error) //perm:read
ChainDeleteObj(ctx context.Context, obj cid.Cid) error //perm:admin
ChainHasObj(ctx context.Context, obj cid.Cid) (bool, error) //perm:read
ChainStatObj(ctx context.Context, obj cid.Cid, base cid.Cid) (chain2.ObjStat, error) //perm:read
}
207 changes: 69 additions & 138 deletions venus-shared/api/chain/v1/chain.go

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions venus-shared/api/chain/v1/fullnode.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/*
in api interface, you can add comment tags to the function
Note:
Rule[perm:admin,ignore:true]
perm: read,write,sign,admin
jwt token permission check
ignore: bool
the func in the api whether needs to be added to the client for external exposure
TODO:
1. Support global FUNC injection
*/
package v1

//go:generate go run github.com/golang/mock/mockgen@v1.6.0 -destination=./mock/full.go -package=mock . FullNode
6 changes: 2 additions & 4 deletions venus-shared/api/chain/v1/jwtauth.go
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ import (
)

type IJwtAuthAPI interface {
// Rule[perm:read]
Verify(ctx context.Context, host, token string) ([]auth.Permission, error)
// Rule[perm:admin]
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error)
Verify(ctx context.Context, host, token string) ([]auth.Permission, error) //perm:read
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error) //perm:admin
}
3 changes: 1 addition & 2 deletions venus-shared/api/chain/v1/market.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,5 @@ import (
)

type IMarket interface {
// Rule[perm:read]
StateMarketParticipants(ctx context.Context, tsk chain.TipSetKey) (map[string]chain2.MarketBalance, error) //perm:admin
StateMarketParticipants(ctx context.Context, tsk chain.TipSetKey) (map[string]chain2.MarketBalance, error) //perm:read
}
6 changes: 2 additions & 4 deletions venus-shared/api/chain/v1/mining.go
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ import (
)

type IMining interface {
// Rule[perm:read]
MinerGetBaseInfo(ctx context.Context, maddr address.Address, round abi.ChainEpoch, tsk chain.TipSetKey) (*chain2.MiningBaseInfo, error)
// Rule[perm:write]
MinerCreateBlock(ctx context.Context, bt *chain2.BlockTemplate) (*chain.BlockMsg, error)
MinerGetBaseInfo(ctx context.Context, maddr address.Address, round abi.ChainEpoch, tsk chain.TipSetKey) (*chain2.MiningBaseInfo, error) //perm:read
MinerCreateBlock(ctx context.Context, bt *chain2.BlockTemplate) (*chain.BlockMsg, error) //perm:write
}
75 changes: 25 additions & 50 deletions venus-shared/api/chain/v1/mpool.go
Original file line number Diff line number Diff line change
@@ -13,57 +13,32 @@ import (
)

type IMessagePool interface {
// Rule[perm:admin]
MpoolDeleteByAdress(ctx context.Context, addr address.Address) error
// Rule[perm:write]
MpoolPublishByAddr(context.Context, address.Address) error
// Rule[perm:write]
MpoolPublishMessage(ctx context.Context, smsg *chain.SignedMessage) error
// Rule[perm:write]
MpoolPush(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error)
// Rule[perm:read]
MpoolGetConfig(context.Context) (*messagepool.MpoolConfig, error)
// Rule[perm:admin]
MpoolSetConfig(ctx context.Context, cfg *messagepool.MpoolConfig) error
// Rule[perm:read]
MpoolSelect(context.Context, chain.TipSetKey, float64) ([]*chain.SignedMessage, error)
// Rule[perm:read]
MpoolSelects(context.Context, chain.TipSetKey, []float64) ([][]*chain.SignedMessage, error)
// Rule[perm:read]
MpoolPending(ctx context.Context, tsk chain.TipSetKey) ([]*chain.SignedMessage, error)
// Rule[perm:write]
MpoolClear(ctx context.Context, local bool) error
// Rule[perm:write]
MpoolPushUntrusted(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error)
// Rule[perm:sign]
MpoolPushMessage(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec) (*chain.SignedMessage, error)
// Rule[perm:write]
MpoolBatchPush(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error)
// Rule[perm:write]
MpoolBatchPushUntrusted(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error)
// Rule[perm:sign]
MpoolBatchPushMessage(ctx context.Context, msgs []*chain.Message, spec *chain2.MessageSendSpec) ([]*chain.SignedMessage, error)
// Rule[perm:read]
MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error)
// Rule[perm:read]
MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error)
// Rule[perm:read]
GasEstimateMessageGas(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec, tsk chain.TipSetKey) (*chain.Message, error)
// Rule[perm:read]
GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*chain2.EstimateMessage, fromNonce uint64, tsk chain.TipSetKey) ([]*chain2.EstimateResult, error)
// Rule[perm:read]
GasEstimateFeeCap(ctx context.Context, msg *chain.Message, maxqueueblks int64, tsk chain.TipSetKey) (big.Int, error)
// Rule[perm:read]
GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk chain.TipSetKey) (big.Int, error)
// Rule[perm:read]
GasEstimateGasLimit(ctx context.Context, msgIn *chain.Message, tsk chain.TipSetKey) (int64, error)
MpoolDeleteByAdress(ctx context.Context, addr address.Address) error //perm:admin
MpoolPublishByAddr(context.Context, address.Address) error //perm:write
MpoolPublishMessage(ctx context.Context, smsg *chain.SignedMessage) error //perm:write
MpoolPush(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error) //perm:write
MpoolGetConfig(context.Context) (*messagepool.MpoolConfig, error) //perm:read
MpoolSetConfig(ctx context.Context, cfg *messagepool.MpoolConfig) error //perm:admin
MpoolSelect(context.Context, chain.TipSetKey, float64) ([]*chain.SignedMessage, error) //perm:read
MpoolSelects(context.Context, chain.TipSetKey, []float64) ([][]*chain.SignedMessage, error) //perm:read
MpoolPending(ctx context.Context, tsk chain.TipSetKey) ([]*chain.SignedMessage, error) //perm:read
MpoolClear(ctx context.Context, local bool) error //perm:write
MpoolPushUntrusted(ctx context.Context, smsg *chain.SignedMessage) (cid.Cid, error) //perm:write
MpoolPushMessage(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec) (*chain.SignedMessage, error) //perm:sign
MpoolBatchPush(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error) //perm:write
MpoolBatchPushUntrusted(ctx context.Context, smsgs []*chain.SignedMessage) ([]cid.Cid, error) //perm:write
MpoolBatchPushMessage(ctx context.Context, msgs []*chain.Message, spec *chain2.MessageSendSpec) ([]*chain.SignedMessage, error) //perm:sign
MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) //perm:read
MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error) //perm:read
GasEstimateMessageGas(ctx context.Context, msg *chain.Message, spec *chain2.MessageSendSpec, tsk chain.TipSetKey) (*chain.Message, error) //perm:read
GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*chain2.EstimateMessage, fromNonce uint64, tsk chain.TipSetKey) ([]*chain2.EstimateResult, error) //perm:read
GasEstimateFeeCap(ctx context.Context, msg *chain.Message, maxqueueblks int64, tsk chain.TipSetKey) (big.Int, error) //perm:read
GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk chain.TipSetKey) (big.Int, error) //perm:read
GasEstimateGasLimit(ctx context.Context, msgIn *chain.Message, tsk chain.TipSetKey) (int64, error) //perm:read
// MpoolCheckMessages performs logical checks on a batch of messages
// Rule[perm:read]
MpoolCheckMessages(ctx context.Context, protos []*messagepool.MessagePrototype) ([][]messagepool.MessageCheckStatus, error)
MpoolCheckMessages(ctx context.Context, protos []*messagepool.MessagePrototype) ([][]messagepool.MessageCheckStatus, error) //perm:read
// MpoolCheckPendingMessages performs logical checks for all pending messages from a given address
// Rule[perm:read]
MpoolCheckPendingMessages(ctx context.Context, addr address.Address) ([][]messagepool.MessageCheckStatus, error)
MpoolCheckPendingMessages(ctx context.Context, addr address.Address) ([][]messagepool.MessageCheckStatus, error) //perm:read
// MpoolCheckReplaceMessages performs logical checks on pending messages with replacement
// Rule[perm:read]
MpoolCheckReplaceMessages(ctx context.Context, msg []*chain.Message) ([][]messagepool.MessageCheckStatus, error)
MpoolCheckReplaceMessages(ctx context.Context, msg []*chain.Message) ([][]messagepool.MessageCheckStatus, error) //perm:read
}
39 changes: 13 additions & 26 deletions venus-shared/api/chain/v1/multisig.go
Original file line number Diff line number Diff line change
@@ -11,30 +11,17 @@ import (
)

type IMultiSig interface {
// Rule[perm:sign]
MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val chain.BigInt, src address.Address, gp chain.BigInt) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error)
// Rule[perm:sign]
MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (*messagepool.MessagePrototype, error)
// Rule[perm:read]
MsigGetVested(ctx context.Context, addr address.Address, start chain.TipSetKey, end chain.TipSetKey) (chain.BigInt, error)
MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val chain.BigInt, src address.Address, gp chain.BigInt) (*messagepool.MessagePrototype, error) //perm:sign
MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) //perm:sign
MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) //perm:sign
MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) //perm:sign
MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) //perm:sign
MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) //perm:sign
MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) //perm:sign
MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) //perm:sign
MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (*messagepool.MessagePrototype, error) //perm:sign
MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) //perm:sign
MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt chain.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) //perm:sign
MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (*messagepool.MessagePrototype, error) //perm:sign
MsigGetVested(ctx context.Context, addr address.Address, start chain.TipSetKey, end chain.TipSetKey) (chain.BigInt, error) //perm:read
}
30 changes: 10 additions & 20 deletions venus-shared/api/chain/v1/network.go
Original file line number Diff line number Diff line change
@@ -13,24 +13,14 @@ import (
)

type INetwork interface {
// Rule[perm:admin]
NetworkGetBandwidthStats(ctx context.Context) metrics.Stats
// Rule[perm:admin]
NetworkGetPeerAddresses(ctx context.Context) []ma.Multiaddr
// Rule[perm:admin]
NetworkGetPeerID(ctx context.Context) peer.ID
// Rule[perm:read]
NetworkFindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo
// Rule[perm:read]
NetworkGetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error)
// Rule[perm:read]
NetworkFindPeer(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error)
// Rule[perm:read]
NetworkConnect(ctx context.Context, addrs []string) (<-chan net.ConnectionResult, error)
// Rule[perm:read]
NetworkPeers(ctx context.Context, verbose, latency, streams bool) (*net.SwarmConnInfos, error)
// Rule[perm:read]
Version(context.Context) (chain2.Version, error)
// Rule[perm:read]
NetAddrsListen(context.Context) (peer.AddrInfo, error)
NetworkGetBandwidthStats(ctx context.Context) metrics.Stats //perm:admin
NetworkGetPeerAddresses(ctx context.Context) []ma.Multiaddr //perm:admin
NetworkGetPeerID(ctx context.Context) peer.ID //perm:admin
NetworkFindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo //perm:read
NetworkGetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error) //perm:read
NetworkFindPeer(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error) //perm:read
NetworkConnect(ctx context.Context, addrs []string) (<-chan net.ConnectionResult, error) //perm:read
NetworkPeers(ctx context.Context, verbose, latency, streams bool) (*net.SwarmConnInfos, error) //perm:read
Version(context.Context) (chain2.Version, error) //perm:read
NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read
}
48 changes: 16 additions & 32 deletions venus-shared/api/chain/v1/paych.go
Original file line number Diff line number Diff line change
@@ -16,84 +16,68 @@ type IPaychan interface {
// @from: the payment channel sender
// @to: the payment channel recipient
// @amt: the deposits funds in the payment channel
// Rule[perm:sign]
PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paych.ChannelInfo, error)
PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paych.ChannelInfo, error) //perm:sign
// PaychAvailableFunds get the status of an outbound payment channel
// @pch: payment channel address
// Rule[perm:sign]
PaychAvailableFunds(ctx context.Context, ch address.Address) (*chain2.ChannelAvailableFunds, error)
PaychAvailableFunds(ctx context.Context, ch address.Address) (*chain2.ChannelAvailableFunds, error) //perm:sign
// PaychAvailableFundsByFromTo get the status of an outbound payment channel
// @from: the payment channel sender
// @to: he payment channel recipient
// Rule[perm:sign]
PaychAvailableFundsByFromTo(ctx context.Context, from, to address.Address) (*chain2.ChannelAvailableFunds, error)
PaychAvailableFundsByFromTo(ctx context.Context, from, to address.Address) (*chain2.ChannelAvailableFunds, error) //perm:sign
// PaychGetWaitReady waits until the create channel / add funds message with the sentinel
// @sentinel: given message CID arrives.
// @ch: the returned channel address can safely be used against the Manager methods.
// Rule[perm:sign]
PaychGetWaitReady(ctx context.Context, sentinel cid.Cid) (address.Address, error)
PaychGetWaitReady(ctx context.Context, sentinel cid.Cid) (address.Address, error) //perm:sign
// PaychAllocateLane Allocate late creates a lane within a payment channel so that calls to
// CreatePaymentVoucher will automatically make vouchers only for the difference in total
// Rule[perm:sign]
PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error)
PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error) //perm:sign
// PaychNewPayment aggregate vouchers into a new lane
// @from: the payment channel sender
// @to: the payment channel recipient
// @vouchers: the outstanding (non-redeemed) vouchers
// Rule[perm:sign]
PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paych.VoucherSpec) (*paych.PaymentInfo, error)
PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paych.VoucherSpec) (*paych.PaymentInfo, error) //perm:sign
// PaychList list the addresses of all channels that have been created
// Rule[perm:read]
PaychList(ctx context.Context) ([]address.Address, error)
PaychList(ctx context.Context) ([]address.Address, error) //perm:read
// PaychStatus get the payment channel status
// @pch: payment channel address
// Rule[perm:read]
PaychStatus(ctx context.Context, pch address.Address) (*paych.Status, error)
PaychStatus(ctx context.Context, pch address.Address) (*paych.Status, error) //perm:read
// PaychSettle update payment channel status to settle
// After a settlement period (currently 12 hours) either party to the payment channel can call collect on chain
// @pch: payment channel address
// Rule[perm:sign]
PaychSettle(ctx context.Context, addr address.Address) (cid.Cid, error)
PaychSettle(ctx context.Context, addr address.Address) (cid.Cid, error) //perm:sign
// PaychCollect update payment channel status to collect
// Collect sends the value of submitted vouchers to the channel recipient (the provider),
// and refunds the remaining channel balance to the channel creator (the client).
// @pch: payment channel address
// Rule[perm:sign]
PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error)
PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error) //perm:sign

// PaychVoucherCheckValid checks if the given voucher is valid (is or could become spendable at some point).
// If the channel is not in the store, fetches the channel from state (and checks that
// the channel To address is owned by the wallet).
// @pch: payment channel address
// @sv: voucher
// Rule[perm:read]
PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error
PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error //perm:read
// PaychVoucherCheckSpendable checks if the given voucher is currently spendable
// @pch: payment channel address
// @sv: voucher
// Rule[perm:read]
PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error)
PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) //perm:read
// PaychVoucherAdd adds a voucher for an inbound channel.
// If the channel is not in the store, fetches the channel from state (and checks that
// the channel To address is owned by the wallet).
// Rule[perm:write]
PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta big.Int) (big.Int, error)
PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta big.Int) (big.Int, error) //perm:write
// PaychVoucherCreate creates a new signed voucher on the given payment channel
// with the given lane and amount. The value passed in is exactly the value
// that will be used to create the voucher, so if previous vouchers exist, the
// actual additional value of this voucher will only be the difference between
// the two.
// If there are insufficient funds in the channel to create the voucher,
// returns a nil voucher and the shortfall.
// Rule[perm:sign]
PaychVoucherCreate(ctx context.Context, pch address.Address, amt big.Int, lane uint64) (*paych.VoucherCreateResult, error)
PaychVoucherCreate(ctx context.Context, pch address.Address, amt big.Int, lane uint64) (*paych.VoucherCreateResult, error) //perm:sign
// PaychVoucherList list vouchers in payment channel
// @pch: payment channel address
// Rule[perm:write]
PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error)
PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) //perm:write
// PaychVoucherSubmit Submit voucher to chain to update payment channel state
// @pch: payment channel address
// @sv: voucher in payment channel
// Rule[perm:sign]
PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error)
PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) //perm:sign
}
24 changes: 8 additions & 16 deletions venus-shared/api/chain/v1/syncer.go
Original file line number Diff line number Diff line change
@@ -10,20 +10,12 @@ import (
)

type ISyncer interface {
// Rule[perm:write]
ChainSyncHandleNewTipSet(ctx context.Context, ci *chain.ChainInfo) error
// Rule[perm:admin]
SetConcurrent(ctx context.Context, concurrent int64) error
// Rule[perm:read]
SyncerTracker(ctx context.Context) *chain2.TargetTracker
// Rule[perm:read]
Concurrent(ctx context.Context) int64
// Rule[perm:read]
ChainTipSetWeight(ctx context.Context, tsk chain.TipSetKey) (big.Int, error)
// Rule[perm:write]
SyncSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error
// Rule[perm:read]
StateCall(ctx context.Context, msg *chain.Message, tsk chain.TipSetKey) (*chain2.InvocResult, error)
// Rule[perm:read]
SyncState(ctx context.Context) (*chain2.SyncState, error)
ChainSyncHandleNewTipSet(ctx context.Context, ci *chain.ChainInfo) error //perm:write
SetConcurrent(ctx context.Context, concurrent int64) error //perm:admin
SyncerTracker(ctx context.Context) *chain2.TargetTracker //perm:read
Concurrent(ctx context.Context) int64 //perm:read
ChainTipSetWeight(ctx context.Context, tsk chain.TipSetKey) (big.Int, error) //perm:read
SyncSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error //perm:write
StateCall(ctx context.Context, msg *chain.Message, tsk chain.TipSetKey) (*chain2.InvocResult, error) //perm:read
SyncState(ctx context.Context) (*chain2.SyncState, error) //perm:read
}
45 changes: 15 additions & 30 deletions venus-shared/api/chain/v1/wallet.go
Original file line number Diff line number Diff line change
@@ -12,34 +12,19 @@ import (
)

type IWallet interface {
// Rule[perm:sign]
WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error)
// Rule[perm:admin]
WalletExport(addr address.Address, password string) (*wallet.KeyInfo, error)
// Rule[perm:admin]
WalletImport(key *wallet.KeyInfo) (address.Address, error)
// Rule[perm:write]
WalletHas(ctx context.Context, addr address.Address) (bool, error)
// Rule[perm:write]
WalletNewAddress(protocol address.Protocol) (address.Address, error)
// Rule[perm:read]
WalletBalance(ctx context.Context, addr address.Address) (abi.TokenAmount, error) //not exists in remote
// Rule[perm:write]
WalletDefaultAddress(ctx context.Context) (address.Address, error) //not exists in remote
// Rule[perm:admin]
WalletAddresses(ctx context.Context) []address.Address
// Rule[perm:write]
WalletSetDefault(ctx context.Context, addr address.Address) error //not exists in remote
// Rule[perm:sign]
WalletSignMessage(ctx context.Context, k address.Address, msg *chain.Message) (*chain.SignedMessage, error)
// Rule[perm:admin]
LockWallet(ctx context.Context) error
// Rule[perm:admin]
UnLockWallet(ctx context.Context, password []byte) error
// Rule[perm:admin]
SetPassword(Context context.Context, password []byte) error
// Rule[perm:admin]
HasPassword(Context context.Context) bool
// Rule[perm:admin]
WalletState(Context context.Context) int
WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error) //perm:sign
WalletExport(addr address.Address, password string) (*wallet.KeyInfo, error) //perm:admin
WalletImport(key *wallet.KeyInfo) (address.Address, error) //perm:admin
WalletHas(ctx context.Context, addr address.Address) (bool, error) //perm:write
WalletNewAddress(protocol address.Protocol) (address.Address, error) //perm:write
WalletBalance(ctx context.Context, addr address.Address) (abi.TokenAmount, error) //perm:read
WalletDefaultAddress(ctx context.Context) (address.Address, error) //perm:write
WalletAddresses(ctx context.Context) []address.Address //perm:admin
WalletSetDefault(ctx context.Context, addr address.Address) error //perm:write
WalletSignMessage(ctx context.Context, k address.Address, msg *chain.Message) (*chain.SignedMessage, error) //perm:sign
LockWallet(ctx context.Context) error //perm:admin
UnLockWallet(ctx context.Context, password []byte) error //perm:admin
SetPassword(Context context.Context, password []byte) error //perm:admin
HasPassword(Context context.Context) bool //perm:admin
WalletState(Context context.Context) int //perm:admin
}
30 changes: 30 additions & 0 deletions venus-shared/api/proxy_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package api

import "reflect"

var _internalField = "Internal"

// GetInternalStructs extracts all pointers to 'Internal' sub-structs from the provided pointer to a proxy struct
func GetInternalStructs(in interface{}) []interface{} {
return getInternalStructs(reflect.ValueOf(in).Elem())
}

func getInternalStructs(rv reflect.Value) []interface{} {
var out []interface{}

internal := rv.FieldByName(_internalField)
ii := internal.Addr().Interface()
out = append(out, ii)

for i := 0; i < rv.NumField(); i++ {
if rv.Type().Field(i).Name == _internalField {
continue
}

sub := getInternalStructs(rv.Field(i))

out = append(out, sub...)
}

return out
}
62 changes: 62 additions & 0 deletions venus-shared/api/proxy_util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package api

import (
"testing"

"github.com/stretchr/testify/require"
)

type StrA struct {
StrB

Internal struct {
A int
}
}

type StrB struct {
Internal struct {
B int
}
}

type StrC struct {
Internal struct {
Internal struct {
C int
}
}
}

func TestGetInternalStructs(t *testing.T) {
var proxy StrA

sts := GetInternalStructs(&proxy)
require.Len(t, sts, 2)

sa := sts[0].(*struct{ A int })
sa.A = 3
sb := sts[1].(*struct{ B int })
sb.B = 4

require.Equal(t, 3, proxy.Internal.A)
require.Equal(t, 4, proxy.StrB.Internal.B)
}

func TestNestedInternalStructs(t *testing.T) {
var proxy StrC

// check that only the top-level internal struct gets picked up

sts := GetInternalStructs(&proxy)
require.Len(t, sts, 1)

sa := sts[0].(*struct {
Internal struct {
C int
}
})
sa.Internal.C = 5

require.Equal(t, 5, proxy.Internal.Internal.C)
}