Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
script: avoid using copy.deepcopy(), to copy the signing TX
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Garzik authored and Jeff Garzik committed Aug 6, 2012
1 parent 6bf85ea commit 886d26f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
29 changes: 29 additions & 0 deletions bitcoin/core.py
Expand Up @@ -90,6 +90,9 @@ def serialize(self):
return r
def is_null(self):
return ((self.hash == 0) and (self.n == 0xffffffff))
def copy(self, old_outpt):
self.hash = old_outpt.hash
self.n = old_outpt.n
def __repr__(self):
return "COutPoint(hash=%064x n=%i)" % (self.hash, self.n)

Expand All @@ -114,6 +117,11 @@ def is_valid(self):
if not script.tokenize(self.scriptSig):
return False
return True
def copy(self, old_txin):
self.prevout = COutPoint()
self.prevout.copy(old_txin.prevout)
self.scriptSig = old_txin.scriptSig
self.nSequence = old_txin.nSequence
def __repr__(self):
return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" % (repr(self.prevout), binascii.hexlify(self.scriptSig), self.nSequence)

Expand All @@ -136,6 +144,9 @@ def is_valid(self):
if not script.tokenize(self.scriptPubKey):
return False
return True
def copy(self, old_txout):
self.nValue = old_txout.nValue
self.scriptPubKey = old_txout.scriptPubKey
def __repr__(self):
return "CTxOut(nValue=%i.%08i scriptPubKey=%s)" % (self.nValue // 100000000, self.nValue % 100000000, binascii.hexlify(self.scriptPubKey))

Expand Down Expand Up @@ -173,6 +184,24 @@ def is_valid(self):
return True
def is_coinbase(self):
return len(self.vin) == 1 and self.vin[0].prevout.is_null()

def copy(self, old_tx):
self.nVersion = old_tx.nVersion
self.vin = []
self.vout = []
self.nLockTime = old_tx.nLockTime
self.sha256 = None

for old_txin in old_tx.vin:
txin = CTxIn()
txin.copy(old_txin)
self.vin.append(txin)

for old_txout in old_tx.vout:
txout = CTxOut()
txout.copy(old_txout)
self.vout.append(txout)

def __repr__(self):
return "CTransaction(nVersion=%i vin=%s vout=%s nLockTime=%i)" % (self.nVersion, repr(self.vin), repr(self.vout), self.nLockTime)

Expand Down
7 changes: 4 additions & 3 deletions bitcoin/scripteval.py
Expand Up @@ -6,18 +6,19 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#

import copy
from serialize import Hash, Hash160, ser_uint256, ser_uint160
from Crypto.Hash import SHA256
from script import *
from core import CTxOut
from core import CTxOut, CTransaction
from key import CKey
from bignum import bn2vch, vch2bn

def SignatureHash(script, txTo, inIdx, hashtype):
if inIdx >= len(txTo.vin):
return (0L, "inIdx %d out of range (%d)" % (inIdx, len(txTo.vin)))
txtmp = copy.deepcopy(txTo)
txtmp = CTransaction()
txtmp.copy(txTo)

for txin in txtmp.vin:
txin.scriptSig = ''
txtmp.vin[inIdx].scriptSig = script.vch
Expand Down

0 comments on commit 886d26f

Please sign in to comment.