lotus/curiosrc/address.go

65 lines
1.8 KiB
Go
Raw Permalink Normal View History

package curio
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/curiosrc/multictladdr"
"github.com/filecoin-project/lotus/node/config"
)
func AddressSelector(addrConf []config.CurioAddresses) func() (*multictladdr.MultiAddressSelector, error) {
2024-02-13 01:03:45 +00:00
return func() (*multictladdr.MultiAddressSelector, error) {
as := &multictladdr.MultiAddressSelector{
2024-01-20 00:48:29 +00:00
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
}
}