def prepare_transaction(asset_group, client, datnum, txid_pointer=None, no_cross_ref=False): user_id = client['user_id'] kp = client['keypair'] txobj = bbclib.BBcTransaction() rtn = bbclib.BBcRelation() asset = bbclib.BBcAsset() asset.add(user_id=user_id, asset_body=b'data=%d' % datnum) rtn.add(asset_group_id=asset_group, asset=asset) if txid_pointer is not None: ptr = bbclib.BBcPointer() ptr.add(transaction_id=txid_pointer) rtn.add(pointer=ptr) wit = bbclib.BBcWitness() txobj.add(relation=rtn, witness=wit) wit.add_witness(user_id) if not no_cross_ref: client['app'].include_cross_ref(txobj) sig = txobj.sign(key_type=bbclib.KeyType.ECDSA_SECP256k1, keypair=kp) txobj.add_signature(user_id=user_id, signature=sig) txobj.digest() return txobj
def make_event(self, ref_indice, user_id, body): event = bbclib.BBcEvent(asset_group_id=self.mint_id) for i in ref_indice: event.add(reference_index=i) event.add(mandatory_approver=self.mint_id) event.add(mandatory_approver=user_id) event.add(asset=bbclib.BBcAsset()) event.asset.add(user_id=user_id, asset_body=body.serialize()) return event
def test_01_setup(self): print("\n-----", sys._getframe().f_code.co_name, "-----") global data_handler dummycore = DummyCore() conf = config["domains"][bbclib.convert_id_to_string(domain_id)] data_handler = DataHandler(networking=dummycore.networking, config=conf, workingdir="testdir", domain_id=domain_id) global transactions for i in range(10): txobj = bbclib.BBcTransaction() evt = bbclib.BBcEvent() evt.asset_group_id = asset_group_id1 evt.asset = bbclib.BBcAsset() evt.asset.add(user_id=user_id1, asset_body=b'aaaaaa') rtn = bbclib.BBcRelation() rtn.asset_group_id = asset_group_id2 rtn.asset = bbclib.BBcAsset() rtn.asset.add(user_id=user_id2, asset_body=b'bbbbbb', asset_file=b'cccccccccc%d' % i) ptr = bbclib.BBcPointer() ptr.add(transaction_id=txid1) rtn.add(pointer=ptr) if i > 0: ptr = bbclib.BBcPointer() ptr.add(transaction_id=transactions[-1].transaction_id) rtn.add(pointer=ptr) wit = bbclib.BBcWitness() txobj.add(event=evt, relation=rtn, witness=wit) wit.add_witness(user_id1) sig = txobj.sign(key_type=bbclib.KeyType.ECDSA_SECP256k1, private_key=keypair1.private_key, public_key=keypair1.public_key) txobj.add_signature(user_id=user_id1, signature=sig) txobj.digest() transactions.append(txobj)
def prepare_transactions(): global transactions for i in range(client_num * 2): txobj = bbclib.BBcTransaction() evt = bbclib.BBcEvent() evt.asset_group_id = asset_group_id1 evt.asset = bbclib.BBcAsset() evt.asset.add(user_id=user_id1, asset_body=b'aaaaaa') rtn = bbclib.BBcRelation() rtn.asset_group_id = asset_group_id2 rtn.asset = bbclib.BBcAsset() rtn.asset.add(user_id=user_id2, asset_body=b'bbbbbb', asset_file=b'cccccccccc%d' % i) ptr = bbclib.BBcPointer() ptr.add(transaction_id=txid1) rtn.add(pointer=ptr) rtn2 = bbclib.BBcRelation() rtn2.asset_group_id = asset_group_id3 rtn2.asset = bbclib.BBcAsset() rtn2.asset.add(user_id=user_id2, asset_body=b'cccccc') if i > 0: ptr = bbclib.BBcPointer() ptr.add(transaction_id=transactions[-1].transaction_id) rtn.add(pointer=ptr) wit = bbclib.BBcWitness() if i % 2 == 0: txobj.add(event=evt, relation=[rtn, rtn2], witness=wit) else: txobj.add(event=evt, relation=rtn, witness=wit) wit.add_witness(user_id1) sig = txobj.sign(key_type=bbclib.KeyType.ECDSA_SECP256k1, private_key=keypair1.private_key, public_key=keypair1.public_key) txobj.add_signature(user_id=user_id1, signature=sig) txobj.digest() transactions.append(txobj)
def test_07_1_insert_transaction(self): print("\n-----", sys._getframe().f_code.co_name, "-----") global transaction transaction = bbclib.BBcTransaction() rtn = bbclib.BBcRelation() rtn.asset_group_id = asset_group_id rtn.asset = bbclib.BBcAsset() rtn.asset.add(user_id=user_id1, asset_body=b'bbbbbb', asset_file=b'cccccccccc') ptr = bbclib.BBcPointer() ptr.add(transaction_id=txid1) rtn.add(pointer=ptr) wit = bbclib.BBcWitness() transaction.add(relation=rtn, witness=wit) wit.add_witness(user_id1) sig = transaction.sign(key_type=bbclib.KeyType.ECDSA_SECP256k1, private_key=keypair.private_key, public_key=keypair.public_key) transaction.add_signature(user_id=user_id1, signature=sig) transaction.digest() asset_files = { transaction.relations[0].asset.asset_id: transaction.relations[0].asset.asset_file, } ret = cores[0].insert_transaction(domain_id, transaction.serialize(), asset_files) assert ret[KeyType.transaction_id] == transaction.transaction_id ret = cores[0].search_transaction_by_txid(domain_id, transaction.transaction_id) assert ret is not None assert len(ret[KeyType.all_asset_files]) == 1 print(ret) print("-- wait 2 seconds --") time.sleep(2)