lotus/provider/address.go

65 lines
1.8 KiB
Go
Raw Normal View History

package provider
import (
2023-10-25 19:13:56 +00:00
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
2023-10-25 19:13:56 +00:00
2024-01-20 00:48:29 +00:00
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/storage/ctladdr"
)
2024-01-20 00:48:29 +00:00
func AddressSelector(addrConf []config.LotusProviderAddresses) func() (*ctladdr.MultiAddressSelector, error) {
return func() (*ctladdr.MultiAddressSelector, error) {
as := &ctladdr.MultiAddressSelector{
MinerMap: make(map[address.Address]api.AddressConfig),
}
if addrConf == nil {
return as, nil
}
2024-01-20 00:48:29 +00:00
for _, addrConf := range addrConf {
for _, minerID := range addrConf.MinerAddresses {
tmp := api.AddressConfig{
DisableOwnerFallback: addrConf.DisableOwnerFallback,
DisableWorkerFallback: addrConf.DisableWorkerFallback,
}
2024-01-20 00:48:29 +00:00
for _, s := range addrConf.PreCommitControl {
addr, err := address.NewFromString(s)
if err != nil {
return nil, xerrors.Errorf("parsing precommit control address: %w", err)
}
2024-01-20 00:48:29 +00:00
tmp.PreCommitControl = append(tmp.PreCommitControl, addr)
}
2024-01-20 00:48:29 +00:00
for _, s := range addrConf.CommitControl {
addr, err := address.NewFromString(s)
if err != nil {
return nil, xerrors.Errorf("parsing commit control address: %w", err)
}
2024-01-20 00:48:29 +00:00
tmp.CommitControl = append(tmp.CommitControl, addr)
}
2024-01-20 00:48:29 +00:00
for _, s := range addrConf.TerminateControl {
addr, err := address.NewFromString(s)
if err != nil {
return nil, xerrors.Errorf("parsing terminate control address: %w", err)
}
2024-01-20 00:48:29 +00:00
tmp.TerminateControl = append(tmp.TerminateControl, addr)
}
a, err := address.NewFromString(minerID)
if err != nil {
return nil, xerrors.Errorf("parsing miner address %s: %w", minerID, err)
}
as.MinerMap[a] = tmp
}
}
return as, nil
}
}