1from pycoin.encoding.bytes32 import from_bytes_32 2from pycoin.encoding.hash import double_sha256 3from pycoin.satoshi.flags import SIGHASH_FORKID 4 5from ..bitcoin.SolutionChecker import BitcoinSolutionChecker 6 7 8class BgoldSolutionChecker(BitcoinSolutionChecker): 9 10 FORKID_BTG = 79 # atomic number for Au (gold) 11 12 def _signature_hash(self, tx_out_script, unsigned_txs_out_idx, hash_type): 13 """ 14 Return the canonical hash for a transaction. We need to 15 remove references to the signature, since it's a signature 16 of the hash before the signature is applied. 17 18 tx_out_script: the script the coins for unsigned_txs_out_idx are coming from 19 unsigned_txs_out_idx: where to put the tx_out_script 20 hash_type: one of SIGHASH_NONE, SIGHASH_SINGLE, SIGHASH_ALL, 21 optionally bitwise or'ed with SIGHASH_ANYONECANPAY 22 """ 23 24 if hash_type & SIGHASH_FORKID != SIGHASH_FORKID: 25 raise self.ScriptError() 26 27 return self._signature_for_hash_type_segwit(tx_out_script, unsigned_txs_out_idx, hash_type) 28 29 def _signature_for_hash_type_segwit(self, script, tx_in_idx, hash_type): 30 hash_type |= self.FORKID_BTG << 8 31 return from_bytes_32(double_sha256(self._segwit_signature_preimage(script, tx_in_idx, hash_type))) 32