Skip to content

Commit

Permalink
Add some new endpoints for querying Msig info
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Oct 8, 2020
1 parent d26ece1 commit 4ed3b60
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
15 changes: 15 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ type FullNode interface {

// MsigGetAvailableBalance returns the portion of a multisig's balance that can be withdrawn or spent
MsigGetAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
// MsigGetLockedBalance returns the locked balance of an msig at a vien epoch.
// The return may be greater than the multisig actor's actual balance.
MsigGetVestingSchedule(context.Context, address.Address, types.TipSetKey) (MsigVesting, error)
// MsigGetVested returns the amount of FIL that vested in a multisig in a certain period.
// It takes the following params: <multisig address>, <start epoch>, <end epoch>
MsigGetVested(context.Context, address.Address, types.TipSetKey, types.TipSetKey) (types.BigInt, error)
Expand Down Expand Up @@ -871,3 +874,15 @@ type Fault struct {
Miner address.Address
Epoch abi.ChainEpoch
}

var EmptyVesting = MsigVesting{
InitialBalance: types.EmptyInt,
StartEpoch: -1,
UnlockDuration: -1,
}

type MsigVesting struct {
InitialBalance abi.TokenAmount
StartEpoch abi.ChainEpoch
UnlockDuration abi.ChainEpoch
}
5 changes: 5 additions & 0 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ type FullNodeStruct struct {
StateNetworkVersion func(context.Context, types.TipSetKey) (stnetwork.Version, error) `perm:"read"`

MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
MsigGetVestingSchedule func(context.Context, address.Address, types.TipSetKey) (api.MsigVesting, error) `perm:"read"`
MsigGetVested func(context.Context, address.Address, types.TipSetKey, types.TipSetKey) (types.BigInt, error) `perm:"read"`
MsigCreate func(context.Context, uint64, []address.Address, abi.ChainEpoch, types.BigInt, address.Address, types.BigInt) (cid.Cid, error) `perm:"sign"`
MsigPropose func(context.Context, address.Address, address.Address, types.BigInt, address.Address, uint64, []byte) (cid.Cid, error) `perm:"sign"`
Expand Down Expand Up @@ -933,6 +934,10 @@ func (c *FullNodeStruct) MsigGetAvailableBalance(ctx context.Context, a address.
return c.Internal.MsigGetAvailableBalance(ctx, a, tsk)
}

func (c *FullNodeStruct) MsigGetVestingSchedule(ctx context.Context, a address.Address, tsk types.TipSetKey) (api.MsigVesting, error) {
return c.Internal.MsigGetVestingSchedule(ctx, a, tsk)
}

func (c *FullNodeStruct) MsigGetVested(ctx context.Context, a address.Address, sTsk types.TipSetKey, eTsk types.TipSetKey) (types.BigInt, error) {
return c.Internal.MsigGetVested(ctx, a, sTsk, eTsk)
}
Expand Down
57 changes: 57 additions & 0 deletions documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
* [MsigCancel](#MsigCancel)
* [MsigCreate](#MsigCreate)
* [MsigGetAvailableBalance](#MsigGetAvailableBalance)
* [MsigGetLockedBalance](#MsigGetLockedBalance)
* [MsigGetVested](#MsigGetVested)
* [MsigGetVestingSchedule](#MsigGetVestingSchedule)
* [MsigPropose](#MsigPropose)
* [MsigSwapApprove](#MsigSwapApprove)
* [MsigSwapCancel](#MsigSwapCancel)
Expand Down Expand Up @@ -2092,6 +2094,30 @@ Response:
MsigGetAvailableBalance returns the portion of a multisig's balance that can be withdrawn or spent


Perms: read

Inputs:
```json
[
"f01234",
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```

Response: `"0"`

### MsigGetLockedBalance
MsigGetLockedBalance returns the locked balance of an msig at a vien epoch.
The return may be greater than the multisig actor's actual balance.


Perms: read

Inputs:
Expand Down Expand Up @@ -2143,6 +2169,37 @@ Inputs:

Response: `"0"`

### MsigGetVestingSchedule
MsigGetLockedBalance returns the locked balance of an msig at a vien epoch.
The return may be greater than the multisig actor's actual balance.


Perms: read

Inputs:
```json
[
"f01234",
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```

Response:
```json
{
"InitialBalance": "0",
"StartEpoch": 10101,
"UnlockDuration": 10101
}
```

### MsigPropose
MsigPropose proposes a multisig message
It takes the following params: <multisig address>, <recipient address>, <value to transfer>,
Expand Down
38 changes: 38 additions & 0 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,44 @@ func (a *StateAPI) MsigGetAvailableBalance(ctx context.Context, addr address.Add
return types.BigSub(act.Balance, locked), nil
}

func (a *StateAPI) MsigGetVestingSchedule(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MsigVesting, error) {
ts, err := a.Chain.GetTipSetFromKey(tsk)
if err != nil {
return api.EmptyVesting, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}

act, err := a.StateManager.LoadActor(ctx, addr, ts)
if err != nil {
return api.EmptyVesting, xerrors.Errorf("failed to load multisig actor: %w", err)
}

msas, err := multisig.Load(a.Chain.Store(ctx), act)
if err != nil {
return api.EmptyVesting, xerrors.Errorf("failed to load multisig actor state: %w", err)
}

ib, err := msas.InitialBalance()
if err != nil {
return api.EmptyVesting, xerrors.Errorf("failed to load multisig initial balance: %w", err)
}

se, err := msas.StartEpoch()
if err != nil {
return api.EmptyVesting, xerrors.Errorf("failed to load multisig start epoch: %w", err)
}

ud, err := msas.UnlockDuration()
if err != nil {
return api.EmptyVesting, xerrors.Errorf("failed to load multisig unlock duration: %w", err)
}

return api.MsigVesting{
InitialBalance: ib,
StartEpoch: se,
UnlockDuration: ud,
}, nil
}

func (a *StateAPI) MsigGetVested(ctx context.Context, addr address.Address, start types.TipSetKey, end types.TipSetKey) (types.BigInt, error) {
startTs, err := a.Chain.GetTipSetFromKey(start)
if err != nil {
Expand Down

0 comments on commit 4ed3b60

Please sign in to comment.