Пример #1
0
 def __init__(self):
     super(GetNodeInfoResponseFilter, self).__init__({
         'latestMilestone':
         f.ByteString(encoding='ascii') | Trytes(TransactionHash),
         'latestSolidSubtangleMilestone':
         f.ByteString(encoding='ascii') | Trytes(TransactionHash),
     })
Пример #2
0
 def __init__(self):
     super(GetTransactionsToApproveResponseFilter, self).__init__({
         'branchTransaction':
         f.ByteString(encoding='ascii') | Trytes(TransactionHash),
         'trunkTransaction':
         f.ByteString(encoding='ascii') | Trytes(TransactionHash),
     })
Пример #3
0
 def __init__(self):
     super(GetBalancesResponseFilter, self).__init__({
         'balances':
         f.Array | f.FilterRepeater(f.Int),
         'milestone':
         f.ByteString(encoding='ascii') | Trytes(result_type=Address),
     })
Пример #4
0
 def __init__(self) -> None:
     super(FindTransactionsResponseFilter, self).__init__({
         'hashes':
         f.FilterRepeater(
             f.ByteString(encoding='ascii') | Trytes(TransactionHash))
         | f.Optional(default=[]),
     })
Пример #5
0
 def __init__(self):
     super(GetTipsResponseFilter, self).__init__({
         'hashes': (f.Array
                    | f.FilterRepeater(
                        f.ByteString(encoding='ascii')
                        | Trytes(result_type=TransactionHash))),
     })
Пример #6
0
 def __init__(self):
     super(AttachToTangleResponseFilter, self).__init__({
         'trytes':
         f.FilterRepeater(
             f.ByteString(encoding='ascii')
             | Trytes(result_type=TransactionTrytes)),
     })
Пример #7
0
 def __init__(self) -> None:
     super(GetBalancesResponseFilter, self).__init__({
         'balances':
         f.Array | f.FilterRepeater(f.Int),
         'references':
         f.Array | f.FilterRepeater(
             f.ByteString(encoding='ascii') | Trytes(TransactionHash)),
     })
Пример #8
0
 def __init__(self) -> None:
     super(AttachToTangleResponseFilter, self).__init__({
         'trytes':
             f.FilterRepeater(
                 f.ByteString(encoding='ascii') |
                 Trytes(TransactionTrytes),
             ),
     })
Пример #9
0
 def __init__(self) -> None:
     super(GetTipsResponseFilter, self).__init__({
         'hashes':
         f.Array | f.FilterRepeater(
             f.ByteString(encoding='ascii') | Trytes(TransactionHash), ),
     })
Пример #10
0
    def execute(self, api, **arguments):
        # type: (Iota, ...) -> int
        channel_key_index = arguments['channel_key_index']  # type: int
        count = arguments['count']  # type: int
        depth = arguments['depth']  # type: int
        dry_run = arguments['dry_run']  # type: bool
        mam_encrypt_path = arguments['mam_encrypt_path']  # type: Text
        min_weight_magnitude = arguments['min_weight_magnitude']  # type: int
        message_encoding = arguments['message_encoding']  # type: Text
        message_file = arguments['message_file']  # type: Optional[Text]
        security_level = arguments['security_level']  # type: int
        start = arguments['start']  # type: int

        if message_file:
            with codecs.open(
                    message_file, 'r',
                    message_encoding) as f_:  # type: codecs.StreamReaderWriter
                message = f_.read()

        else:
            self.stdout.write(
                'Enter message to send.  Press Ctrl-D on a blank line when done.\n\n',
            )

            message = self.stdin.read().strip()
            self.stdout.write('\n')

        # Generating the encrypted message may take a little while, so we
        # should provide some feedback to the user so that they know that
        # their input is being processed (this is especially important if
        # the user typed in their message, so that they don't press ^D
        # again, thinking that the program didn't register the first one).
        self.stdout.write('Encrypting message...\n')

        proc =\
          run(
            args = [
              # mam_encrypt.js
              mam_encrypt_path,

              # Required arguments
              binary_type(api.seed),
              message,

              # Options
              '--channel-key-index', text_type(channel_key_index),
              '--start', text_type(start),
              '--count', text_type(count),
              '--security-level', text_type(security_level),
            ],

            check   = True,
            stdout  = PIPE,
            stderr  = self.stderr,
          )

        # The output of the JS script is a collection of transaction
        # trytes, encoded as JSON.
        filter_ =\
          f.FilterRunner(
            starting_filter =
                f.Required
              | f.Unicode
              | f.JsonDecode
              | f.Array
              | f.FilterRepeater(
                    f.ByteString(encoding='ascii')
                  | Trytes(result_type=TransactionTrytes)
                ),

            incoming_data = proc.stdout,
          )

        if not filter_.is_valid():
            self.stderr.write(
                'Invalid output from {mam_encrypt_path}:\n'
                '\n'
                'Output:\n'
                '{output}\n'
                '\n'
                'Errors:\n'
                '{errors}\n'.format(
                    errors=pformat(filter_.get_errors(with_context=True)),
                    mam_encrypt_path=mam_encrypt_path,
                    output=proc.stdout,
                ), )

            return 2

        transaction_trytes = filter_.cleaned_data  # type: List[TransactionTrytes]

        bundle = Bundle.from_tryte_strings(transaction_trytes)

        if dry_run:
            self.stdout.write('Transactions:\n\n')
            self.stdout.write(json.dumps(bundle, cls=JsonEncoder, indent=2))
        else:
            api.send_trytes(
                depth=depth,
                trytes=transaction_trytes,
                min_weight_magnitude=min_weight_magnitude,
            )

            self.stdout.write('Message broadcast successfully!\n')
            self.stdout.write(
                'Bundle ID: {bundle_hash}\n'.format(
                    bundle_hash=bundle.hash, ), )

        return 0
Пример #11
0
 def __init__(self):
     super(GetTrytesResponseFilter, self).__init__({
         'trytes':
         f.Array
         | f.FilterRepeater(f.ByteString(encoding='ascii') | Trytes),
     })