Class: NwcRuby::NIP47::Notification
- Inherits:
-
Object
- Object
- NwcRuby::NIP47::Notification
- Defined in:
- lib/nwc_ruby/nip47/notification.rb
Overview
Parses kind 23196 (NIP-04) or 23197 (NIP-44 v2) notification events.
Inner payload shape:
{ "notification_type": "payment_received"|"payment_sent",
"notification": { ...transaction fields... } }
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #amount_msats ⇒ Object
-
#initialize(type:, data:, event:) ⇒ Notification
constructor
A new instance of Notification.
- #payment_hash ⇒ Object
- #payment_received? ⇒ Boolean
- #payment_sent? ⇒ Boolean
Constructor Details
#initialize(type:, data:, event:) ⇒ Notification
Returns a new instance of Notification.
13 14 15 16 17 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 13 def initialize(type:, data:, event:) @type = type @data = data @event = event end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 11 def data @data end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
11 12 13 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 11 def event @event end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 11 def type @type end |
Class Method Details
.parse(event, client_privkey, wallet_pubkey) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 35 def self.parse(event, client_privkey, wallet_pubkey) plaintext = case event.kind when Methods::KIND_NOTIFICATION_NIP44 NIP44::Cipher.decrypt(event.content, client_privkey, wallet_pubkey) when Methods::KIND_NOTIFICATION_NIP04 NIP04::Cipher.decrypt(event.content, client_privkey, wallet_pubkey) else raise ArgumentError, "not a notification kind: #{event.kind}" end data = JSON.parse(plaintext) new(type: data['notification_type'], data: data['notification'] || {}, event: event) end |
Instance Method Details
#amount_msats ⇒ Object
23 24 25 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 23 def amount_msats @data['amount'] end |
#payment_hash ⇒ Object
19 20 21 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 19 def payment_hash @data['payment_hash'] end |
#payment_received? ⇒ Boolean
27 28 29 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 27 def payment_received? @type == 'payment_received' end |
#payment_sent? ⇒ Boolean
31 32 33 |
# File 'lib/nwc_ruby/nip47/notification.rb', line 31 def payment_sent? @type == 'payment_sent' end |