class Bitcoin::Wallet::DB

Constants

KEY_PREFIX

Attributes

level_db[R]
master_key[RW]

Public Class Methods

new(path = " click to toggle source
# File lib/bitcoin/wallet/db.rb, line 16
def initialize(path = "#{Bitcoin.base_dir}/db/wallet")
  FileUtils.mkdir_p(path)
  @level_db = ::LevelDBNative::DB.new(path)
end

Public Instance Methods

accounts() click to toggle source

get accounts raw data.

# File lib/bitcoin/wallet/db.rb, line 27
def accounts
  from = KEY_PREFIX[:account] + '00000000'
  to = KEY_PREFIX[:account] + 'ffffffff'
  level_db.each(from: from, to: to).map { |k, v| v}
end
close() click to toggle source

close database

# File lib/bitcoin/wallet/db.rb, line 22
def close
  level_db.close
end
get_keys(account) click to toggle source
# File lib/bitcoin/wallet/db.rb, line 49
def get_keys(account)
  id = [account.purpose, account.index].pack('I*').bth
  from = KEY_PREFIX[:key] + id + '00000000'
  to = KEY_PREFIX[:key] + id + 'ffffffff'
  level_db.each(from: from, to: to).map { |k, v| v}
end
register_master_key(master) click to toggle source

save seed @param [Bitcoin::Wallet::MasterKey] master a master key.

# File lib/bitcoin/wallet/db.rb, line 63
def register_master_key(master)
  level_db.put(KEY_PREFIX[:master], master.to_payload)
  level_db.put(KEY_PREFIX[:version], Bitcoin::Wallet::Base::VERSION.to_s)
  @master_key = master
end
registered_master?() click to toggle source

whether master key registered.

# File lib/bitcoin/wallet/db.rb, line 70
def registered_master?
  !level_db.get(KEY_PREFIX[:master]).nil?
end
save_account(account) click to toggle source
# File lib/bitcoin/wallet/db.rb, line 33
def save_account(account)
  level_db.batch do
    id = [account.purpose, account.index].pack('I*').bth
    key = KEY_PREFIX[:account] + id
    level_db.put(key, account.to_payload)
  end
end
save_key(account, purpose, index, key) click to toggle source
# File lib/bitcoin/wallet/db.rb, line 41
def save_key(account, purpose, index, key)
  pubkey = key.pub
  id = [account.purpose, account.index, purpose, index].pack('I*').bth
  k = KEY_PREFIX[:key] + id
  level_db.put(k, pubkey)
  key
end
version() click to toggle source

wallet version

# File lib/bitcoin/wallet/db.rb, line 75
def version
  level_db.get(KEY_PREFIX[:version]).to_i
end