Exemplo n.º 1
0
 def serialize(self, payload_version):
     _count = len(self.signs)
     return b''.join(
         (self.illegalType, pack_le_uint32(self.height),
          pack_varbytes(self.illegalSigner), self.evidence.serialize(),
          self.compareEvidence.serialize(),
          pack_varbytes(self.genesisBlockAddress), pack_varint(_count),
          b''.join((pack_varbytes(self.signs[i] for i in range(_count))))))
Exemplo n.º 2
0
    def _serialize_extra_payload(self):
        extra = self.extra_payload
        spec_tx_class = DeserializerDash.SPEC_TX_HANDLERS.get(self.tx_type)
        if not spec_tx_class:
            assert isinstance(extra, (bytes, bytearray))
            return pack_varbytes(extra)

        if not isinstance(extra, spec_tx_class):
            raise ValueError('Dash tx_type does not conform with extra'
                             ' payload class: %s, %s' % (self.tx_type, extra))
        return pack_varbytes(extra.serialize())
Exemplo n.º 3
0
 def serialize(self):
     return b''.join((
         pack_le_int64(self.value),
         pack_varbytes(self.pk_script),
         pack_varbytes(self.ek),
         pack_varbytes(self.ok),
         pack_varbytes(self.sk),
         self.tokenid,
         pack_le_int64(self.tokennftid),
         pack_varbytes(self.vdata),
     ))
Exemplo n.º 4
0
 def serialize(self):
     assert (len(self.proTxHash) == 32 and len(self.PubKeyOperator) == 48
             and len(self.KeyIdVoting) == 20 and len(self.inputsHash) == 32)
     return (pack_le_uint16(self.version) +  # version
             self.proTxHash +  # proTxHash
             pack_le_uint16(self.mode) +  # mode
             self.PubKeyOperator +  # PubKeyOperator
             self.KeyIdVoting +  # KeyIdVoting
             pack_varbytes(self.scriptPayout) +  # scriptPayout
             self.inputsHash +  # inputsHash
             pack_varbytes(self.payloadSig)  # payloadSig
             )
Exemplo n.º 5
0
 def serialize(self):
     assert (len(self.pubKey) == 48 and len(self.payloadSig) == 96)
     return (pack_le_uint16(self.version) +  # version
             pack_varbytes(self.userName) +  # userName
             self.pubKey +  # pubKey
             self.payloadSig  # payloadSig
             )
Exemplo n.º 6
0
def test_pack_varbytes():
    tests = [b'', b'1', b'2' * 253, b'3' * 254, b'4' * 256, b'5' * 65536]

    for test in tests:
        data = util.pack_varbytes(test)
        deser = tx.Deserializer(data)
        assert deser._read_varbytes() == test
Exemplo n.º 7
0
 def serialize(self):
     return b''.join((
         self.keyimage,
         self.ringsize,
         pack_varbytes(self.script),
         pack_le_uint32(self.sequence),
     ))
Exemplo n.º 8
0
def test_pack_varbytes():
    tests = [b'', b'1', b'2' * 253, b'3' * 254, b'4' * 256, b'5' * 65536]

    for test in tests:
        data = util.pack_varbytes(test)
        value, size = tx.read_varbytes(data, 0)
        assert value == test and size == len(data)
Exemplo n.º 9
0
 def serialize(self):
     return b''.join((
         self.prev_hash,
         pack_le_uint32(self.prev_idx),
         pack_varbytes(self.script),
         pack_le_uint32(self.sequence),
     ))
Exemplo n.º 10
0
    def serialize(self, payload_version):
        _count = len(self.addresses)
        assert _count == len(self.indexes) == len(self.amounts)

        return b''.join((pack_varint(_count), b''.join((b''.join(
            (pack_varbytes(self.addresses[i]), pack_varint(self.indexes[i]),
             pack_le_int64(self.amounts[i]))) for i in range(_count)))))
Exemplo n.º 11
0
 def serialize(self):
     assert (len(self.ipAddress) == 16 and len(self.KeyIdOwner) == 20
             and len(self.PubKeyOperator) == 48
             and len(self.KeyIdVoting) == 20 and len(self.inputsHash) == 32)
     return (pack_le_uint16(self.version) +  # version
             pack_le_uint16(self.type) +  # type
             pack_le_uint16(self.mode) +  # mode
             self.collateralOutpoint.serialize() +  # collateralOutpoint
             self.ipAddress +  # ipAddress
             pack_be_uint16(self.port) +  # port
             self.KeyIdOwner +  # KeyIdOwner
             self.PubKeyOperator +  # PubKeyOperator
             self.KeyIdVoting +  # KeyIdVoting
             pack_le_uint16(self.operatorReward) +  # operatorReward
             pack_varbytes(self.scriptPayout) +  # scriptPayout
             self.inputsHash +  # inputsHash
             pack_varbytes(self.payloadSig)  # payloadSig
             )
Exemplo n.º 12
0
 def serialize(self):
     assert (len(self.proTxHash) == 32 and len(self.ipAddress) == 16
             and len(self.inputsHash) == 32 and len(self.payloadSig) == 96)
     return (
         pack_le_uint16(self.version) +  # version
         self.proTxHash +  # proTxHash
         self.ipAddress +  # ipAddress
         pack_be_uint16(self.port) +  # port
         pack_varbytes(self.scriptOperatorPayout) +  # scriptOperatorPayout
         self.inputsHash +  # inputsHash
         self.payloadSig  # payloadSig
     )
Exemplo n.º 13
0
    def serialize(self):
        nLocktime = pack_le_uint32(self.locktime)
        txins = (pack_varint(len(self.inputs)) +
                 b''.join(tx_in.serialize() for tx_in in self.inputs))
        txouts = (pack_varint(len(self.outputs)) +
                  b''.join(tx_out.serialize() for tx_out in self.outputs))
        nWitness = pack_varbytes(witness)

        if self.tx_type:
            uVersion = pack_le_uint16(self.version)
            uTxType = pack_le_uint16(self.tx_type)
            vExtra = self._serialize_extra_payload()
            return uVersion + uTxType + txins + txouts + nWitness + nLocktime + vExtra
        else:
            nVersion = pack_le_int32(self.version)
            return nVersion + txins + txouts + nWitness + nLocktime
Exemplo n.º 14
0
 def serialize(self):
     return b''.join(
         (pack_varbytes(self.name), pack_varbytes(self.description),
          int_to_byte(self.precision), int_to_byte(self.assettype),
          int_to_byte(self.recordtype)))
Exemplo n.º 15
0
 def serialize(self):
     return b''.join((pack_varbytes(bytes.fromhex(self.parameter)),
                      pack_varbytes(bytes.fromhex(self.code))))
Exemplo n.º 16
0
 def serialize(self, version):
     _temp = pack_varbytes(self.candidate)
     if version >= VoteProducerAndCR:
         return b''.join((_temp, pack_le_int64(self.votes)))
     else:
         return _temp
Exemplo n.º 17
0
 def serialize(self):
     return b''.join((
         int_to_byte(self.usage),
         pack_varbytes(self.data),
     ))
Exemplo n.º 18
0
 def serialize_unsigned(self, payload_version):
     return b''.join((self.hash, self.messageHash, int_to_byte(self.stage),
                      pack_varbytes(self.ownerPublicKey),
                      pack_varbytes(self.newOwnerPublicKey)))
Exemplo n.º 19
0
 def serialize(self):
     return b''.join(
         (pack_varbytes(self.type), pack_varbytes(self.verification_method),
          pack_varbytes(self.signature)))
Exemplo n.º 20
0
 def serialize_unsigned(self, payload_version):
     return b''.join((self.type, pack_varbytes(self.data),
                      pack_varbytes(self.ownerPublicKey), self.draftHash,
                      pack_varint(len(self.budgets)),
                      b''.join(budget.serialize()
                               for budget in self.budgets), self.recipient))
Exemplo n.º 21
0
 def serialize_others(self):
     _count = len(self.signers)
     return b''.join(
         (pack_varbytes(self.blockconfirm), pack_varint(_count), b''.join(
             (pack_varbytes(self.signers[i] for i in range(_count))))))
Exemplo n.º 22
0
 def serialize_unsigned(self):
     return pack_varbytes(self.header)
Exemplo n.º 23
0
 def serialize_unsigned(self):
     return b''.join((self.proposalhash, pack_varbytes(self.signer),
                      int_to_byte(1) if self.accept else int_to_byte(0)))
Exemplo n.º 24
0
 def serialize(self, payload_version):
     if len(self.content) == 0:
         return pack_varbytes(self.content)
     else:
         return pack_varbytes(self.content)
Exemplo n.º 25
0
 def serialize(self):
     return b''.join(
         (pack_varbytes(self.specification), pack_varbytes(self.operation),
          b'' if self.operation != b'update' else pack_varbytes(
              self.previoustxid)))
Exemplo n.º 26
0
 def serialize(self, payload_version):
     return b''.join((self.serialize_unsigned(payload_version),
                      pack_varbytes(self.signature)))
Exemplo n.º 27
0
 def serialize(self, payload_version):
     _count = len(self.arbitrators)
     return b''.join(
         (pack_varbytes(self.sponsor), pack_le_uint32(self.blockHeight),
          pack_varint(_count), b''.join(
              (pack_varbytes(self.arbitrators[i]) for i in range(_count)))))
Exemplo n.º 28
0
 def serialize(self, payload_version):
     return b''.join((self.serialize_unsigned(payload_version),
                      pack_varbytes(self.ownerSignature),
                      pack_varbytes(self.newOwnerSignature),
                      int_to_byte(self.trackingType), self.opinionHash,
                      pack_varbytes(self.generalSignature)))
Exemplo n.º 29
0
 def serialize(self):
     return b''.join((
         pack_le_int64(self.value),
         pack_varbytes(self.pk_script),
     ))
Exemplo n.º 30
0
 def serialize_unsigned(self, payload_version):
     return b''.join((pack_varbytes(self.code), self.cid,
                      self.did if payload_version > 0 else b'',
                      pack_varbytes(self.nickname), pack_varbytes(self.url),
                      pack_le_uint64(self.location)))