class Universa::StoredContractBase

under construction, pls don't use.

this is a base class for a contract stored in some contract chain. The implementation must inherit and implement its {#load} and {#save} methods at least. To do it, inherit and implement {ChainStore} to work with it.

Notable features:

Attributes

chain_store[R]

{ChainStore} instance to which it is connected

contract[R]

{Contract} instance stored in it. Can be lazy-loaded

hash_id[R]

{HashId} of the {#contract}

Public Class Methods

new(chain_store) click to toggle source

Construct implementation connected to a given store @param [ChainStore] chain_store descendant class

# File lib/universa/stored_contract.rb, line 35
def initialize(chain_store)
  @chain_store = chain_store
  @chain_store.is_a?(ChainStore) or raise ArgumentError, "ChainStore instance required"
  @chain_store = chain_store
end

Public Instance Methods

contract=(new_contract) click to toggle source

Assign contract to the instance. @param [Contracy] new_contract to store

# File lib/universa/stored_contract.rb, line 65
def contract=(new_contract)
  raise IllegalStateError, "contract can't be reassigned" if has_contract?
  @contract = new_contract
  @hash_id = @contract.hash_id
  @origin = @parent = nil
end
has_contract?() click to toggle source

For implementation logic, in particular, to make lazy loads. @return true if the stored contract is loaded into this instance

# File lib/universa/stored_contract.rb, line 43
def has_contract?
  !@contract.nil?
end
load(hash_id) click to toggle source

override it to load the contract from the connected contract chain.

# File lib/universa/stored_contract.rb, line 59
def load hash_id
  raise NotFoundError
end
origin() click to toggle source

@return [HashId] {#contract}.origin. See {Contract#origin}

# File lib/universa/stored_contract.rb, line 24
def origin
  @origin ||= @contract.origin
end
packed_contract() click to toggle source

Shortcut for `contract.packed`. See {Contract#packed} @return [String] binary string with contained contract packed transaction.

# File lib/universa/stored_contract.rb, line 49
def packed_contract
  @contract.packed
end
packed_contract=(new_packed_contract) click to toggle source

Convenience method. Unoacks and stores the contract.

# File lib/universa/stored_contract.rb, line 73
def packed_contract=(new_packed_contract)
  self.contract = Contract.from_packed(new_packed_contract)
end
parent() click to toggle source

@return [HashId] {#contract}.origin. See {Contract#parent}

# File lib/universa/stored_contract.rb, line 29
def parent
  @parent ||= @contract.parent
end
save() click to toggle source

override it to save the contract in the connected contract chain.

# File lib/universa/stored_contract.rb, line 54
def save
  raise NotFoundError
end