コード例 #1
0
ファイル: test_gevent.py プロジェクト: trangttt/pycoin
    def testChecksum(self):
        data = [
            ('test', '954d5a49'),
            ('pycoin', '58709a9f')
        ]

        for d, h in data:
            self.assertEquals(utils.checksum(d).encode('hex'), h)
            self.assertEquals(utils.doubleSha256(d)[:4].encode('hex'), h)
コード例 #2
0
ファイル: messages.py プロジェクト: sunfinite/graphene
 def hash(self):
     """
     If we have the hash saved from a parsing action we just return it
     otherwise we serialize this transaction and calculate the 2xSha256.
     If the hash is derived from a serialization we do not cache the result
     should happen rarely though.
     """
     buf = BytesIO()
     self.toWire(buf, {'segwit': False})
     return doubleSha256(buf.getvalue())[::-1]
コード例 #3
0
ファイル: messages.py プロジェクト: gitter-badger/pycoin
 def hash(self):
     """
     If we have the hash saved from a parsing action we just return it
     otherwise we serialize this transaction and calculate the 2xSha256.
     If the hash is derived from a serialization we do not cache the result
     should happen rarely though.
     """
     buf = BytesIO()
     self.toWire(buf, PROTOCOL_VERSION)
     return doubleSha256(buf.getvalue())[::-1]
コード例 #4
0
ファイル: messages.py プロジェクト: cdecker/pycoin
 def hash(self):
     """
     If we have the hash saved from a parsing action we just return it
     otherwise we serialize this transaction and calculate the 2xSha256.
     If the hash is derived from a serialization we do not cache the result
     should happen rarely though.
     """
     if self._hash:
         return self._hash
     else:
         buf = BytesIO()
         self.toWire(buf, {'segwit': False, 'version': PROTOCOL_VERSION})
         return doubleSha256(buf.getvalue()[:80])[::-1]
コード例 #5
0
ファイル: messages.py プロジェクト: sunfinite/graphene
    def parse(self, payload, opts):
        Packet.parse(self, payload, opts)

        self.version, self.prev_block, self.merkle_root = struct.unpack(
            '<I32s32s', payload.read(68))
        self.prev_block = self.prev_block[::-1]
        self.merkle_root = self.merkle_root[::-1]
        self.timestamp, self.bits, self.nonce = struct.unpack(
            '<III', payload.read(12))
        transactionCount = decodeVarLength(payload)
        while len(self.transactions) < transactionCount:
            t = TxPacket()
            t.parse(payload, opts)
            self.transactions.append(t)
        self._hash = doubleSha256(payload.getvalue()[:80])[::-1]
コード例 #6
0
ファイル: messages.py プロジェクト: sunfinite/graphene
    def normalized_hash(self):
        if self.is_coinbase():
            return self.hash()
        else:
            copy = TxPacket()
            buf = BytesIO()
            self.toWire(buf, None)
            copy.parse(BytesIO(buf.getvalue()), None)

            for pos, iput in enumerate(copy.inputs):
                copy.inputs[pos] = (iput[0], "", iput[2])
            buf = BytesIO()
            copy.toWire(buf, None)
            buf.write(struct.pack('<I', 1))
            return doubleSha256(buf.getvalue())[::-1]
コード例 #7
0
ファイル: messages.py プロジェクト: gitter-badger/pycoin
    def parse(self, payload, version):
        Packet.parse(self, payload, version)

        self.version, self.prev_block, self.merkle_root = struct.unpack(
            '<I32s32s', payload.read(68))
        self.prev_block = self.prev_block[::-1]
        self.merkle_root = self.merkle_root[::-1]
        self.timestamp, self.bits, self.nonce = struct.unpack(
            '<III', payload.read(12))
        transactionCount = decodeVarLength(payload)
        while len(self.transactions) < transactionCount:
            t = TxPacket()
            t.parse(payload, version)
            self.transactions.append(t)
        self._hash = doubleSha256(payload.getvalue()[:80])[::-1]
コード例 #8
0
ファイル: messages.py プロジェクト: gitter-badger/pycoin
    def normalized_hash(self):
        if self.is_coinbase():
            return self.hash()
        else:
            copy = TxPacket()
            buf = BytesIO()
            self.toWire(buf, None)
            copy.parse(BytesIO(buf.getvalue()), None)

            for pos, iput in enumerate(copy.inputs):
                copy.inputs[pos] = (iput[0], "", iput[2])
            buf = BytesIO()
            copy.toWire(buf, None)
            buf.write(struct.pack('<I', 1))
            return doubleSha256(buf.getvalue())[::-1]
コード例 #9
0
ファイル: messages.py プロジェクト: sunfinite/graphene
 def whash(self):
     if self.is_coinbase():
         return "\x00" * 32
     buf = BytesIO()
     self.toWire(buf, {'segwit': self.is_segwit})
     return doubleSha256(buf.getvalue())[::-1]
コード例 #10
0
ファイル: messages.py プロジェクト: cdecker/pycoin
 def whash(self):
     if self.is_coinbase():
         return "00".decode('hex')*32
     buf = BytesIO()
     self.toWire(buf, {'segwit': self.is_segwit})
     return doubleSha256(buf.getvalue())[::-1]