Skip to content

Commit

Permalink
MoneyTree from rubygems.org (#5)
Browse files Browse the repository at this point in the history
* MoneyTree from rubygems.org

* update demo
  • Loading branch information
korol-sas authored and maxkully committed Mar 21, 2018
1 parent cc4e4ec commit 77d4d7a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in money-tree.gemspec
gemspec

gem 'money-tree', :github => 'rusanter/money-tree', :branch => 'thebestcoin'
20 changes: 10 additions & 10 deletions bin/demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
BIP45KEYS = {
thebestcoin_testnet: "2DhbqvYUoAPXA3Cp34dGRS8Mdvjauqx3zXf4KyGPnKaW9Zu4MZPoNUCK53gWMqEV21m8thAq5XPC6oFy1mz6payxrnFqnctpnzn2AMzY8JYLycr5gEMsQaVGgXxvUktbMb56GoLSD81haHK8wtsjrjN841hU1VF5EySFqnrPfcn2V88aF9k2jgnuXtE5jpdQr4KoeUHjEjmXC99Bcn7bjuzBRxAv89kDhSFWy2vukYvYKDTkFyqGdRXuB6FjvHwnujYZ3PKFzbEdvNzAYs1fjSuHyXCDrFJrFfbBGn4HRwZm2KFUsn3cgGy4yDyzroyqLz53aNdpbitv15o3iS8T3LnjoNqoh",
bitcoin_testnet: "UCEprTQ5bbeFXFrnkQQJ7wgFNLdnxZCoJXv3ytZ4rN1hwm71NuLRi6nP8cLjxuGMQFHxMHTKZHiohFAyNzZyfPiSCZTDnGzjDAKraZbfE2H46Gfgfi2WzNr6qDSMjzGKxKFStu4scNbDayiU5BB2AUVNCkWfAMSQyasDdQFo67dyKVeYmRrbPgBrBp76HtUpL9bKZg8BpumXuCmy7rgEbT7Cisd3EdNVoSiyWZwzgFDSCBeApZTVXjuPmx1HQPTarA5xxuPzyUmheRAxZXgEQd6jNBApFZVsg1zqTJ657TKnqTPmMperZEvHYGM4daE2ZrRY72n3KVvWp7XhXZrv"
}
}

# Generate new wallets
# ==== Arguments
Expand Down Expand Up @@ -57,7 +57,7 @@ def node_multisig wallet, node_id, cosigners_count, required_signs
cosigners_count.times do |i|
keys[i] = wallet["cosigner#{i}".to_sym][:nodes][node_id][:public][:pubkey]
end

opts = {
required_signs: required_signs,
public_keys: keys,
Expand Down Expand Up @@ -91,17 +91,17 @@ def multisig_node_from_bip45(node_id)
# Returned hash with keys
# For key_type = :private
# pubkey, address, privkey, privkey_wif
# For key_type = :public
# For key_type = :public
# pubkey, address
def bip45_node(wallet, cosigner_index, key_type = :public, node_id)
# Get key from wallet keys storege by index
key = wallet["cosigner#{cosigner_index}".to_sym][:master][key_type]

# Get master node
# Get master node
master = MultisigMoneyTree::Master.from_bip32(cosigner_index, key)
# get bip45 node by change flag and index
node = master.node_for(0, node_id)

# generate address, keys
result = {
pubkey: node.to_bip32(:public, network: NETWORK),
Expand All @@ -126,14 +126,14 @@ def init_cosigner_wallet(wallet, cosigner_index, node_index)
key = "cosigner#{cosigner_index}".to_sym
wallet[key] = {} if wallet[key].nil?
wallet[key][:nodes] = {} if wallet[key][:nodes].nil?

# seed master node
wallet[key][:master] = seed(cosigner_index) if wallet[key][:master].nil?

# generate new node for +node_index+
wallet[key][:nodes][node_index] = {
public: bip45_node(wallet, cosigner_index, :public, node_index),
private: bip45_node(wallet, cosigner_index, :private, node_index)
wallet[key][:nodes][node_index] = {
public: bip45_node(wallet, cosigner_index, :public, node_index),
private: bip45_node(wallet, cosigner_index, :private, node_index)
} if wallet[key][:nodes][node_index].nil?
end

Expand Down Expand Up @@ -176,4 +176,4 @@ def init_multisig_address_from_bip45(wallet, node_index)
init_multisig_address_from_bip45(wallet, NODE + 1)

# Save wallet data
File.write(wallet_file, YAML.dump(wallet))
File.write(wallet_file, YAML.dump(wallet))
47 changes: 29 additions & 18 deletions lib/multisig-money-tree/networks.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,59 @@
module MultisigMoneyTree
@@networks = Bitcoin::NETWORKS
@@network = :bitcoin

# Merge ThiBestCoin networks configuration to Bitcoin gem
begin
@@networks[:bitcoin_testnet] = @@networks[:testnet]
@@networks.merge!(
thebestcoin: @@networks[:bitcoin].merge(
# Merge TheBestCoin network settings to +networks+ settings
def self.merge_thebestcoin(networks)
networks[:bitcoin_testnet] = networks[:testnet] unless networks[:bitcoin_testnet]
networks.merge(
thebestcoin: networks[:bitcoin].merge(
address_version: '0f',
p2sh_version: '12',
p2sh_char: '8',
privkey_version: '60',
privkey_compression_flag: '01',
extended_privkey_version: "05adc3a6",
extended_pubkey_version: "05adb52c",
compressed_wif_chars: %w(c),
uncompressed_wif_chars: %w(G),
protocol_version: 70015
),
thebestcoin_testnet: @@networks[:bitcoin].merge(
thebestcoin_testnet: networks[:bitcoin].merge(
address_version: '55',
p2sh_version: '57',
p2sh_char: 'c',
privkey_version: '1a',
privkey_compression_flag: '01',
extended_privkey_version: "3f23263a",
extended_pubkey_version: "3f23253b",
compressed_wif_chars: %w(c),
uncompressed_wif_chars: %w(B),
protocol_version: 70015
)
)

Bitcoin.send(:remove_const, :NETWORKS)
Bitcoin.const_set(:NETWORKS, @@networks)
Bitcoin.network = @@network
end
# Set network to Bitcoin gem

# Set network to self and Bitcoin gem
def self.network=(network)
raise Error::NetworkNotFound unless @@networks.key?(network.to_sym)
raise Error::NetworkNotFound, "#{network} is not a valid network!" unless @@network_keys.include?(network.to_sym)
@@network = Bitcoin.network = network.to_sym
end

# Get current network
def self.network
@@network
end
end

# Merge ThiBestCoin networks configuration to Bitcoin and MoneyTree gems
begin
money_tree = merge_thebestcoin(MoneyTree::NETWORKS)
bitcoin = merge_thebestcoin(Bitcoin::NETWORKS)

@@network_keys = bitcoin.keys
@@network = :bitcoin

MoneyTree.send(:remove_const, :NETWORKS)
MoneyTree.const_set(:NETWORKS, money_tree)

Bitcoin.send(:remove_const, :NETWORKS)
Bitcoin.const_set(:NETWORKS, bitcoin)
Bitcoin.network = @@network
end
end
4 changes: 2 additions & 2 deletions lib/multisig-money-tree/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MultisigMoneyTree
VERSION = "0.1.1".freeze
end
VERSION = "0.1.3".freeze
end

0 comments on commit 77d4d7a

Please sign in to comment.