/
offer.go
42 lines (36 loc) · 900 Bytes
/
offer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package types
import sdk "github.com/cosmos/cosmos-sdk/types"
func (o Offer) ToStoreRecord() OfferStoreRecord {
buyer, err := sdk.AccAddressFromBech32(o.Buyer)
if err != nil {
panic(err)
}
return OfferStoreRecord{
ClassId: o.ClassId,
NftId: o.NftId,
Buyer: buyer,
Price: o.Price,
Expiration: o.Expiration,
}
}
func (r OfferStoreRecord) ToPublicRecord() Offer {
return Offer{
ClassId: r.ClassId,
NftId: r.NftId,
Buyer: r.Buyer.String(),
Price: r.Price,
Expiration: r.Expiration,
}
}
func MapOffersToStoreRecords(offers []Offer) (records []OfferStoreRecord) {
for _, offer := range offers {
records = append(records, offer.ToStoreRecord())
}
return
}
func MapOffersToPublicRecords(records []OfferStoreRecord) (offers []Offer) {
for _, record := range records {
offers = append(offers, record.ToPublicRecord())
}
return
}