Merge pull request #3590 from filecoin-project/asr/multisig

Multisig API additions
This commit is contained in:
Łukasz Magiera
2020-09-10 17:04:48 +02:00
committed by GitHub
6 changed files with 534 additions and 8 deletions
+39
View File
@@ -130,6 +130,33 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr
return smsg.Cid(), nil
}
func (a *MsigAPI) MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (cid.Cid, error) {
enc, actErr := serializeAddParams(newAdd, inc)
if actErr != nil {
return cid.Undef, actErr
}
return a.MsigPropose(ctx, msig, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.AddSigner), enc)
}
func (a *MsigAPI) MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (cid.Cid, error) {
enc, actErr := serializeAddParams(newAdd, inc)
if actErr != nil {
return cid.Undef, actErr
}
return a.MsigApprove(ctx, msig, txID, proposer, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.AddSigner), enc)
}
func (a *MsigAPI) MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (cid.Cid, error) {
enc, actErr := serializeAddParams(newAdd, inc)
if actErr != nil {
return cid.Undef, actErr
}
return a.MsigCancel(ctx, msig, txID, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.AddSigner), enc)
}
func (a *MsigAPI) MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) {
enc, actErr := serializeSwapParams(oldAdd, newAdd)
if actErr != nil {
@@ -244,6 +271,18 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro
return smsg.Cid(), nil
}
func serializeAddParams(new address.Address, inc bool) ([]byte, error) {
enc, actErr := actors.SerializeParams(&samsig.AddSignerParams{
Signer: new,
Increase: inc,
})
if actErr != nil {
return nil, actErr
}
return enc, nil
}
func serializeSwapParams(old address.Address, new address.Address) ([]byte, error) {
enc, actErr := actors.SerializeParams(&samsig.SwapSignerParams{
From: old,
+42
View File
@@ -886,6 +886,48 @@ func (a *StateAPI) MsigGetAvailableBalance(ctx context.Context, addr address.Add
return types.BigSub(act.Balance, minBalance), 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 {
return types.EmptyInt, xerrors.Errorf("loading start tipset %s: %w", start, err)
}
endTs, err := a.Chain.GetTipSetFromKey(end)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading end tipset %s: %w", end, err)
}
if startTs.Height() > endTs.Height() {
return types.EmptyInt, xerrors.Errorf("start tipset %d is after end tipset %d", startTs.Height(), endTs.Height())
} else if startTs.Height() == endTs.Height() {
return big.Zero(), nil
}
var mst samsig.State
act, err := a.StateManager.LoadActorState(ctx, addr, &mst, endTs)
if err != nil {
return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state at end epoch: %w", err)
}
if act.Code != builtin.MultisigActorCodeID {
return types.EmptyInt, fmt.Errorf("given actor was not a multisig")
}
if mst.UnlockDuration == 0 ||
mst.InitialBalance.IsZero() ||
mst.StartEpoch+mst.UnlockDuration <= startTs.Height() ||
mst.StartEpoch >= endTs.Height() {
return big.Zero(), nil
}
startLk := mst.InitialBalance
if startTs.Height() > mst.StartEpoch {
startLk = mst.AmountLocked(startTs.Height() - mst.StartEpoch)
}
return big.Sub(startLk, mst.AmountLocked(endTs.Height()-mst.StartEpoch)), nil
}
var initialPledgeNum = types.NewInt(110)
var initialPledgeDen = types.NewInt(100)