Class: Bitcoin

Inherits:
Base
  • Object
show all
Defined in:
lib/blocksdk_ruby/bitcoin.rb

Instance Attribute Summary

Attributes inherited from Base

#api_token

Instance Method Summary collapse

Methods inherited from Base

#initialize, #request

Constructor Details

This class inherits a constructor from Base

Instance Method Details

#createHdWallet(request = {}) ⇒ Object



64
65
66
67
68
69
# File 'lib/blocksdk_ruby/bitcoin.rb', line 64

def createHdWallet(request = {})
	request["limit"].to_s.empty? ? request['limit'] = nil : request["limit"]
	return request("POST","/btc/wallets/hd",{
		"name" => request['name']
	})
end

#createWalletAddress(request = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/blocksdk_ruby/bitcoin.rb', line 96

def createWalletAddress(request = {})

	request["wif"].to_s.empty? ? request['wif'] = nil : request["wif"]
	request["password"].to_s.empty? ? request['password'] = nil : request["password"]
	
	return request("POST","/btc/wallets/"+(request['wallet_id']).to_s + "/addresses",{
		"wif" => request['wif'],
		"password" => request['password']
	})
end

#getAddressBalance(request = {}) ⇒ Object



46
47
48
# File 'lib/blocksdk_ruby/bitcoin.rb', line 46

def getAddressBalance(request = {})
	return request("GET","/btc/addresses/" + (request['address']).to_s + "/balance")
end

#getAddressInfo(request = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blocksdk_ruby/bitcoin.rb', line 31

def getAddressInfo(request = {})

	request["reverse"].to_s.empty? ? request['reverse'] = true : request["reverse"]
	request["rawtx"].to_s.empty? ? request['rawtx'] = false : request['rawtx']
	request["offset"].to_s.empty? ? request['offset'] = 0 : request["offset"]
	request["limit"].to_s.empty? ? request['limit'] = 10 : request["limit"]
	
	return request("GET","/btc/addresses/" + (request['address']).to_s,{
		"reverse" => request['reverse'],
		"rawtx" => request['rawtx'],
		"offset" => request['offset'],
		"limit" => request['limit']
	})
end

#getBlock(request = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blocksdk_ruby/bitcoin.rb', line 7

def getBlock(request = {})
	request["rawtx"].to_s.empty? ? request['rawtx'] = false : request['rawtx']
	request["offset"].to_s.empty? ? request['offset'] = 0 : request["offset"]
	request["limit"].to_s.empty? ? request['limit'] = 10 : request["limit"]
	
	return request("GET","/btc/blocks/"+ (request['block']).to_s, {
		"rawtx" => request['rawtx'],
		"offset" => request['offset'],
		"limit" => request['limit']
	})
end

#getBlockChain(request = {}) ⇒ Object



4
5
6
# File 'lib/blocksdk_ruby/bitcoin.rb', line 4

def getBlockChain(request = {})
	return request("GET","/btc/info")
end

#getMemPool(request = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/blocksdk_ruby/bitcoin.rb', line 19

def getMemPool(request = {})
	request["rawtx"].to_s.empty? ? request['rawtx'] = false : request['rawtx']
	request["offset"].to_s.empty? ? request['offset'] = 0 : request["offset"]
	request["limit"].to_s.empty? ? request['limit'] = 10 : request["limit"]
	
	return request("GET","/btc/mempool",{
		"rawtx" => request['rawtx'],
		"offset" => request['offset'],
		"limit" => request['limit']
	})
end

#getTransaction(request = {}) ⇒ Object



167
168
169
# File 'lib/blocksdk_ruby/bitcoin.rb', line 167

def getTransaction(request = {})
	return request("GET","/btc/transactions/"+     (request['hash']).to_s + "")
end

#getWallet(request = {}) ⇒ Object



60
61
62
# File 'lib/blocksdk_ruby/bitcoin.rb', line 60

def getWallet(request = {})
	return request("GET","/btc/wallets/"+     (request['wallet_id']).to_s + "")
end

#getWalletAddress(request = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/blocksdk_ruby/bitcoin.rb', line 82

