Skip to content

Commit

Permalink
Merge pull request bitcoin#16 from pstratem/issue_15
Browse files Browse the repository at this point in the history
Limit send-to-sidechain transaction size
  • Loading branch information
Matt Corallo committed Jul 17, 2015
2 parents 9b0868e + 2319a2e commit 29a8740
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion contrib/sidechain-manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,26 @@ def __init__(self, value):
print("Sending %s to %s..." % (sys.argv[3], send_address))
print("(nonce: %s)" % nonce)

txid = bitcoin.sendtoaddress(send_address, Decimal(sys.argv[3]))
try:
tx_hex = bitcoin.createrawtransaction([], {send_address: Decimal(sys.argv[3])})
tx_hex = bitcoin.fundrawtransaction(tx_hex)['hex']
tx = bitcoin.signrawtransaction(tx_hex)
assert(tx['complete'])

tx_hex = tx['hex']

total_length = len(tx_hex)/2
total_length += 14*32 # maximum length of spv proof 1MB blocks
total_length += 1000 # len(full_contract) + len(secondScriptPubKey) and rounded up to 1000

if total_length >= 10000:
print("Transaction is too large.")
exit(1)

txid = bitcoin.sendrawtransaction(tx_hex)
except:
txid = bitcoin.sendtoaddress(send_address, Decimal(sys.argv[3]))

print("Sent tx with id %s" % txid)
elif sys.argv[1] == "claim-on-sidechain":
if len(sys.argv) != 5:
Expand Down

0 comments on commit 29a8740

Please sign in to comment.