Module: BlockIo
- Defined in:
- lib/block_io.rb,
lib/block_io/version.rb
Defined Under Namespace
Modules: Helper
Classes: Key
Constant Summary
collapse
- VERSION =
"1.2.1"
Class Method Summary
collapse
Class Method Details
.method_missing(m, *args, &block) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/block_io.rb', line 40
def self.method_missing(m, *args, &block)
method_name = m.to_s
if ['withdraw', 'withdraw_from_address', 'withdraw_from_addresses', 'withdraw_from_user', 'withdraw_from_users', 'withdraw_from_label', 'withdraw_from_labels'].include?(m.to_s) then
self.withdraw(args.first, m.to_s)
elsif ['sweep_from_address'].include?(m.to_s) then
self.sweep(args.first, m.to_s)
else
params = get_params(args.first)
self.api_call([method_name, params])
end
end
|
.set_options(args = {}) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/block_io.rb', line 21
def self.set_options(args = {})
@api_key = args[:api_key]
@pin = args[:pin]
@encryptionKey = Helper.pinToAesKey(@pin) if !@pin.nil?
hostname = args[:hostname] || "block.io"
@base_url = "https://" << hostname << "/api/VERSION/API_CALL/?api_key="
@client = HTTPClient.new
@client.tcp_keepalive = true
@client.ssl_config.ssl_version = :auto
@version = args[:version] || 2
self.api_call(['get_balance',""])
end
|
.sweep(args = {}, method_name = 'sweep_from_address') ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/block_io.rb', line 98
def self.sweep(args = {}, method_name = 'sweep_from_address')
raise Exception.new("No private_key provided.") unless args.has_key?(:private_key)
key = Key.from_wif(args[:private_key])
args[:public_key] = key.public_key args.delete(:private_key)
params = get_params(args)
response = self.api_call([method_name, params])
if response['data'].has_key?('reference_id') then
inputs = response['data']['inputs']
Helper.signData(inputs, [key])
response = self.api_call(['sign_and_finalize_sweep',{:signature_data => Oj.dump(response['data'])}])
end
return response
end
|
.withdraw(args = {}, method_name = 'withdraw') ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/block_io.rb', line 57
def self.withdraw(args = {}, method_name = 'withdraw')
raise Exception.new("PIN not set. Use BlockIo.set_options(:api_key=>'API KEY',:pin=>'SECRET PIN',:version=>'API VERSION')") if @pin.nil?
args.delete(:pin)
args.delete('pin')
params = get_params(args)
response = self.api_call([method_name, params])
if response['data'].has_key?('reference_id') then
encrypted_passphrase = response['data']['encrypted_passphrase']['passphrase']
key = Helper.(encrypted_passphrase, @encryptionKey)
raise Exception.new('Public key mismatch for requested signer and ourselves. Invalid Secret PIN detected.') if key.public_key != response['data']['encrypted_passphrase']['signer_public_key']
inputs = response['data']['inputs']
Helper.signData(inputs, [key])
response = self.api_call(['sign_and_finalize_withdrawal',{:signature_data => Oj.dump(response['data'])}])
end
return response
end
|