2024-03-15 21:38:13 +00:00
|
|
|
package curio
|
2023-10-25 12:23:25 +00:00
|
|
|
|
|
|
|
import (
|
2023-10-25 19:13:56 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2023-10-25 12:23:25 +00:00
|
|
|
"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"
|
2024-03-15 21:38:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/curiosrc/multictladdr"
|
2023-10-25 12:23:25 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/config"
|
|
|
|
)
|
|
|
|
|
2024-03-15 21:38:13 +00:00
|
|
|
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),
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
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,
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
|
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)
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
|
2024-01-20 00:48:29 +00:00
|
|
|
tmp.PreCommitControl = append(tmp.PreCommitControl, addr)
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
|
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)
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
|
2024-01-20 00:48:29 +00:00
|
|
|
tmp.CommitControl = append(tmp.CommitControl, addr)
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
|
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)
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
|
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
|
|
|
|
}
|
2023-10-25 12:23:25 +00:00
|
|
|
}
|
|
|
|
return as, nil
|
|
|
|
}
|
|
|
|
}
|