Skip to content

Commit

Permalink
Add spending multiple inputs example
Browse files Browse the repository at this point in the history
  • Loading branch information
pool2win committed May 15, 2024
1 parent c2cc5cd commit 7680d16
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/contracts/multiple_inputs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 Kulpreet Singh
#
# This file is part of Bitcoin-DSL
#
# Bitcoin-DSL is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bitcoin-DSL is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bitcoin-DSL. If not, see <https://www.gnu.org/licenses/>.

# frozen_string_literal: false

# Generate new keys
@alice = key :new
@bob = key :new
@carol = key :new

# Seed alice with some coins
extend_chain to: @alice

# Seed bob with some coins and make coinbase spendable
extend_chain num_blocks: 1, to: @alice
extend_chain num_blocks: 101, to: @bob

@alice_coinbase = spendable_coinbase_for @alice
@bob_coinbase = spendable_coinbase_for @bob

@multiple_inputs_tx = transaction inputs: [
{ tx: @alice_coinbase, vout: 0, script_sig: 'sig:wpkh(@alice)' },
{ tx: @bob_coinbase, vout: 0, script_sig: 'sig:wpkh(@bob)' }
],
outputs: [
{
descriptor: 'wpkh(@carol)',
amount: 99.999.sats
}
]

# verify_signature for_transaction: @multiple_inputs_tx,
# at_index: 0,
# with_prevout: [@alice_coinbase, 0]

assert_mempool_accept @multiple_inputs_tx
broadcast @multiple_inputs_tx
confirm transaction: @multiple_inputs_tx, to: @carol

assert_output_is_spent transaction: @alice_coinbase, vout: 0
assert_output_is_spent transaction: @bob_coinbase, vout: 0
1 change: 1 addition & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
it_behaves_like 'script evaluation', './lib/contracts/anchor_transactions.rb'
it_behaves_like 'script evaluation', './lib/contracts/fold_transactions.rb'
it_behaves_like 'script evaluation', './lib/contracts/multisig.rb'
it_behaves_like 'script evaluation', './lib/contracts/multiple_inputs.rb'
it_behaves_like 'script evaluation', './lib/contracts/simple.rb'
end

Expand Down

0 comments on commit 7680d16

Please sign in to comment.