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.



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

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.



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

def hash
  @hash
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#storeObject (readonly)

Returns the value of attribute store.



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

def store
  @store
end

#txout_idObject (readonly)

Returns the value of attribute txout_id.



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

def txout_id
  @txout_id
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#as_json(opts = {}) ⇒ Object



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

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

#expires_inObject



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

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

#get_addressObject



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

def get_address
  get_txout.get_address
end

#get_blockObject



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

def get_block
  get_tx.get_block rescue nil
end

#get_txObject



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

def get_tx
  get_txout.get_tx rescue nil
end

#get_txoutObject



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

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