bitcoinrb 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/bitcoin/psbt/input.rb +1 -1
- data/lib/bitcoin/rpc/bitcoin_core_client.rb +72 -0
- data/lib/bitcoin/rpc.rb +1 -0
- data/lib/bitcoin/script/script.rb +3 -2
- data/lib/bitcoin/script/script_interpreter.rb +8 -0
- data/lib/bitcoin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79b3878cc9efefd8c38b5cd870144bc23a80bbf7bf1c741378dd66c9e5ebdbf8
|
4
|
+
data.tar.gz: a5d9956a5a6b7bed15b73e552b84110d9636f1b069c1d97978be4e94c1e0a0f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b779fd9decef5b224144dae60e06b99f3ac0fbb17b34202af0ce31eb2bd7e0a6076b3a940dcfe2e460923017c14feb40c2d0bf891f3ebe9553b65be124559a32
|
7
|
+
data.tar.gz: 7f011d31ab1ec5364cc8f04a63b6baf74d37db05d49666588dd1329d5005f3ba01a8e8b83752989121b73c3956eda8a5808365b729f6d21dc136f6abf0c817cd
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2017-2018 HAW International, Inc.
|
3
|
+
Copyright (c) 2017-2018 HAW International, Inc. / chaintope, Inc.
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/bitcoin/psbt/input.rb
CHANGED
@@ -141,7 +141,7 @@ module Bitcoin
|
|
141
141
|
def finalize!
|
142
142
|
if non_witness_utxo
|
143
143
|
self.final_script_sig = Bitcoin::Script.new << Bitcoin::Opcodes::OP_0 if redeem_script.multisig?
|
144
|
-
partial_sigs.values.each {|sig|final_script_sig << sig
|
144
|
+
partial_sigs.values.each {|sig|final_script_sig << sig}
|
145
145
|
final_script_sig << redeem_script.to_payload.bth
|
146
146
|
self.partial_sigs = {}
|
147
147
|
self.hd_key_paths = {}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Bitcoin
|
4
|
+
module RPC
|
5
|
+
|
6
|
+
# Client implementation for RPC to Bitcoin Core.
|
7
|
+
#
|
8
|
+
# [Usage]
|
9
|
+
# config = {schema: 'http', host: 'localhost', port: 18332, user: 'xxx', password: 'yyy'}
|
10
|
+
# client = Bitcoin::RPC::BitcoinCoreClient.new(config)
|
11
|
+
#
|
12
|
+
# You can execute the CLI command supported by Bitcoin Core as follows:
|
13
|
+
#
|
14
|
+
# client.listunspent
|
15
|
+
# client.getblockchaininfo
|
16
|
+
#
|
17
|
+
class BitcoinCoreClient
|
18
|
+
|
19
|
+
attr_reader :config
|
20
|
+
|
21
|
+
# @param [Hash] config a configuration required to connect to Bitcoin Core.
|
22
|
+
def initialize(config)
|
23
|
+
@config = config
|
24
|
+
|
25
|
+
commands = request(:help).split("\n").inject([]) do |memo_ary, line|
|
26
|
+
if !line.empty? && !line.start_with?('==')
|
27
|
+
memo_ary << line.split(' ').first.to_sym
|
28
|
+
end
|
29
|
+
memo_ary
|
30
|
+
end
|
31
|
+
BitcoinCoreClient.class_eval do
|
32
|
+
commands.each do |command|
|
33
|
+
define_method(command) do |*params|
|
34
|
+
request(command, *params)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def server_url
|
43
|
+
url = "#{config[:schema]}://#{config[:user]}:#{config[:password]}@#{config[:host]}:#{config[:port]}"
|
44
|
+
if !config[:wallet].nil? && !config[:wallet].empty?
|
45
|
+
url += "/wallet/#{config[:wallet]}"
|
46
|
+
end
|
47
|
+
url
|
48
|
+
end
|
49
|
+
|
50
|
+
def request(command, *params)
|
51
|
+
data = {
|
52
|
+
:method => command,
|
53
|
+
:params => params,
|
54
|
+
:id => 'jsonrpc'
|
55
|
+
}
|
56
|
+
post(server_url, @config[:timeout], @config[:open_timeout], data.to_json, content_type: :json) do |respdata, request, result|
|
57
|
+
raise result.message if !result.kind_of?(Net::HTTPSuccess) && respdata.empty?
|
58
|
+
response = JSON.parse(respdata.gsub(/\\u([\da-fA-F]{4})/) { [$1].pack('H*').unpack('n*').pack('U*').encode('ISO-8859-1').force_encoding('UTF-8') })
|
59
|
+
raise response['error'] if response['error']
|
60
|
+
response['result']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def post(url, timeout, open_timeout, payload, headers={}, &block)
|
65
|
+
RestClient::Request.execute(method: :post, url: url, timeout: timeout,
|
66
|
+
open_timeout: open_timeout, payload: payload, headers: headers, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
data/lib/bitcoin/rpc.rb
CHANGED
@@ -264,7 +264,7 @@ module Bitcoin
|
|
264
264
|
if obj.is_a?(Integer)
|
265
265
|
push_int(obj)
|
266
266
|
elsif obj.is_a?(String)
|
267
|
-
append_data(obj
|
267
|
+
append_data(obj)
|
268
268
|
elsif obj.is_a?(Array)
|
269
269
|
obj.each { |o| self.<< o}
|
270
270
|
self
|
@@ -295,7 +295,8 @@ module Bitcoin
|
|
295
295
|
# @param [String] data append data. this data is not binary
|
296
296
|
# @return [Script] return self
|
297
297
|
def append_data(data)
|
298
|
-
|
298
|
+
data = Encoding::ASCII_8BIT == data.encoding ? data : data.htb
|
299
|
+
chunks << Bitcoin::Script.pack_pushdata(data)
|
299
300
|
self
|
300
301
|
end
|
301
302
|
|
@@ -13,6 +13,14 @@ module Bitcoin
|
|
13
13
|
|
14
14
|
DISABLE_OPCODES = [OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT, OP_AND, OP_OR, OP_XOR, OP_2MUL, OP_2DIV, OP_DIV, OP_MUL, OP_MOD, OP_LSHIFT, OP_RSHIFT]
|
15
15
|
|
16
|
+
|
17
|
+
# syntax sugar for simple evaluation for script.
|
18
|
+
# @param [Bitcoin::Script] script_sig a scriptSig.
|
19
|
+
# @param [Bitcoin::Script] script_pubkey a scriptPubkey.
|
20
|
+
def self.eval(script_sig, script_pubkey)
|
21
|
+
self.new.verify_script(script_sig, script_pubkey)
|
22
|
+
end
|
23
|
+
|
16
24
|
# initialize runner
|
17
25
|
def initialize(flags: SCRIPT_VERIFY_NONE, checker: TxChecker.new)
|
18
26
|
@stack, @debug = [], []
|
data/lib/bitcoin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitcoinrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecdsa
|
@@ -371,6 +371,7 @@ files:
|
|
371
371
|
- lib/bitcoin/psbt/output.rb
|
372
372
|
- lib/bitcoin/psbt/tx.rb
|
373
373
|
- lib/bitcoin/rpc.rb
|
374
|
+
- lib/bitcoin/rpc/bitcoin_core_client.rb
|
374
375
|
- lib/bitcoin/rpc/http_server.rb
|
375
376
|
- lib/bitcoin/rpc/request_handler.rb
|
376
377
|
- lib/bitcoin/script/multisig.rb
|