Class: Bitcoin::Namecoin::Storage::Models::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/namecoin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, data) ⇒ Name

Returns a new instance of Name.



236
237
238
239
240
241
242
# File 'lib/bitcoin/namecoin.rb', line 236

def initialize store, data
  @store = store
  @txout_id = data[:txout_id]
  @hash = data[:hash]
  @name = data[:name]
  @value = data[:value]
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



234
235
236
# File 'lib/bitcoin/namecoin.rb', line 234

def hash
  @hash
end

#nameObject (readonly)

Returns the value of attribute name.



234
235
236
# File 'lib/bitcoin/namecoin.rb', line 234

def name
  @name
end

#storeObject (readonly)

Returns the value of attribute store.



234
235
236
# File 'lib/bitcoin/namecoin.rb', line 234

def store
  @store
end

#txout_idObject (readonly)

Returns the value of attribute txout_id.



234
235
236
# File 'lib/bitcoin/namecoin.rb', line 234

def txout_id
  @txout_id
end

#valueObject (readonly)

Returns the value of attribute value.



234
235
236
# File 'lib/bitcoin/namecoin.rb', line 234

def value
  @value
end

Instance Method Details

#expires_inObject



264
265
266
# File 'lib/bitcoin/namecoin.rb', line 264

def expires_in
  Namecoin::EXPIRATION_DEPTH - (@store.get_depth - get_block.depth) rescue nil
end

#get_addressObject



252
253
254
# File 'lib/bitcoin/namecoin.rb', line 252

def get_address
  get_txout.get_address
end

#get_blockObject



260
261
262
# File 'lib/bitcoin/namecoin.rb', line 260

def get_block
  get_tx.get_block rescue nil
end

#get_txObject



256
257
258
# File 'lib/bitcoin/namecoin.rb', line 256

def get_tx
  get_txout.get_tx rescue nil
end

#get_txoutObject



244
245
246
247
248
249
250
# File 'lib/bitcoin/namecoin.rb', line 244

def get_txout
  if @txout_id.is_a?(Array)
    @store.get_tx(@txout_id[0]).out[@txout_id[1]]
  else
    @store.get_txout_by_id(@txout_id)
  end
end

#to_json(opts = {}) ⇒ Object



268
269
270
271
# File 'lib/bitcoin/namecoin.rb', line 268

def to_json(opts = {})
  JSON.pretty_generate({ name: @name, value: @value, txid: get_tx.hash,
                         address: get_address, expires_in: expires_in }, opts)
end