def from_trytes(cls, trytes, *args, **kwargs): # type: (Type[T], Iterable[Iterable[int]], *Any, **Any) -> T """ Creates a TryteString from a sequence of trytes. :param trytes: Iterable of tryte values. In this context, a tryte is defined as a list containing 3 trits. :param args: Additional positional arguments to pass to the initializer. :param kwargs: Additional keyword arguments to pass to the initializer. References: - :py:meth:`as_trytes` """ chars = bytearray() for t in trytes: converted = int_from_trits(t) # :py:meth:`_tryte_from_int` if converted < 0: converted += 27 chars.append(AsciiTrytesCodec.alphabet[converted]) return cls(chars, *args, **kwargs)
def from_trytes(cls, trytes, *args, **kwargs): # type: (Iterable[Iterable[int]], *Any, **Any) -> TryteString """ Creates a TryteString from a sequence of trytes. :param trytes: Iterable of tryte values. In this context, a tryte is defined as a list containing 3 trits. :param args: Additional positional arguments to pass to the initializer. :param kwargs: Additional keyword arguments to pass to the initializer. References: - :py:meth:`as_trytes` """ chars = bytearray() for t in trytes: converted = int_from_trits(t) # :py:meth:`_tryte_from_int` if converted < 0: converted += 27 chars.append(AsciiTrytesCodec.alphabet[converted]) return cls(chars, *args, **kwargs)
def from_trytes(cls: Type[T], trytes: Iterable[Iterable[int]], *args: Any, **kwargs: Any) -> T: """ Creates a TryteString from a sequence of trytes. :param Iterable[Iterable[int]] trytes: Iterable of tryte values. In this context, a tryte is defined as a list containing 3 trits. :param args: Additional positional arguments to pass to the initializer. :param kwargs: Additional keyword arguments to pass to the initializer. :return: :py:class:`TryteString` object. Example usage:: from iota import TryteString message_trytes = TryteString.from_trytes( [ [1, 0, -1], [-1, 1, 0], [1, -1, 0], [-1, 1, 0], [0, 1, 0], [0, 1, 0], [-1, 1, 1], [-1, 1, 0], ] ) References: - :py:meth:`as_trytes` """ chars = bytearray() for t in trytes: converted = int_from_trits(t) # :py:meth:`_tryte_from_int` if converted < 0: converted += 27 chars.append(AsciiTrytesCodec.alphabet[converted]) return cls(chars, *args, **kwargs)
def find_milestone(hash_txn): print(datetime.datetime.now().strftime("%m-%d %H:%M") + " Child transaction: " + hash_txn) data = {'command': 'getTrytes', 'hashes': [hash_txn]} headers = {'Content-type': 'application/json', 'X-IOTA-API-Version': '1'} r = requests.post(NODE_URL, data=json.dumps(data), headers=headers) if r.status_code == requests.codes.ok: if COORDINATOR_ADDR[:80] in r.text: tag_milestone = get_txn_tag(hash_txn) index_milestone = int_from_trits( TryteString(tag_milestone).as_trits()) return index_milestone return 0
def from_tryte_string(cls, trytes, hash_=None): # type: (TrytesCompatible, Optional[TransactionHash]) -> Transaction """ Creates a Transaction object from a sequence of trytes. :param trytes: Raw trytes. Should be exactly 2673 trytes long. :param hash_: The transaction hash, if available. If not provided, it will be computed from the transaction trytes. """ tryte_string = TransactionTrytes(trytes) if not hash_: hash_trits = [0] * HASH_LENGTH # type: MutableSequence[int] sponge = Curl() sponge.absorb(tryte_string.as_trits()) sponge.squeeze(hash_trits) hash_ = TransactionHash.from_trits(hash_trits) return cls( hash_=hash_, signature_message_fragment=Fragment(tryte_string[0:2187]), address=Address(tryte_string[2187:2268]), value=int_from_trits(tryte_string[2268:2295].as_trits()), legacy_tag=Tag(tryte_string[2295:2322]), timestamp=int_from_trits(tryte_string[2322:2331].as_trits()), current_index=int_from_trits(tryte_string[2331:2340].as_trits()), last_index=int_from_trits(tryte_string[2340:2349].as_trits()), bundle_hash=BundleHash(tryte_string[2349:2430]), trunk_transaction_hash=TransactionHash(tryte_string[2430:2511]), branch_transaction_hash=TransactionHash(tryte_string[2511:2592]), tag=Tag(tryte_string[2592:2619]), attachment_timestamp=int_from_trits( tryte_string[2619:2628].as_trits()), attachment_timestamp_lower_bound=int_from_trits( tryte_string[2628:2637].as_trits()), attachment_timestamp_upper_bound=int_from_trits( tryte_string[2637:2646].as_trits()), nonce=Nonce(tryte_string[2646:2673]), )
def from_tryte_string(cls, trytes, hash_=None): # type: (TrytesCompatible, Optional[TransactionHash]) -> Transaction """ Creates a Transaction object from a sequence of trytes. :param trytes: Raw trytes. Should be exactly 2673 trytes long. :param hash_: The transaction hash, if available. If not provided, it will be computed from the transaction trytes. """ tryte_string = TransactionTrytes(trytes) if not hash_: hash_trits = [0] * HASH_LENGTH # type: MutableSequence[int] sponge = Curl() sponge.absorb(tryte_string.as_trits()) sponge.squeeze(hash_trits) hash_ = TransactionHash.from_trits(hash_trits) return cls( hash_ = hash_, signature_message_fragment = Fragment(tryte_string[0:2187]), address = Address(tryte_string[2187:2268]), value = int_from_trits(tryte_string[2268:2295].as_trits()), legacy_tag = Tag(tryte_string[2295:2322]), timestamp = int_from_trits(tryte_string[2322:2331].as_trits()), current_index = int_from_trits(tryte_string[2331:2340].as_trits()), last_index = int_from_trits(tryte_string[2340:2349].as_trits()), bundle_hash = BundleHash(tryte_string[2349:2430]), trunk_transaction_hash = TransactionHash(tryte_string[2430:2511]), branch_transaction_hash = TransactionHash(tryte_string[2511:2592]), tag = Tag(tryte_string[2592:2619]), attachment_timestamp = int_from_trits(tryte_string[2619:2628].as_trits()), attachment_timestamp_lower_bound = int_from_trits(tryte_string[2628:2637].as_trits()), attachment_timestamp_upper_bound = int_from_trits(tryte_string[2637:2646].as_trits()), nonce = Nonce(tryte_string[2646:2673]), )
def from_tryte_string(cls: Type[T], trytes: TrytesCompatible, hash_: Optional[TransactionHash] = None) -> T: """ Creates a Transaction object from a sequence of trytes. :param TrytesCompatible trytes: Raw trytes. Should be exactly 2673 trytes long. :param Optional[TransactionHash] hash_: The transaction hash, if available. If not provided, it will be computed from the transaction trytes. :return: :py:class:`Transaction` object. Example usage:: from iota import Transaction txn =\\ Transaction.from_tryte_string( b'GYPRVHBEZOOFXSHQBLCYW9ICTCISLHDBNMMVYD9JJHQMPQCTIQAQTJNNNJ9IDXLRCC' b'OYOXYPCLR9PBEY9ORZIEPPDNTI9CQWYZUOTAVBXPSBOFEQAPFLWXSWUIUSJMSJIIIZ' b'WIKIRH9GCOEVZFKNXEVCUCIIWZQCQEUVRZOCMEL9AMGXJNMLJCIA9UWGRPPHCEOPTS' b'VPKPPPCMQXYBHMSODTWUOABPKWFFFQJHCBVYXLHE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VMVIWLRTKYPI' b'XNFGYWOJSQDAXGFHKZPFLPXQEHCYEAGTIWIJEZTAVLNUMAFWGGLXMBNUQTOFCNLJTC' b'DMWVVZGVBSEBCPFSM99FLOIDTCLUGPSEDLOKZUAEVBLWNMODGZBWOVQT9DPFOTSKRA' b'BQAVOQ9RXWBMAKFYNDCZOJGTCIDMQSQQSODKDXTPFLNOKSIZEOY9HFUTLQRXQMEPGO' b'XQGLLPNSXAUCYPGZMNWMQWSWCKAQYKXJTWINSGPPZG9HLDLEAWUWEVCTVRCBDFOXKU' b'ROXH9HXXAXVPEJFRSLOGRVGYZASTEBAQNXJJROCYRTDPYFUIQJVDHAKEG9YACV9HCP' b'JUEUKOYFNWDXCCJBIFQKYOXGRDHVTHEQUMHO999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999RKWEEVD99A99999999A99999999NFDPEEZCWVYLKZGSLCQNOFUSENI' b'XRHWWTZFBXMPSQHEDFWZULBZFEOMNLRNIDQKDNNIELAOXOVMYEI9PGTKORV9IKTJZQ' b'UBQAWTKBKZ9NEZHBFIMCLV9TTNJNQZUIJDFPTTCTKBJRHAITVSKUCUEMD9M9SQJ999' b'999TKORV9IKTJZQUBQAWTKBKZ9NEZHBFIMCLV9TTNJNQZUIJDFPTTCTKBJRHAITVSK' b'UCUEMD9M9SQJ999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999' ) """ tryte_string = TransactionTrytes(trytes) if not hash_: hash_trits: MutableSequence[int] = [0] * HASH_LENGTH sponge = Curl() sponge.absorb(tryte_string.as_trits()) sponge.squeeze(hash_trits) hash_ = TransactionHash.from_trits(hash_trits) return cls( hash_=hash_, signature_message_fragment=Fragment(tryte_string[0:2187]), address=Address(tryte_string[2187:2268]), value=int_from_trits(tryte_string[2268:2295].as_trits()), legacy_tag=Tag(tryte_string[2295:2322]), timestamp=int_from_trits(tryte_string[2322:2331].as_trits()), current_index=int_from_trits(tryte_string[2331:2340].as_trits()), last_index=int_from_trits(tryte_string[2340:2349].as_trits()), bundle_hash=BundleHash(tryte_string[2349:2430]), trunk_transaction_hash=TransactionHash(tryte_string[2430:2511]), branch_transaction_hash=TransactionHash(tryte_string[2511:2592]), tag=Tag(tryte_string[2592:2619]), attachment_timestamp=int_from_trits( tryte_string[2619:2628].as_trits()), attachment_timestamp_lower_bound=int_from_trits( tryte_string[2628:2637].as_trits()), attachment_timestamp_upper_bound=int_from_trits( tryte_string[2637:2646].as_trits()), nonce=Nonce(tryte_string[2646:2673]), )
def new_seed(old_seed_trytes, used_addresses_int): old_seed_int = int_from_trits(TryteString(old_seed_trytes).as_trits()) old_seed_int += used_addresses_int return TryteString.from_trits(trits_from_int(old_seed_int))