lotus/markets/utils/converters.go
hannahhoward 691bd9f442 feat(markets): complete markets conversion
complete markets conversion to using chain/actors types, also replacing DealProposal/DealState
interfaces with structs
2020-09-17 00:43:14 -07:00

39 lines
1.1 KiB
Go

package utils
import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/api"
peer "github.com/libp2p/go-libp2p-core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
)
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)
}
return storagemarket.StorageProviderInfo{
Address: address,
Worker: miner,
SectorSize: uint64(sectorSize),
PeerID: peer,
Addrs: multiaddrs,
}
}
func ToSharedBalance(bal api.MarketBalance) storagemarket.Balance {
return storagemarket.Balance{
Locked: bal.Locked,
Available: big.Sub(bal.Escrow, bal.Locked),
}
}