forked from scottlingran/bitcoin-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.shsig.rb
More file actions
47 lines (37 loc) · 1.2 KB
/
Copy pathtest.shsig.rb
File metadata and controls
47 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'pry'
Bitcoin.network = :testnet3
include Bitcoin::Builder
privs = [
"f457f5c3ce39c5041935f047525e3d12d74a7a4ba7321393bf8167a465051b99",
"7218d2410ccf203b3d99e1448ddcd0d4f7a0c09d16f8f0611d0104e94b88629d",
"910e6a8ef179f1ee0187b5eebb52dbb06958d34d17a2e350036db280fd7c4eea",
]
keys = privs.map do |priv|
Bitcoin::Key.new(priv, nil, false)
end
unspent = {
confirmations: 1,
blockHeight: 227071,
txHash: 'cef3e503886b597bf67cea46c21f22f9ef8e238dad6f595dcd2a42c1c2eb61c9',
index: 0,
scriptPubKey: 'a9148a8b86cab5d35efea59c6fa9b416fbea07c7452f87',
type: 'scripthash',
value: 100000,
hash160: '8a8b86cab5d35efea59c6fa9b416fbea07c7452f',
address: '2N5snPEHUgsw5FjypjZ5zR8DQKqotmU5YAR' }
pubkeys = keys.map { |k| k.pub }.join(" ")
redeem_script = Bitcoin::Script.from_string("2 #{pubkeys} 3 OP_CHECKMULTISIG")
binding.pry
new_tx = build_tx({p2sh_multisig: true}) do |t|
t.input do |i|
i.prev_out unspent[:txHash]
i.prev_out_index unspent[:index]
i.prev_out_script redeem_script.raw
i.signature_key keys[0..1]
end
t.output do |o|
o.value unspent[:value]
o.script { |s| s.recipient("mvaRDyLUeF4CP7Lu9umbU3FxehyC5nUz3L") }
end
end
p new_tx.payload.unpack("H*")[0]