Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit empty properties when serializing to json #32

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions uma/protocol/lnurl_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ type LnurlpResponse struct {
MaxSendable int64 `json:"maxSendable"`
EncodedMetadata string `json:"metadata"`
// Currencies is the list of currencies that the receiver can quote. See LUD-21. Required for UMA.
Currencies *[]Currency `json:"currencies"`
Currencies *[]Currency `json:"currencies,omitempty"`
// RequiredPayerData the data about the payer that the sending VASP must provide in order to send a payment.
RequiredPayerData *CounterPartyDataOptions `json:"payerData"`
RequiredPayerData *CounterPartyDataOptions `json:"payerData,omitempty"`
// Compliance is compliance-related data from the receiving VASP for UMA.
Compliance *LnurlComplianceResponse `json:"compliance"`
Compliance *LnurlComplianceResponse `json:"compliance,omitempty"`
// UmaVersion is the version of the UMA protocol that VASP2 has chosen for this transaction based on its own support
// and VASP1's specified preference in the LnurlpRequest. For the version negotiation flow, see
// https://static.swimlanes.io/87f5d188e080cb8e0494e46f80f2ae74.png
UmaVersion *string `json:"umaVersion"`
UmaVersion *string `json:"umaVersion,omitempty"`
// CommentCharsAllowed is the number of characters that the sender can include in the comment field of the pay request.
CommentCharsAllowed *int `json:"commentAllowed"`
CommentCharsAllowed *int `json:"commentAllowed,omitempty"`
// NostrPubkey is an optional nostr pubkey used for nostr zaps (NIP-57). If set, it should be a valid BIP-340 public
// key in hex format.
NostrPubkey *string `json:"nostrPubkey"`
NostrPubkey *string `json:"nostrPubkey,omitempty"`
// AllowsNostr should be set to true if the receiving VASP allows nostr zaps (NIP-57).
AllowsNostr *bool `json:"allowsNostr"`
AllowsNostr *bool `json:"allowsNostr,omitempty"`
}

// LnurlComplianceResponse is the `compliance` field of the LnurlpResponse.
Expand Down Expand Up @@ -83,12 +83,12 @@ type UmaLnurlpResponse struct {
// https://static.swimlanes.io/87f5d188e080cb8e0494e46f80f2ae74.png
UmaVersion string `json:"umaVersion"`
// CommentCharsAllowed is the number of characters that the sender can include in the comment field of the pay request.
CommentCharsAllowed *int `json:"commentAllowed"`
CommentCharsAllowed *int `json:"commentAllowed,omitempty"`
// NostrPubkey is an optional nostr pubkey used for nostr zaps (NIP-57). If set, it should be a valid BIP-340 public
// key in hex format.
NostrPubkey *string `json:"nostrPubkey"`
NostrPubkey *string `json:"nostrPubkey,omitempty"`
// AllowsNostr should be set to true if the receiving VASP allows nostr zaps (NIP-57).
AllowsNostr *bool `json:"allowsNostr"`
AllowsNostr *bool `json:"allowsNostr,omitempty"`
}

