예제 #1
0
    def add_multi_sign_transaction(tx: Transaction, m: int, pub_keys: list,
                                   signer: Account):
        """
        This interface is used to generate an Transaction object which has multi signature.

        :param tx: a Transaction object which will be signed.
        :param m: the amount of signer.
        :param pub_keys: a list of public keys.
        :param signer: an Account object which will sign the transaction.
        :return: a Transaction object which has been signed.
        """
        pub_keys = ProgramBuilder.sort_publickeys(pub_keys)
        tx_hash = tx.hash256_bytes()
        sig_data = signer.generate_signature(tx_hash,
                                             signer.get_signature_scheme())
        if tx.sigs is None or len(tx.sigs) == 0:
            tx.sigs = []
        elif len(tx.sigs) >= Common.TX_MAX_SIG_SIZE:
            raise SDKException(
                ErrorCode.param_err(
                    'the number of transaction signatures should not be over 16'
                ))
        else:
            for i in range(len(tx.sigs)):
                if tx.sigs[i].public_keys == pub_keys:
                    if len(tx.sigs[i].sig_data) + 1 > len(pub_keys):
                        raise SDKException(
                            ErrorCode.param_err('too more sigData'))
                    if tx.sigs[i].M != m:
                        raise SDKException(ErrorCode.param_err('M error'))
                    tx.sigs[i].sig_data.append(sig_data)
                    return tx
        sig = Sig(pub_keys, m, [sig_data])
        tx.sigs.append(sig)
        return tx
예제 #2
0
 def add_multi_sign_transaction(self, tx: Transaction, m: int, pubkeys: [],
                                signer: Account):
     pubkeys = ProgramBuilder.sort_publickeys(pubkeys)
     tx_hash = tx.hash256_bytes()
     sig_data = signer.generate_signature(tx_hash,
                                          signer.get_signature_scheme())
     if tx.sigs is None or len(tx.sigs) == 0:
         tx.sigs = []
     elif len(tx.sigs) >= Common.TX_MAX_SIG_SIZE:
         raise SDKException(
             ErrorCode.param_err(
                 'the number of transaction signatures should not be over 16'
             ))
     else:
         for i in range(len(tx.sigs)):
             if tx.sigs[i].public_keys == pubkeys:
                 if len(tx.sigs[i].sig_data) + 1 > len(pubkeys):
                     raise SDKException(
                         ErrorCode.param_err('too more sigData'))
                 if tx.sigs[i].M != m:
                     raise SDKException(ErrorCode.param_err('M error'))
                 tx.sigs[i].sig_data.append(sig_data)
                 return tx
     sig = Sig(pubkeys, m, [sig_data])
     tx.sigs.append(sig)
     return tx
 def test_sort_public_key(self):
     pub_keys = [acc.get_public_key(), acc2.get_public_key(), acc3.get_public_key()]
     p = ProgramBuilder()
     a = p.sort_publickeys(pub_keys)
     self.assertEqual("03036c12be3726eb283d078dff481175e96224f0b0c632c7a37e10eb40fe6be889", a[0].hex())
     self.assertEqual("020f9ce29ede5f0e271b67e61b2480dccc98c3aabad095c604ef9ab1d92a475c0a", a[1].hex())
     self.assertEqual("035384561673e76c7e3003e705e4aa7aee67714c8b68d62dd1fb3221f48c5d3da0", a[2].hex())
예제 #4
0
 def test_aa(self):
     pubkeys = [
         acc.get_public_key(),
         acc2.get_public_key(),
         acc3.get_public_key()
     ]
     p = ProgramBuilder()
     a = p.sort_publickeys(pubkeys)
     print(a[0].hex())
     print(a[1].hex())
     print(a[2].hex())