コード例 #1
0
    def test_04_transaction_with_reference(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        global transaction2, event3, asset3
        asset3 = BBcAsset(format_type=fmt)
        asset3.add(asset_body=b'bbbbbbb', user_id=user_id)
        event3 = BBcEvent(asset_group_id=asset_group_id, format_type=fmt)
        event3.add(asset=asset3, option_approver_num_numerator=1, option_approver_num_denominator=2)
        event3.add(option_approver=user_id)
        event3.add(option_approver=user_id2)

        transaction2 = BBcTransaction(format_type=fmt)
        transaction2.add(event=event3)
        reference2 = BBcReference(asset_group_id=asset_group_id,
                                  transaction=transaction2, ref_transaction=transaction1,
                                  event_index_in_ref=0, format_type=fmt)
        transaction2.add(reference=reference2)
        dummy_cross_ref3 = BBcCrossRef(domain_id=domain_id, transaction_id=transaction1_id, format_type=fmt)
        transaction2.add(cross_ref=dummy_cross_ref3)

        sig = transaction2.sign(key_type=CURVE_TYPE, private_key=keypair1.private_key,
                                public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        reference2.add_signature(user_id=user_id, signature=sig)

        print(transaction2)
コード例 #2
0
    def test_05_transaction_with_reference2(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        asset1 = BBcAsset(id_length=ID_LENGTH)
        asset1.add(user_id=user_id, asset_body=b'ccccc')
        event = BBcEvent(asset_group_id=asset_group_id)
        event.add(asset=asset1, option_approver_num_numerator=1, option_approver_num_denominator=2)
        event.add(option_approver=user_id)
        event.add(option_approver=user_id2)

        global transaction1
        transaction1 = BBcTransaction(id_length=ID_LENGTH)
        transaction1.add(event=event)
        reference = BBcReference(asset_group_id=asset_group_id,
                                 transaction=transaction1, ref_transaction=transaction2, event_index_in_ref=0)
        transaction1.add(reference=reference)
        dummy_cross_ref = BBcCrossRef(domain_id=domain_id, transaction_id=transaction1_id)
        transaction2.add(cross_ref=dummy_cross_ref)

        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1,
                                private_key=keypair2.private_key, public_key=keypair2.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        reference.add_signature(user_id=user_id2, signature=sig)
        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1,
                                private_key=keypair1.private_key, public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        reference.add_signature(user_id=user_id, signature=sig)

        print(transaction1)
コード例 #3
0
ファイル: bbc_core.py プロジェクト: t-hashimoto249/bbc-simple
    def validate_transaction(self, txdata):
        """Validate transaction by verifying signature

        Args:
            txdata (bytes): serialized transaction data
        Returns:
            BBcTransaction: if validation fails, None returns.
        """
        txobj = BBcTransaction()
        if not txobj.deserialize(txdata):
            self.stats.update_stats_increment("transaction", "invalid", 1)
            self.logger.error("Fail to deserialize transaction data")
            return None
        txobj.digest()

        if bbclib.validate_transaction_object(txobj):
            return txobj
        else:
            self.stats.update_stats_increment("transaction", "invalid", 1)
            return None
コード例 #4
0
    def test_06_transaction_with_witness(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        witness = BBcWitness(format_type=fmt)

        global transaction1
        transaction1 = BBcTransaction(format_type=fmt)
        transaction1.add(witness=witness)

        witness.add_witness(user_id)
        witness.add_witness(user_id2)

        sig = transaction1.sign(key_type=CURVE_TYPE,
                                private_key=keypair2.private_key, public_key=keypair2.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        witness.add_signature(user_id=user_id2, signature=sig)

        sig = transaction1.sign(key_type=CURVE_TYPE,
                                private_key=keypair1.private_key, public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        witness.add_signature(user_id=user_id, signature=sig)

        print(transaction1)
コード例 #5
0
    def test_06_transaction_with_witness(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        witness = BBcWitness()

        global transaction1
        transaction1 = BBcTransaction(id_length=ID_LENGTH)
        transaction1.add(witness=witness)

        witness.add_witness(user_id)
        witness.add_witness(user_id2)

        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1,
                                private_key=keypair2.private_key, public_key=keypair2.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        witness.add_signature(user_id=user_id2, signature=sig)

        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1,
                                private_key=keypair1.private_key, public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        witness.add_signature(user_id=user_id, signature=sig)

        print(transaction1)
コード例 #6
0
ファイル: bbc_core.py プロジェクト: t-hashimoto249/bbc-simple
    def __init__(self,
                 core_port=None,
                 workingdir=".bbc1",
                 configfile=None,
                 ipv6=False,
                 server_start=True):
        self.logger = get_fluent_logger(name="bbc_core")
        self.stats = bbc_stats.BBcStats()
        self.config = BBcConfig(workingdir, configfile)
        conf = self.config.get_config()
        self.ipv6 = ipv6
        self.logger.debug("config = %s" % conf)
        self.test_tx_obj = BBcTransaction()
        self.networking = bbc_network.BBcNetwork(self.config, core=self)
        for domain_id_str in conf['domains'].keys():
            domain_id = bbclib.convert_idstring_to_bytes(domain_id_str)
            c = self.config.get_domain_config(domain_id)
            self.networking.create_domain(domain_id=domain_id, config=c)

        gevent.signal(signal.SIGINT, self.quit_program)
        if server_start:
            self._start_server(core_port)
コード例 #7
0
    def test_03_transaction_1(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        global transaction1
        transaction1 = BBcTransaction(format_type=fmt)
        transaction1.add(event=[event1, event2])
        dummy_cross_ref1 = BBcCrossRef(domain_id=domain_id, transaction_id=transaction1_id, format_type=fmt)
        transaction1.add(cross_ref=dummy_cross_ref1)
        dummy_cross_ref2 = BBcCrossRef(domain_id=domain_id, transaction_id=transaction2_id, format_type=fmt)
        transaction1.add(cross_ref=dummy_cross_ref2)
        witness = BBcWitness(format_type=fmt)
        transaction1.add(witness=witness)

        sig = transaction1.sign(key_type=CURVE_TYPE, private_key=keypair1.private_key,
                                public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        transaction1.add_signature(signature=sig)

        # --- for checking serialization function ---
        digest = transaction1.digest()
        dat = transaction1.serialize()
        print("Digest:", binascii.b2a_hex(digest))
        print("Serialized data:", binascii.b2a_hex(dat))

        transaction_tmp = BBcTransaction()
        transaction_tmp.deserialize(dat)
        transaction1 = transaction_tmp
        #transaction1.events[1].asset.add(asset_file=asset_content)
        print("transaction_id:", binascii.b2a_hex(transaction1.transaction_id))
        print("transaction_id (recalc2):", binascii.b2a_hex(transaction1.digest()))
        asset_tmp = transaction1.events[0].asset
        print("asset_id1:", binascii.b2a_hex(asset_tmp.asset_id))
        asset_tmp = transaction1.events[1].asset
        print("asset_id2:", binascii.b2a_hex(asset_tmp.asset_id))
        print(" --> asset_file_size:", asset_tmp.asset_file_size)
        print(" --> asset_file_digest:", binascii.b2a_hex(asset_tmp.asset_file_digest))
        ret = asset_tmp.recover_asset_file(asset_content)
        assert ret
        print(" --> asset_file (after recover):", asset_tmp.asset_file)