2020-01-10 18:21:46 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
2020-06-29 17:20:06 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2020-01-10 18:21:46 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-01-10 18:21:46 +00:00
|
|
|
)
|
|
|
|
|
2020-08-05 20:54:45 +00:00
|
|
|
func NewStorageProviderInfo(address address.Address, miner address.Address, sectorSize abi.SectorSize, peer peer.ID, addrs []abi.Multiaddrs) storagemarket.StorageProviderInfo {
|
|
|
|
multiaddrs := make([]multiaddr.Multiaddr, 0, len(addrs))
|
|
|
|
for _, a := range addrs {
|
|
|
|
maddr, err := multiaddr.NewMultiaddrBytes(a)
|
|
|
|
if err != nil {
|
|
|
|
return storagemarket.StorageProviderInfo{}
|
|
|
|
}
|
|
|
|
multiaddrs = append(multiaddrs, maddr)
|
|
|
|
}
|
2020-06-29 17:20:06 +00:00
|
|
|
|
2020-01-10 18:21:46 +00:00
|
|
|
return storagemarket.StorageProviderInfo{
|
|
|
|
Address: address,
|
|
|
|
Worker: miner,
|
2020-02-08 02:18:32 +00:00
|
|
|
SectorSize: uint64(sectorSize),
|
2020-01-10 18:21:46 +00:00
|
|
|
PeerID: peer,
|
2020-08-05 20:54:45 +00:00
|
|
|
Addrs: multiaddrs,
|
2020-01-10 18:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-20 08:37:10 +00:00
|
|
|
|
|
|
|
func ToSharedBalance(bal api.MarketBalance) storagemarket.Balance {
|
|
|
|
return storagemarket.Balance{
|
|
|
|
Locked: bal.Locked,
|
2020-02-23 15:50:36 +00:00
|
|
|
Available: big.Sub(bal.Escrow, bal.Locked),
|
2020-02-20 08:37:10 +00:00
|
|
|
}
|
|
|
|
}
|