func (r *UmaLnurlpResponse) SignablePayload() []byte {
Expand Down
26 changes: 13 additions & 13 deletions uma/protocol/pay_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,42 @@ type PayRequest struct {
// *should not* pass the sending currency code here, as it is not relevant to the receiver.
// Rather, by specifying an invoice amount in msats, the sending VASP can ensure that their
// user will be sending a fixed amount, regardless of the exchange rate on the receiving side.
SendingAmountCurrencyCode *string `json:"sendingAmountCurrencyCode"`
SendingAmountCurrencyCode *string `json:"sendingAmountCurrencyCode,omitempty"`
// ReceivingCurrencyCode is the ISO 3-digit currency code that the receiver will receive for this payment. Defaults
// to amount being specified in msats if this is not provided.
ReceivingCurrencyCode *string `json:"convert"`
ReceivingCurrencyCode *string `json:"convert,omitempty"`
// Amount is the amount that the receiver will receive for this payment in the smallest unit of the specified
// currency (i.e. cents for USD) if `SendingAmountCurrencyCode` is not `nil`. Otherwise, it is the amount in
// millisatoshis.
Amount int64 `json:"amount"`
// PayerData is the data that the sender will send to the receiver to identify themselves. Required for UMA, as is
// the `compliance` field in the `payerData` object.
PayerData *PayerData `json:"payerData"`
PayerData *PayerData `json:"payerData,omitempty"`
// RequestedPayeeData is the data that the sender is requesting about the payee.
RequestedPayeeData *CounterPartyDataOptions `json:"payeeData"`
RequestedPayeeData *CounterPartyDataOptions `json:"payeeData,omitempty"`
// Comment is a comment that the sender would like to include with the payment. This can only be included
// if the receiver included the `commentAllowed` field in the lnurlp response. The length of
// the comment must be less than or equal to the value of `commentAllowed`.
Comment *string `json:"comment"`
Comment *string `json:"comment,omitempty"`
// UmaMajorVersion is the major version of the UMA protocol that the VASP supports for this currency. This is used
// for serialization, but is not serialized itself.
UmaMajorVersion int `json:"-"`
}

type v0PayRequest struct {
ReceivingCurrencyCode *string `json:"currency"`
ReceivingCurrencyCode *string `json:"currency,omitempty"`
Amount int64 `json:"amount"`
PayerData *PayerData `json:"payerData"`
RequestedPayeeData *CounterPartyDataOptions `json:"payeeData"`
Comment *string `json:"comment"`
PayerData *PayerData `json:"payerData,omitempty"`
RequestedPayeeData *CounterPartyDataOptions `json:"payeeData,omitempty"`
Comment *string `json:"comment,omitempty"`
}

type v1PayRequest struct {
ReceivingCurrencyCode *string `json:"convert"`
ReceivingCurrencyCode *string `json:"convert,omitempty"`
Amount string `json:"amount"`
PayerData *PayerData `json:"payerData"`
RequestedPayeeData *CounterPartyDataOptions `json:"payeeData"`
Comment *string `json:"comment"`
PayerData *PayerData `json:"payerData,omitempty"`
RequestedPayeeData *CounterPartyDataOptions `json:"payeeData,omitempty"`
Comment *string `json:"comment,omitempty"`
}

// IsUmaRequest returns true if the request is a valid UMA request, otherwise, if any fields are missing, it returns false.
Expand Down
10 changes: 5 additions & 5 deletions uma/protocol/payee_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ func (p *PayeeData) Compliance() (*CompliancePayeeData, error) {

type CompliancePayeeData struct {
// NodePubKey is the public key of the receiver's node if known.
NodePubKey *string `json:"nodePubKey"`
NodePubKey *string `json:"nodePubKey,omitempty"`
// Utxos is a list of UTXOs of channels over which the receiver will likely receive the payment.
Utxos []string `json:"utxos"`
// UtxoCallback is the URL that the sender VASP will call to send UTXOs of the channel that the sender used to send the payment once it completes.
UtxoCallback *string `json:"utxoCallback"`
UtxoCallback *string `json:"utxoCallback,omitempty"`
// Signature is the base64-encoded signature of sha256(SenderAddress|ReceiverAddress|Nonce|Timestamp).
// Note: This field is optional for UMA v0.X backwards-compatibility. It is required for UMA v1.X.
Signature *string `json:"signature"`
Signature *string `json:"signature,omitempty"`
// SignatureNonce is a random string that is used to prevent replay attacks.
// Note: This field is optional for UMA v0.X backwards-compatibility. It is required for UMA v1.X.
SignatureNonce *string `json:"signatureNonce"`
SignatureNonce *string `json:"signatureNonce,omitempty"`
// SignatureTimestamp is the unix timestamp (in seconds since epoch) of when the request was sent. Used in the signature.
// Note: This field is optional for UMA v0.X backwards-compatibility. It is required for UMA v1.X.
SignatureTimestamp *int64 `json:"signatureTimestamp"`
SignatureTimestamp *int64 `json:"signatureTimestamp,omitempty"`
}

func (c *CompliancePayeeData) AsMap() (map[string]interface{}, error) {
Expand Down
8 changes: 4 additions & 4 deletions uma/protocol/payer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ func (t *TravelRuleFormat) UnmarshalJSON(data []byte) error {

type CompliancePayerData struct {
// Utxos is the list of UTXOs of the sender's channels that might be used to fund the payment.
Utxos *[]string `json:"utxos"`
Utxos *[]string `json:"utxos,omitempty"`
// NodePubKey is the public key of the sender's node if known.
NodePubKey *string `json:"nodePubKey"`
NodePubKey *string `json:"nodePubKey,omitempty"`
// KycStatus indicates whether VASP1 has KYC information about the sender.
KycStatus KycStatus `json:"kycStatus"`
// EncryptedTravelRuleInfo is the travel rule information of the sender. This is encrypted with the receiver's public encryption key.
EncryptedTravelRuleInfo *string `json:"encryptedTravelRuleInfo"`
EncryptedTravelRuleInfo *string `json:"encryptedTravelRuleInfo,omitempty"`
// TravelRuleFormat is an optional standardized format of the travel rule information (e.g. IVMS). Null indicates raw json or a custom format.
TravelRuleFormat *TravelRuleFormat `json:"travelRuleFormat"`
TravelRuleFormat *TravelRuleFormat `json:"travelRuleFormat,omitempty"`
// Signature is the base64-encoded signature of sha256(ReceiverAddress|Nonce|Timestamp).
Signature string `json:"signature"`
SignatureNonce string `json:"signatureNonce"`
Expand Down
28 changes: 14 additions & 14 deletions uma/protocol/payreq_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ type PayReqResponse struct {
Routes []Route `json:"routes"`
// PaymentInfo is information about the payment that the receiver will receive. Includes Final currency-related
// information for the payment. Required for UMA.
PaymentInfo *PayReqResponsePaymentInfo `json:"converted"`
PaymentInfo *PayReqResponsePaymentInfo `json:"converted,omitempty"`
// PayeeData The data about the receiver that the sending VASP requested in the payreq request.
// Required for UMA.
PayeeData *PayeeData `json:"payeeData"`
PayeeData *PayeeData `json:"payeeData,omitempty"`
// Disposable This field may be used by a WALLET to decide whether the initial LNURL link will be stored locally
// for later reuse or erased. If disposable is null, it should be interpreted as true, so if SERVICE intends its
// LNURL links to be stored it must return `disposable: false`. UMA should never return `disposable: false` due to
// signature nonce checks, etc. See LUD-11.
Disposable *bool `json:"disposable"`
Disposable *bool `json:"disposable,omitempty"`
// SuccessAction defines a struct which can be stored and shown to the user on payment success. See LUD-09.
SuccessAction *map[string]string `json:"successAction"`
SuccessAction *map[string]string `json:"successAction,omitempty"`
// UmaMajorVersion is the major version of the UMA protocol that the receiver is using. Only used
// for serialization and deserialization. Not included in the JSON response.
UmaMajorVersion int `json:"umaMajorVersion"`
Expand Down Expand Up @@ -53,7 +53,7 @@ type Route struct {
type PayReqResponsePaymentInfo struct {
// Amount is the amount that the receiver will receive in the receiving currency not including fees. The amount is
// specified in the smallest unit of the currency (eg. cents for USD).
Amount *int64 `json:"amount"`
Amount *int64 `json:"amount,omitempty"`
// CurrencyCode is the currency code that the receiver will receive for this payment.
CurrencyCode string `json:"currencyCode"`
// Multiplier is the conversion rate. It is the number of millisatoshis that the receiver will receive for 1 unit of
Expand Down Expand Up @@ -81,20 +81,20 @@ type v0PayReqResponsePaymentInfo struct {
type v0PayReqResponse struct {
EncodedInvoice string `json:"pr"`
Routes []Route `json:"routes"`
PaymentInfo *v0PayReqResponsePaymentInfo `json:"paymentInfo"`
PayeeData *PayeeData `json:"payeeData"`
Disposable *bool `json:"disposable"`
SuccessAction *map[string]string `json:"successAction"`
Compliance *CompliancePayeeData `json:"compliance"`
PaymentInfo *v0PayReqResponsePaymentInfo `json:"paymentInfo,omitempty"`
PayeeData *PayeeData `json:"payeeData,omitempty"`
Disposable *bool `json:"disposable,omitempty"`
SuccessAction *map[string]string `json:"successAction,omitempty"`
Compliance *CompliancePayeeData `json:"compliance,omitempty"`
}

type v1PayReqResponse struct {
EncodedInvoice string `json:"pr"`
Routes []Route `json:"routes"`
PaymentInfo *PayReqResponsePaymentInfo `json:"converted"`
PayeeData *PayeeData `json:"payeeData"`
Disposable *bool `json:"disposable"`
SuccessAction *map[string]string `json:"successAction"`
PaymentInfo *PayReqResponsePaymentInfo `json:"converted,omitempty"`
PayeeData *PayeeData `json:"payeeData,omitempty"`
Disposable *bool `json:"disposable,omitempty"`
SuccessAction *map[string]string `json:"successAction,omitempty"`
}

func (p *PayReqResponse) asV0() (*v0PayReqResponse, error) {
Expand Down
8 changes: 4 additions & 4 deletions uma/protocol/post_transaction_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ type PostTransactionCallback struct {
Utxos []UtxoWithAmount `json:"utxos"`
// VaspDomain is the domain of the VASP that is sending the callback.
// It will be used by the VASP to fetch the public keys of its counterparty.
VaspDomain *string `json:"vaspDomain"`
VaspDomain *string `json:"vaspDomain,omitempty"`
// Signature is the base64-encoded signature of sha256(Nonce|Timestamp).
Signature *string `json:"signature"`
Signature *string `json:"signature,omitempty"`
// Nonce is a random string that is used to prevent replay attacks.
Nonce *string `json:"signatureNonce"`
Nonce *string `json:"signatureNonce,omitempty"`
// Timestamp is the unix timestamp of when the request was sent. Used in the signature.
Timestamp *int64 `json:"signatureTimestamp"`
Timestamp *int64 `json:"signatureTimestamp,omitempty"`
}

// UtxoWithAmount is a pair of utxo and amount transferred over that corresponding channel.
Expand Down
10 changes: 5 additions & 5 deletions uma/protocol/pub_key_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (r *PubKeyResponse) UnmarshalJSON(data []byte) error {
}

type pubKeyResponseJson struct {
SigningCertChainHexDer *[]string `json:"signingCertChain"`
EncryptionCertChainHexDer *[]string `json:"encryptionCertChain"`
SigningPubKeyHex *string `json:"signingPubKey"`
EncryptionPubKeyHex *string `json:"encryptionPubKey"`
ExpirationTimestamp *int64 `json:"expirationTimestamp"`
SigningCertChainHexDer *[]string `json:"signingCertChain,omitempty"`
EncryptionCertChainHexDer *[]string `json:"encryptionCertChain,omitempty"`
SigningPubKeyHex *string `json:"signingPubKey,omitempty"`
EncryptionPubKeyHex *string `json:"encryptionPubKey,omitempty"`
ExpirationTimestamp *int64 `json:"expirationTimestamp,omitempty"`
}
Loading