Class: Round::WalletCollection
- Inherits:
-
Collection
- Object
- Base
- Collection
- Round::WalletCollection
- Defined in:
- lib/round/wallet.rb
Instance Attribute Summary
Attributes inherited from Collection
Attributes inherited from Base
Instance Method Summary collapse
- #content_type ⇒ Object
- #create(name, passphrase, network: 'bitcoin_testnet', multiwallet: CoinOp::Bit::MultiWallet.generate([:primary, :backup])) ⇒ Object
- #create_wallet_resource(multiwallet, passphrase, name) ⇒ Object
-
#initialize(options, &block) ⇒ WalletCollection
constructor
A new instance of WalletCollection.
Methods inherited from Collection
#[], #add, #method_missing, #populate_data, #refresh
Methods inherited from Base
association, #hash_identifier, hash_identifier, #method_missing, #refresh
Constructor Details
#initialize(options, &block) ⇒ WalletCollection
Returns a new instance of WalletCollection.
41 42 43 44 |
# File 'lib/round/wallet.rb', line 41 def initialize(, &block) super @application = [:application] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Round::Collection
Instance Method Details
#content_type ⇒ Object
46 47 48 |
# File 'lib/round/wallet.rb', line 46 def content_type Round::Wallet end |
#create(name, passphrase, network: 'bitcoin_testnet', multiwallet: CoinOp::Bit::MultiWallet.generate([:primary, :backup])) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/round/wallet.rb', line 50 def create(name, passphrase, network: 'bitcoin_testnet', multiwallet: CoinOp::Bit::MultiWallet.generate([:primary, :backup])) backup = multiwallet.private_seed(:backup, network: :bitcoin) multiwallet.drop_private(:backup) backup_master = multiwallet.trees[:backup] new_bmaster = MoneyTree::Master.new(public_key: backup_master.public_key, chain_code: backup_master.chain_code) multiwallet.trees[:backup] = new_bmaster wallet_resource = create_wallet_resource(multiwallet, passphrase, name) multiwallet.import( cosigner_public_seed: wallet_resource.cosigner_public_seed ) wallet = Round::Wallet.new( resource: wallet_resource, multiwallet: multiwallet, application: @application, client: @client ) add(wallet) [backup, wallet] end |
#create_wallet_resource(multiwallet, passphrase, name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/round/wallet.rb', line 71 def create_wallet_resource(multiwallet, passphrase, name) primary_seed = CoinOp::Encodings.hex(multiwallet.trees[:primary].seed) ## Encrypt the primary seed using a passphrase-derived key encrypted_seed = CoinOp::Crypto::PassphraseBox.encrypt(passphrase, primary_seed) @resource.create( name: name, backup_public_seed: multiwallet.trees[:backup].to_bip32, primary_public_seed: multiwallet.trees[:primary].to_bip32, primary_private_seed: encrypted_seed ) end |