Files
sendico/api/pkg/model/cryptoaddress.go
2025-12-12 11:05:12 +01:00

29 lines
779 B
Go

package model
import (
"fmt"
"github.com/tech/sendico/pkg/merrors"
"go.mongodb.org/mongo-driver/bson"
)
type CryptoAddressPaymentData struct {
Currency Currency `bson:"currency" json:"currency"`
Address string `bson:"address" json:"address"`
Network string `bson:"network" json:"network"`
DestinationTag *string `bson:"destinationTag,omitempty" json:"destinationTag,omitempty"`
}
func (m *PaymentMethod) AsCryptoAddress() (*CryptoAddressPaymentData, error) {
if m.Type != PaymentTypeCryptoAddress {
return nil, merrors.InvalidArgument(fmt.Sprintf("payment method type is %s, not cryptoAddress", m.Type), "type")
}
var d CryptoAddressPaymentData
if err := bson.Unmarshal(m.Data, &d); err != nil {
return nil, err
}
return &d, nil
}