def getWalletAddress(request = {})
	request["address"].to_s.empty? ? request['address'] = nil : request["address"]
	request["hdkeypath"].to_s.empty? ? request['hdkeypath'] = nil : request["hdkeypath"]
	request["offset"].to_s.empty? ? request['offset'] = 0 : request["offset"]
	request["limit"].to_s.empty? ? request['limit'] = 10 : request["limit"]
	
	return request("GET","/btc/wallets/"+(request['wallet_id']).to_s + "/addresses",{
		"address" => request['address'],
		"hdkeypath" => request['hdkeypath'],
		"offset" => request['offset'],
		"limit" => request['limit']
	})
end

#getWalletBalance(request = {}) ⇒ Object



107
108
109
# File 'lib/blocksdk_ruby/bitcoin.rb', line 107

def getWalletBalance(request = {})	
	return request("GET","/btc/wallets/"+(request['wallet_id']).to_s + "/balance")		
end

#getWallets(request = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/blocksdk_ruby/bitcoin.rb', line 50

def getWallets(request = {})
	request["offset"].to_s.empty? ? request['offset'] = 0 : request["offset"]
	request["limit"].to_s.empty? ? request['limit'] = 10 : request["limit"]
	
	return request("GET","/btc/wallets",{
		"offset" => request['offset'],
		"limit" => request['limit']
	})
end

#getWalletTransactions(request = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/blocksdk_ruby/bitcoin.rb', line 111

def getWalletTransactions(request = {})

	request["order"].to_s.empty? ? request['order'] = 'desc' : request["order"]
	request["type"].to_s.empty? ? request['type'] = 'all' : request["type"]
	request["offset"].to_s.empty? ? request['offset'] = 0 : request["offset"]
	request["limit"].to_s.empty? ? request['limit'] = 10 : request["limit"]

	return request("GET","/btc/wallets/"+(request['wallet_id']).to_s + "/transaction",{
		"type" => request['type'],
		"order" => request['order'],
		"offset" => request['offset'],
		"limit" => request['limit']
	})
end

#loadWallet(request = {}) ⇒ Object



71
72
73
74
75
76
# File 'lib/blocksdk_ruby/bitcoin.rb', line 71

def loadWallet(request = {})
	return request("POST","/btc/wallets/"+ (request['wallet_id']).to_s + "/load",{
		"wif" => request['wif'],
		"password" => request['password']
	})
end

#sendMany(request = {}) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/blocksdk_ruby/bitcoin.rb', line 147

def sendMany(request = {})
	
	request["wif"].to_s.empty? ? request['wif'] = nil : request["wif"]
	request["password"].to_s.empty? ? request['password'] = nil : request["password"]
	request["subtractfeefromamount"].to_s.empty? ? request['subtractfeefromamount'] = false : request['subtractfeefromamount']
	
	return request("POST","/btc/wallets/"+     (request['wallet_id']).to_s + "/sendmany",{
		"to" => request['to'],
		"wif" => request['wif'],
		"password" => request['password'],
		"subtractfeefromamount" => request['subtractfeefromamount']
	})
end

#sendToAddress(request = {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/blocksdk_ruby/bitcoin.rb', line 126

def sendToAddress(request = {})

	if request["kbfee"].to_s.empty?
		blockChain = getBlockChain()
		request['kbfee'] = blockChain['medium_fee_per_kb']
	end
	
	request["wif"].to_s.empty? ? request['wif'] = nil : request["wif"]
	request["password"].to_s.empty? ? request['password'] = nil : request["password"]
	request["subtractfeefromamount"].to_s.empty? ? request['subtractfeefromamount'] = false : request['subtractfeefromamount']
	
	return request("POST","/btc/wallets/"+     (request['wallet_id']).to_s + "/sendtoaddress",{
		"address" => request['address'],
		"amount" => request['amount'],
		"wif" => request['wif'],
		"password" => request['password'],
		"kbfee" => request['kbfee'],
		"subtractfeefromamount" => request['subtractfeefromamount']
	})
end

#sendTransaction(request = {}) ⇒ Object



161
162
163
164
165
# File 'lib/blocksdk_ruby/bitcoin.rb', line 161

def sendTransaction(request = {})
	return request("POST","/btc/transactions/send",{
		"hex" => request['hex']
	})
end

#unloadWallet(request = {}) ⇒ Object



78
79
80
# File 'lib/blocksdk_ruby/bitcoin.rb', line 78

def unloadWallet(request = {})
	return request("POST","/btc/wallets/"+(request['wallet_id']).to_s + "/unload")
end