sibit 0.34.1 → 0.34.2
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/lib/sibit/tx.rb +21 -7
- data/lib/sibit/txbuilder.rb +3 -2
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ea3404e8f546263164e5b87826a723238cb6bd21589149429f9e3d5b32f0e5a
|
|
4
|
+
data.tar.gz: 81c897434a338c46c517c8de6d4fc69693f190b10beffe8ef43f909daa92e47d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f481815314355cdf7cad857fb35d9b08599e8b2a6e8aa175c33ec5e68962957b390033d8aafb01d580c1e33035376a52b6dee983d3fe31469b15f1be6868ae0
|
|
7
|
+
data.tar.gz: 1652d8c4bee002326b3f9e6b885e85cf750742b10b7de6fd71379f64331e07d94d6aefbc49cab2a71f8a0ab8a6b7606a7458eb395fec7e50a715a309db1ffa2d
|
data/lib/sibit/tx.rb
CHANGED
|
@@ -24,9 +24,10 @@ class Sibit
|
|
|
24
24
|
|
|
25
25
|
attr_reader :inputs, :outputs
|
|
26
26
|
|
|
27
|
-
def initialize
|
|
27
|
+
def initialize(network: :mainnet)
|
|
28
28
|
@inputs = []
|
|
29
29
|
@outputs = []
|
|
30
|
+
@network = network
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
def add_input(hash:, index:, script:, key:, value: 0)
|
|
@@ -34,7 +35,7 @@ class Sibit
|
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def add_output(value, address)
|
|
37
|
-
@outputs << Output.new(value, address)
|
|
38
|
+
@outputs << Output.new(value, address, @network)
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def hash
|
|
@@ -103,20 +104,33 @@ class Sibit
|
|
|
103
104
|
class Output
|
|
104
105
|
attr_reader :value
|
|
105
106
|
|
|
106
|
-
def initialize(value, address)
|
|
107
|
+
def initialize(value, address, network = :mainnet)
|
|
107
108
|
@value = value
|
|
108
109
|
@address = address
|
|
110
|
+
@network = network
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
def script
|
|
112
114
|
return segwit_script if segwit?
|
|
113
|
-
return p2pkh_script if
|
|
114
|
-
return p2sh_script if
|
|
115
|
-
raise(
|
|
115
|
+
return p2pkh_script if version == (@network == :mainnet ? '00' : '6f')
|
|
116
|
+
return p2sh_script if version == (@network == :mainnet ? '05' : 'c4')
|
|
117
|
+
raise(
|
|
118
|
+
Sibit::Error,
|
|
119
|
+
"Address '#{@address}' has version byte 0x#{version}, " \
|
|
120
|
+
"which does not belong to the #{@network} network"
|
|
121
|
+
)
|
|
116
122
|
end
|
|
117
123
|
|
|
118
124
|
def segwit?
|
|
119
|
-
@address.downcase
|
|
125
|
+
down = @address.downcase
|
|
126
|
+
return true if down.start_with?(*(@network == :mainnet ? ['bc1'] : %w[tb1 bcrt1]))
|
|
127
|
+
if down.start_with?(*(@network == :mainnet ? %w[tb1 bcrt1] : ['bc1']))
|
|
128
|
+
raise(
|
|
129
|
+
Sibit::Error,
|
|
130
|
+
"Address '#{@address}' is a Bech32 address of a different network than #{@network}"
|
|
131
|
+
)
|
|
132
|
+
end
|
|
133
|
+
false
|
|
120
134
|
end
|
|
121
135
|
|
|
122
136
|
def script_hex
|
data/lib/sibit/txbuilder.rb
CHANGED
|
@@ -20,9 +20,10 @@ class Sibit
|
|
|
20
20
|
class TxBuilder
|
|
21
21
|
DUST = 546
|
|
22
22
|
|
|
23
|
-
def initialize
|
|
23
|
+
def initialize(network = :mainnet)
|
|
24
24
|
@inputs = []
|
|
25
25
|
@outputs = []
|
|
26
|
+
@network = network
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def input
|
|
@@ -36,7 +37,7 @@ class Sibit
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def tx(input_value:, leave_fee:, extra_fee:, change_address:)
|
|
39
|
-
txn = Tx.new
|
|
40
|
+
txn = Tx.new(network: @network)
|
|
40
41
|
@inputs.each do |inp|
|
|
41
42
|
txn.add_input(
|
|
42
43
|
hash: inp.prev_out_hash,
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED