示例#1
0
    def toWire(self, buf, opts=None):
        Packet.toWire(self, buf, opts)
        buf.write(struct.pack("<I", self.version))

        if get_opt(opts, 'segwit', False):
            buf.write("\x00\x01")

        buf.write(encodeVarLength(len(self.inputs)))
        for i in self.inputs:
            prev_out, script, sequence = i
            buf.write(prev_out[0][::-1])
            buf.write(struct.pack("<I", prev_out[1]))
            buf.write(encodeVarString(script))
            buf.write(struct.pack("<I", sequence))

        buf.write(encodeVarLength(len(self.outputs)))
        for o in self.outputs:
            value, script = o
            buf.write(struct.pack("<Q", value))
            buf.write(encodeVarString(script))

        if get_opt(opts, 'segwit', False):
            for w in self.witnesses:
                buf.write(encodeVarLength(len(w)))
                for e in w:
                    buf.write(encodeVarString(e))

        buf.write(struct.pack("<I", self.lock_time))
示例#2
0
 def testVarLength(self):
     self.assertEqual('01', encodeVarLength(1).encode("hex"))
     self.assertEqual('fd0004', encodeVarLength(1024).encode("hex"))
     self.assertEqual('feefbeadde',
                      encodeVarLength(3735928559).encode("hex"))
     self.assertEqual('ffdeadbeefdeadbeef',
                      encodeVarLength(17275436393656397278).encode("hex"))
示例#3
0
    def toWire(self, buf, opts=None):
        Packet.toWire(self, buf, opts)
        buf.write(struct.pack("<I", self.version))

        if get_opt(opts, 'segwit', False):
            buf.write("\x00\x01")

        buf.write(encodeVarLength(len(self.inputs)))
        for i in self.inputs:
            prev_out, script, sequence = i
            buf.write(prev_out[0][::-1])
            buf.write(struct.pack("<I", prev_out[1]))
            buf.write(encodeVarString(script))
            buf.write(struct.pack("<I", sequence))

        buf.write(encodeVarLength(len(self.outputs)))
        for o in self.outputs:
            value, script = o
            buf.write(struct.pack("<Q", value))
            buf.write(encodeVarString(script))

        if get_opt(opts, 'segwit', False):
            for w in self.witnesses:
                buf.write(encodeVarLength(len(w)))
                for e in w:
                    buf.write(encodeVarString(e))

        buf.write(struct.pack("<I", self.lock_time))
示例#4
0
 def testVarLength(self):
     self.assertEqual("01",
                      encodeVarLength(1).encode("hex"),
                      "Simple 1 char number")
     self.assertEqual("fd0004",
                      encodeVarLength(1024).encode("hex"),
                      "2 + 1 byte number")
     self.assertEqual("feefbeadde",
                      encodeVarLength(3735928559).encode("hex"),
                      "4 + 1 byte number")
     self.assertEqual("ffdeadbeefdeadbeef",
                      encodeVarLength(17275436393656397278).encode("hex"),
                      "8 + 1 byte number")
示例#5
0
 def testVarLength(self):
     self.assertEqual(
         '01', encodeVarLength(1).encode("hex")
     )
     self.assertEqual(
         'fd0004', encodeVarLength(1024).encode("hex")
     )
     self.assertEqual(
         'feefbeadde', encodeVarLength(3735928559).encode("hex")
     )
     self.assertEqual(
         'ffdeadbeefdeadbeef',
         encodeVarLength(17275436393656397278).encode("hex")
     )
示例#6
0
 def toWire(self, buf, opts):
     buf.write(encodeVarLength(len(self.hashes)))
     for h in self.hashes:
         buf.write(struct.pack("<I", h[0]))
         buf.write(h[1][::-1])
         if h[0] == 5 and self.type == "getdata":
             buf.write(struct.pack("<I", h[2]))
示例#7
0
 def toWire(self, buf, opts):
     Packet.toWire(self, buf, opts)
     buf.write(
         struct.pack("<I32s32sIII", self.version, self.prev_block[::-1],
                     self.merkle_root[::-1], self.timestamp, self.bits,
                     self.nonce))
     buf.write(encodeVarLength(len(self.transactions)))
     for t in self.transactions:
         t.toWire(buf, opts)
示例#8
0
    def toWire(self, buf, version):
        Packet.toWire(self, buf, version)
        buf.write(struct.pack("<I", self.version))
        buf.write(encodeVarLength(len(self.inputs)))
        for i in self.inputs:
            prev_out, script, sequence = i
            buf.write(prev_out[0][::-1])
            buf.write(struct.pack("<I", prev_out[1]))
            buf.write(encodeVarString(script))
            buf.write(struct.pack("<I", sequence))

        buf.write(encodeVarLength(len(self.outputs)))
        for o in self.outputs:
            value, script = o
            buf.write(struct.pack("<Q", value))
            buf.write(encodeVarString(script))

        buf.write(struct.pack("<I", self.lock_time))
示例#9
0
 def toWire(self, buf, version):
     Packet.toWire(self, buf, version)
     buf.write(struct.pack("<I32s32sIII",
                           self.version,
                           self.prev_block[::-1],
                           self.merkle_root[::-1],
                           self.timestamp,
                           self.bits,
                           self.nonce))
     buf.write(encodeVarLength(len(self.transactions)))
     for t in self.transactions:
         t.toWire(buf, version)
示例#10
0
 def testVarLength(self):
     self.assertEqual("01", encodeVarLength(1).encode("hex"), "Simple 1 char number")
     self.assertEqual("fd0004", encodeVarLength(1024).encode("hex"), "2 + 1 byte number")
     self.assertEqual("feefbeadde", encodeVarLength(3735928559).encode("hex"), "4 + 1 byte number")
     self.assertEqual("ffdeadbeefdeadbeef", encodeVarLength(17275436393656397278).encode("hex"), "8 + 1 byte number")
示例#11
0
 def toWire(self, buf, opts):
     buf.write(encodeVarLength(len(self.addresses)))
     for a in self.addresses:
         a.toWire(buf, opts)
示例#12
0
 def toWire(self, buf, version):
     buf.write(encodeVarLength(len(self.addresses)))
     for a in self.addresses:
         a.toWire(buf, version)
示例#13
0
 def toWire(self, buf, unused_version):
     buf.write(encodeVarLength(len(self.hashes)))
     for h in self.hashes:
         buf.write(struct.pack("<I", h[0]))
         buf.write(h[1][::-1])