def createAtomicSwapAccount(self, callback = None): _address, _public, _private = Crypto.generateKeys() privateBytes = bytearray() privateBytes.extend(_address) privateBytes.extend(_public) privateBytes.extend(_private) privateKey = Crypto.generateHash(privateBytes) self.createNewMultiSigAccountType(AccountType.ATOMIC_SWAP, privateKey, callback)
def extcodehash(self): address = self.pop() unspentTransactionScript = UXTO.getUnspentTransactionScript(address) txOut = unspentTransactionScript.output script = txOut.script _hash = 0 if script == None else Crypto.generateHash(script, Config.getValue('SHA3_HASHING_ALGORITHM')) self.stack.append(_hash)
def init(self): merkleNodes = [] for transaction in self.transactions: merkleNode = MerkleNode() txHash = transaction.hashTxWitness( ) if self.includeWitness else transaction.hash() merkleNode.hash = Crypto.generateHash(txHash) merkleNodes.append(merkleNode) self.generateMerkleTree(merkleNodes) self.merkleNodes.extend(merkleNodes)
def generateMerkleTree(self, prevMerkleNodes): if len(prevMerkleNodes) > 1: merkleNodes = [] merkleNode = None for prevMerkleNode in prevMerkleNodes: if merkleNode == None: merkleNode = MerkleNode() if merkleNode.left == None: merkleNode.left = prevMerkleNode elif merkleNode.right == None: merkleNode.right = prevMerkleNode if merkleNode.left != None and merkleNode.right != None: data = merkleNode.left.hash + merkleNode.right.hash merkleNode.hash = Crypto.generateHash(data) merkleNodes.append(merkleNode) merkleNode = None if merkleNode != None: merkleNode.hash = Crypto.generateHash(merkleNode.left.hash) merkleNodes.append(merkleNode) self.generateMerkleTree(merkleNodes) self.merkleNodes.extend(merkleNodes)
def sha256(self): data = self.pop() _hash = Crypto.generateHash(data, Config.getValue('SHA2_HASHING_ALGORITHM')) self.stack.append(_hash)
def hashTxWitness(self): return Crypto.generateHash(self.serialize())
def hash(self): includeWitness = self.isCoinbase() return Crypto.generateHash(self.serialize(includeWitness))