Beispiel #1
0
    def prepare_txn2_(self, protocol_id, str_list, scan_count, min_utxo,
                      max_utxo, sort_flag, from_uock):
        if not self.WEB_SERVER_ADDR: return None

        str_list2 = []
        ii = 0  # 0x00000010 PUSH <MSG> PUSH <locate> PUSH <utf8-message>
        for s in str_list:  # 0x00000010 PUSH <PROOF> PUSH <locate> PUSH <hash32>
            if type(s) != bytes:
                s = s.encode('utf-8')
            if len(s) > 75:  # msg length must < 76 (OP_PUSHDATA1)
                print(
                    'Error: item of RETURN list should be short than 75 bytes')
                return None
            ii += len(s) + 2  # 2 is OP_PUSH(1) + LEN(1)
            if ii > 84:  # RETURN(1) + B(1) + ID(4) + 84 = 90
                print('Error: RETURN list exceed max byte length')
                return None
            str_list2.append(s)

        self._sequence = self._sequence + 1
        pay_from = [protocol.format.PayFrom(0, self._wallet.address())]

        ex_args = []
        ex_format = ''
        for s in str_list2:
            ex_format += 'BB%is' % len(s)
            ex_args.extend([76, len(s), s])  # 0x4c=76 is OP_PUSHDATA1
        ex_msg = struct.pack('<BBI' + ex_format, 106, 4, protocol_id,
                             *ex_args)  # 0x6a=106 is OP_RETURN
        pay_to = [protocol.format.PayTo(0, ex_msg)
                  ]  # value=0 means using RETURN script

        return protocol.MakeSheet(self._vcn, self._sequence, pay_from, pay_to,
                                  scan_count, min_utxo, max_utxo, sort_flag,
                                  [from_uock])
Beispiel #2
0
    def prepare_txn1_(self, pay_to, ext_in, scan_count, min_utxo, max_utxo, sort_flag, from_uocks):
        if not self.WEB_SERVER_ADDR:
            return None

        self._sequence = self._sequence + 1
        pay_from = [protocol.format.PayFrom(0, self._wallet.address())]
        if ext_in:
            for item in ext_in:
                if isinstance(item, _list_types):
                    pay_from.append(protocol.format.PayFrom(item[0], item[1]))
                else:
                    pay_from.append(item)
        if from_uocks is None:
            from_uocks = [0 for item in pay_from]
        pay_to = [protocol.format.PayTo(int(v*100000000), a)
                  for (a, v) in pay_to]
        return protocol.MakeSheet(self._vcn, self._sequence, pay_from, pay_to, scan_count, min_utxo, max_utxo, sort_flag, from_uocks)