add api and cli calls for beneficiary withdrawl
This commit is contained in:
parent
c791fe34b9
commit
21906b5a63
@ -54,6 +54,11 @@ type StorageMiner interface {
|
||||
// and does not wait for message execution
|
||||
ActorWithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) //perm:admin
|
||||
|
||||
// BeneficiaryWithdrawBalance allows the beneficiary of a miner to withdraw balance from miner actor
|
||||
// Specify amount as "0" to withdraw full balance. This method returns a message CID
|
||||
// and does not wait for message execution
|
||||
BeneficiaryWithdrawBalance(context.Context, abi.TokenAmount) (cid.Cid, error) //perm:admin
|
||||
|
||||
MiningBase(context.Context) (*types.TipSet, error) //perm:read
|
||||
|
||||
ComputeWindowPoSt(ctx context.Context, dlIdx uint64, tsk types.TipSetKey) ([]miner.SubmitWindowedPoStParams, error) //perm:admin
|
||||
|
@ -664,6 +664,8 @@ type StorageMinerStruct struct {
|
||||
|
||||
ActorWithdrawBalance func(p0 context.Context, p1 abi.TokenAmount) (cid.Cid, error) `perm:"admin"`
|
||||
|
||||
BeneficiaryWithdrawBalance func(p0 context.Context, p1 abi.TokenAmount) (cid.Cid, error) `perm:"admin"`
|
||||
|
||||
CheckProvable func(p0 context.Context, p1 abi.RegisteredPoStProof, p2 []storiface.SectorRef, p3 bool) (map[abi.SectorNumber]string, error) `perm:"admin"`
|
||||
|
||||
ComputeDataCid func(p0 context.Context, p1 abi.UnpaddedPieceSize, p2 storiface.Data) (abi.PieceInfo, error) `perm:"admin"`
|
||||
@ -4036,6 +4038,17 @@ func (s *StorageMinerStub) ActorWithdrawBalance(p0 context.Context, p1 abi.Token
|
||||
return *new(cid.Cid), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) BeneficiaryWithdrawBalance(p0 context.Context, p1 abi.TokenAmount) (cid.Cid, error) {
|
||||
if s.Internal.BeneficiaryWithdrawBalance == nil {
|
||||
return *new(cid.Cid), ErrNotSupported
|
||||
}
|
||||
return s.Internal.BeneficiaryWithdrawBalance(p0, p1)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) BeneficiaryWithdrawBalance(p0 context.Context, p1 abi.TokenAmount) (cid.Cid, error) {
|
||||
return *new(cid.Cid), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) CheckProvable(p0 context.Context, p1 abi.RegisteredPoStProof, p2 []storiface.SectorRef, p3 bool) (map[abi.SectorNumber]string, error) {
|
||||
if s.Internal.CheckProvable == nil {
|
||||
return *new(map[abi.SectorNumber]string), ErrNotSupported
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
@ -295,6 +296,9 @@ type MinerInfo struct {
|
||||
SectorSize abi.SectorSize
|
||||
WindowPoStPartitionSectors uint64
|
||||
ConsensusFaultElapsed abi.ChainEpoch
|
||||
Beneficiary address.Address
|
||||
BeneficiaryTerm miner.BeneficiaryTerm
|
||||
PendingBeneficiaryTerm *miner.PendingBeneficiaryChange
|
||||
}
|
||||
|
||||
type NetworkParams struct {
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
@ -232,7 +233,7 @@ var actorSetPeeridCmd = &cli.Command{
|
||||
|
||||
var actorWithdrawCmd = &cli.Command{
|
||||
Name: "withdraw",
|
||||
Usage: "withdraw available balance",
|
||||
Usage: "withdraw available balance to beneficiary",
|
||||
ArgsUsage: "[amount (FIL)]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
@ -240,6 +241,10 @@ var actorWithdrawCmd = &cli.Command{
|
||||
Usage: "number of block confirmations to wait for",
|
||||
Value: int(build.MessageConfidence),
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "beneficiary",
|
||||
Usage: "send withdraw message from the beneficiary address",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
amount := abi.NewTokenAmount(0)
|
||||
@ -267,7 +272,12 @@ var actorWithdrawCmd = &cli.Command{
|
||||
|
||||
ctx := lcli.ReqContext(cctx)
|
||||
|
||||
res, err := nodeApi.ActorWithdrawBalance(ctx, amount)
|
||||
var res cid.Cid
|
||||
if cctx.IsSet("beneficiary") {
|
||||
res, err = nodeApi.BeneficiaryWithdrawBalance(ctx, amount)
|
||||
} else {
|
||||
res, err = nodeApi.ActorWithdrawBalance(ctx, amount)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ var actorCmd = &cli.Command{
|
||||
|
||||
var actorWithdrawCmd = &cli.Command{
|
||||
Name: "withdraw",
|
||||
Usage: "withdraw available balance",
|
||||
Usage: "withdraw available balance to beneficiary",
|
||||
ArgsUsage: "[amount (FIL)]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
@ -50,6 +50,10 @@ var actorWithdrawCmd = &cli.Command{
|
||||
Usage: "number of block confirmations to wait for",
|
||||
Value: int(build.MessageConfidence),
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "beneficiary",
|
||||
Usage: "send withdraw message from the beneficiary address",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
var maddr address.Address
|
||||
@ -113,9 +117,16 @@ var actorWithdrawCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
var sender address.Address
|
||||
if cctx.IsSet("beneficiary") {
|
||||
sender = mi.Beneficiary
|
||||
} else {
|
||||
sender = mi.Owner
|
||||
}
|
||||
|
||||
smsg, err := nodeAPI.MpoolPushMessage(ctx, &types.Message{
|
||||
To: maddr,
|
||||
From: mi.Owner,
|
||||
From: sender,
|
||||
Value: types.NewInt(0),
|
||||
Method: builtin.MethodsMiner.WithdrawBalance,
|
||||
Params: params,
|
||||
|
@ -13,6 +13,8 @@
|
||||
* [Auth](#Auth)
|
||||
* [AuthNew](#AuthNew)
|
||||
* [AuthVerify](#AuthVerify)
|
||||
* [Beneficiary](#Beneficiary)
|
||||
* [BeneficiaryWithdrawBalance](#BeneficiaryWithdrawBalance)
|
||||
* [Check](#Check)
|
||||
* [CheckProvable](#CheckProvable)
|
||||
* [Compute](#Compute)
|
||||
@ -364,6 +366,31 @@ Response:
|
||||
]
|
||||
```
|
||||
|
||||
## Beneficiary
|
||||
|
||||
|
||||
### BeneficiaryWithdrawBalance
|
||||
BeneficiaryWithdrawBalance allows the beneficiary of a miner to withdraw balance from miner actor
|
||||
Specify amount as "0" to withdraw full balance. This method returns a message CID
|
||||
and does not wait for message execution
|
||||
|
||||
|
||||
Perms: admin
|
||||
|
||||
Inputs:
|
||||
```json
|
||||
[
|
||||
"0"
|
||||
]
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
|
||||
}
|
||||
```
|
||||
|
||||
## Check
|
||||
|
||||
|
||||
|
@ -5811,7 +5811,20 @@ Response:
|
||||
"WindowPoStProofType": 8,
|
||||
"SectorSize": 34359738368,
|
||||
"WindowPoStPartitionSectors": 42,
|
||||
"ConsensusFaultElapsed": 10101
|
||||
"ConsensusFaultElapsed": 10101,
|
||||
"Beneficiary": "f01234",
|
||||
"BeneficiaryTerm": {
|
||||
"Quota": "0",
|
||||
"UsedQuota": "0",
|
||||
"Expiration": 10101
|
||||
},
|
||||
"PendingBeneficiaryTerm": {
|
||||
"NewBeneficiary": "f01234",
|
||||
"NewQuota": "0",
|
||||
"NewExpiration": 10101,
|
||||
"ApprovedByBeneficiary": true,
|
||||
"ApprovedByNominee": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -6328,7 +6328,20 @@ Response:
|
||||
"WindowPoStProofType": 8,
|
||||
"SectorSize": 34359738368,
|
||||
"WindowPoStPartitionSectors": 42,
|
||||
"ConsensusFaultElapsed": 10101
|
||||
"ConsensusFaultElapsed": 10101,
|
||||
"Beneficiary": "f01234",
|
||||
"BeneficiaryTerm": {
|
||||
"Quota": "0",
|
||||
"UsedQuota": "0",
|
||||
"Expiration": 10101
|
||||
},
|
||||
"PendingBeneficiaryTerm": {
|
||||
"NewBeneficiary": "f01234",
|
||||
"NewQuota": "0",
|
||||
"NewExpiration": 10101,
|
||||
"ApprovedByBeneficiary": true,
|
||||
"ApprovedByNominee": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -232,7 +232,7 @@ USAGE:
|
||||
|
||||
COMMANDS:
|
||||
set-addresses, set-addrs set addresses that your miner can be publicly dialed on
|
||||
withdraw withdraw available balance
|
||||
withdraw withdraw available balance to beneficiary
|
||||
repay-debt pay down a miner's debt
|
||||
set-peer-id set the peer id of your miner
|
||||
set-owner Set owner address (this command should be invoked twice, first with the old owner as the senderAddress, and then with the new owner)
|
||||
@ -254,12 +254,13 @@ OPTIONS:
|
||||
### lotus-miner actor withdraw
|
||||
```
|
||||
NAME:
|
||||
lotus-miner actor withdraw - withdraw available balance
|
||||
lotus-miner actor withdraw - withdraw available balance to beneficiary
|
||||
|
||||
USAGE:
|
||||
lotus-miner actor withdraw [command options] [amount (FIL)]
|
||||
|
||||
OPTIONS:
|
||||
--beneficiary send withdraw message from the beneficiary address (default: false)
|
||||
--confidence value number of block confirmations to wait for (default: 5)
|
||||
|
||||
```
|
||||
|
@ -177,6 +177,9 @@ func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address,
|
||||
SectorSize: info.SectorSize,
|
||||
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
|
||||
ConsensusFaultElapsed: info.ConsensusFaultElapsed,
|
||||
Beneficiary: info.Beneficiary,
|
||||
BeneficiaryTerm: info.BeneficiaryTerm,
|
||||
PendingBeneficiaryTerm: info.PendingBeneficiaryTerm,
|
||||
}
|
||||
|
||||
if info.PendingWorkerKey != nil {
|
||||
|
@ -1349,6 +1349,14 @@ func (sm *StorageMinerAPI) RuntimeSubsystems(context.Context) (res api.MinerSubs
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) ActorWithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) {
|
||||
return sm.withdrawBalance(ctx, amount, true)
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) BeneficiaryWithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) {
|
||||
return sm.withdrawBalance(ctx, amount, false)
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) withdrawBalance(ctx context.Context, amount abi.TokenAmount, fromOwner bool) (cid.Cid, error) {
|
||||
available, err := sm.Full.StateMinerAvailableBalance(ctx, sm.Miner.Address(), types.EmptyTSK)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("Error getting miner balance: %w", err)
|
||||
@ -1374,9 +1382,16 @@ func (sm *StorageMinerAPI) ActorWithdrawBalance(ctx context.Context, amount abi.
|
||||
return cid.Undef, xerrors.Errorf("Error getting miner's owner address: %w", err)
|
||||
}
|
||||
|
||||
var sender address.Address
|
||||
if fromOwner {
|
||||
sender = mi.Owner
|
||||
} else {
|
||||
sender = mi.Beneficiary
|
||||
}
|
||||
|
||||
smsg, err := sm.Full.MpoolPushMessage(ctx, &types.Message{
|
||||
To: sm.Miner.Address(),
|
||||
From: mi.Owner,
|
||||
From: sender,
|
||||
Value: types.NewInt(0),
|
||||
Method: builtintypes.MethodsMiner.WithdrawBalance,
|
||||
Params: params,
|
||||
|
Loading…
Reference in New Issue
Block a user