place the remainder of unallocated funds in a 'remainder' account

This commit is contained in:
whyrusleeping 2020-08-17 23:38:58 -07:00
parent 8cae101c04
commit 64e18131c1
3 changed files with 26 additions and 2 deletions

View File

@ -258,11 +258,33 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
Balance: types.NewInt(0),
Head: verifierState,
})
if err != nil {
return nil, nil, xerrors.Errorf("setting account from actmap: %w", err)
}
totalFilAllocated := big.Zero()
err = state.ForEach(func(addr address.Address, act *types.Actor) error {
totalFilAllocated = big.Add(totalFilAllocated, act.Balance)
return nil
})
if err != nil {
return nil, nil, xerrors.Errorf("summing account balances in state tree: %w", err)
}
totalFil := big.Mul(big.NewInt(int64(build.FilBase)), big.NewInt(int64(build.FilecoinPrecision)))
remainingFil := big.Sub(totalFil, totalFilAllocated)
template.RemainderAccount.Balance = remainingFil
remAccKey, err := address.NewIDAddress(90)
if err != nil {
return nil, nil, err
}
if err := createAccount(ctx, bs, cst, state, remAccKey, template.RemainderAccount); err != nil {
return nil, nil, err
}
return state, keyIDs, nil
}

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/builtin"

View File

@ -79,5 +79,6 @@ type Template struct {
NetworkName string
Timestamp uint64 `json:",omitempty"`
VerifregRootKey Actor
VerifregRootKey Actor
RemainderAccount Actor
}