async def load_attest_files_for_recovery_spend(self, filenames): spend_bundle_list = [] info_dict = {} try: for i in filenames: f = open(i) info = f.read().split(":") info_dict[info[0]] = [ bytes.fromhex(info[2]), bytes.fromhex(info[3]), uint64(info[4]), ] new_sb = SpendBundle.from_bytes(bytes.fromhex(info[1])) spend_bundle_list.append(new_sb) f.close() # info_dict {0xidentity: "(0xparent_info 0xinnerpuz amount)"} my_recovery_list: List[bytes] = self.did_info.backup_ids # convert info dict into recovery list - same order as wallet info_list = [] for entry in my_recovery_list: if entry.hex() in info_dict: info_list.append([ info_dict[entry.hex()][0], info_dict[entry.hex()][1], info_dict[entry.hex()][2], ]) else: info_list.append([]) message_spend_bundle = SpendBundle.aggregate(spend_bundle_list) return info_list, message_spend_bundle except Exception: raise
def test_version_override(self): coin_spend = CoinSpend( COIN, OFFER_MOD, SOLUTION, ) spend_bundle = SpendBundle([coin_spend], G2Element()) compressed = compress_object_with_puzzles(bytes(spend_bundle), LATEST_VERSION) compressed_earlier = compress_object_with_puzzles( bytes(spend_bundle), 1) assert len(bytes(spend_bundle)) > len(bytes(compressed)) assert spend_bundle == SpendBundle.from_bytes( decompress_object_with_puzzles(compressed)) assert spend_bundle == SpendBundle.from_bytes( decompress_object_with_puzzles(compressed_earlier)) assert len(bytes(compressed_earlier)) > len(bytes(compressed))
def validate_transaction_multiprocess( constants_dict: Dict, spend_bundle_bytes: bytes, ) -> bytes: constants: ConsensusConstants = dataclass_from_dict(ConsensusConstants, constants_dict) # Calculate the cost and fees program = best_solution_program(SpendBundle.from_bytes(spend_bundle_bytes)) # npc contains names of the coins removed, puzzle_hashes and their spend conditions return bytes(calculate_cost_of_program(program, constants.CLVM_COST_RATIO_CONSTANT, True))
def get_npc_multiprocess(spend_bundle_bytes: bytes, max_cost: int, cost_per_byte: int) -> bytes: program = simple_solution_generator( SpendBundle.from_bytes(spend_bundle_bytes)) # npc contains names of the coins removed, puzzle_hashes and their spend conditions return bytes( get_name_puzzle_conditions(program, max_cost, cost_per_byte=cost_per_byte, safe_mode=True, rust_checker=True))
def validate_clvm_and_signature( spend_bundle_bytes: bytes, max_cost: int, cost_per_byte: int, additional_data: bytes ) -> Tuple[Optional[Err], bytes, Dict[bytes, bytes]]: """ Validates CLVM and aggregate signature for a spendbundle. This is meant to be called under a ProcessPoolExecutor in order to validate the heavy parts of a transction in a different thread. Returns an optional error, the NPCResult and a cache of the new pairings validated (if not error) """ try: bundle: SpendBundle = SpendBundle.from_bytes(spend_bundle_bytes) program = simple_solution_generator(bundle) # npc contains names of the coins removed, puzzle_hashes and their spend conditions result: NPCResult = get_name_puzzle_conditions( program, max_cost, cost_per_byte=cost_per_byte, mempool_mode=True) if result.error is not None: return Err(result.error), b"", {} pks: List[G1Element] = [] msgs: List[bytes32] = [] # TODO: address hint error and remove ignore # error: Incompatible types in assignment (expression has type "List[bytes]", variable has type # "List[bytes32]") [assignment] pks, msgs = pkm_pairs(result.npc_list, additional_data) # type: ignore[assignment] # Verify aggregated signature cache: LRUCache = LRUCache(10000) if not cached_bls.aggregate_verify( pks, msgs, bundle.aggregated_signature, True, cache): return Err.BAD_AGGREGATE_SIGNATURE, b"", {} new_cache_entries: Dict[bytes, bytes] = {} for k, v in cache.cache.items(): new_cache_entries[k] = bytes(v) except ValidationError as e: return e.code, b"", {} except Exception: return Err.UNKNOWN, b"", {} return None, bytes(result), new_cache_entries
def from_bytes(cls, as_bytes: bytes) -> "Offer": # Because of the __bytes__ method, we need to parse the dummy CoinSpends as `requested_payments` bundle = SpendBundle.from_bytes(as_bytes) return cls.from_spend_bundle(bundle)
def stream(self, f): as_spend_bundle = SpendBundle.from_bytes(bytes(self)) as_spend_bundle.stream(f)
def get_npc_multiprocess(spend_bundle_bytes: bytes, ) -> bytes: program = simple_solution_generator( SpendBundle.from_bytes(spend_bundle_bytes)) # npc contains names of the coins removed, puzzle_hashes and their spend conditions return bytes(get_name_puzzle_conditions(program, True))