Skip to content

Commit 85097d6

Browse files
committed
builder: add safeguard to prevent duplicate in/outputs
1 parent 0c248cb commit 85097d6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/bitcoin/builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ def output
173173
# case to specify a tx fee that should be left unclaimed by the
174174
# change output.
175175
def tx opts = {}
176+
return @tx if @tx.hash
177+
176178
if opts[:change_address] && !opts[:input_value]
177179
raise "Must give 'input_value' when auto-generating change output!"
178180
end
179181
@ins.each {|i| @tx.add_in(i.txin) }
180182
@outs.each {|o| @tx.add_out(o.txout) }
181-
182183
if opts[:change_address]
183184
output_value = @tx.out.map(&:value).inject(:+)
184185
change_value = opts[:input_value] - output_value

0 commit comments

Comments
 (0)