onchain / paper-wallet-spender

Create transactions for multiple currencies from private keys.
0 stars 4 forks source link

Add bitcoin testnet support. #4

Closed 9876691 closed 6 years ago

9876691 commented 6 years ago

Finish the implementation of UTXOTransaction. The following methods need to be implemented.

to_hex - generates a valid Bitcoin/Testnet transaction (Unsigned). You can use a service such as https://www.blockchain.com/en/btc/decode-tx To check the transactions are correct.

signature_hash_for_input method - You can see an example written in ruby here https://github.com/lian/bitcoin-ruby/blob/master/lib/bitcoin/protocol/tx.rb#L171

The example implements witness which we don't need, what we need is a much reduced version of the ZCashTransaction.signature_hash_for_zcash method that's already written.

Add a new spec i.e. testnet_spec.cr that parses and generates the transactions similar to zcash_spec.cr

9876691 commented 6 years ago

Test Case 1

tx_hex = "0100000001c140e8db2c9e1289f8d0d84ac6f4041a8ca89713685bd109b6b0241db497339a020000001976a9143a48bfebcdc52c7b3831eab75a1955e58744c7e388acffffffff03a0860100000000001976a914abf102c1e98693c5949c02559a8a8b33d102de5b88ac801a0600000000001976a914e229651d1ea66dbdfc4ec59f1eb9394559c284c988ac20a94c17000000001976a9143a48bfebcdc52c7b3831eab75a1955e58744c7e388ac00000000"

tx = UTXOTransaction.new(tx_hex)
tx.inputs.size.should eq(1)
tx.outputs.size.should eq(3)
tx.to_hex.should eq(tx_hex)
9876691 commented 6 years ago

Test Case 2

tx_hex = "0100000001c140e8db2c9e1289f8d0d84ac6f4041a8ca89713685bd109b6b0241db497339a020000001976a9143a48bfebcdc52c7b3831eab75a1955e58744c7e388acffffffff03a0860100000000001976a914abf102c1e98693c5949c02559a8a8b33d102de5b88ac801a0600000000001976a914e229651d1ea66dbdfc4ec59f1eb9394559c284c988ac20a94c17000000001976a9143a48bfebcdc52c7b3831eab75a1955e58744c7e388ac00000000"

tx = UTXOTransaction.new(tx_hex)
tx.inputs.size.should eq(1)
tx.outputs.size.should eq(3)
tx.hash_signature_for_input(0).should eq("48d61492e2d8651868677056b5157e54e34171b6b942ccc9c450dfe65c95c8ac")