4 # dcrun - Fetch and execute programs from the Dogeparty blockchain.
5 # Copyright (C) 2014 Rob Myers rob@robmyers.org
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from optparse import OptionParser
23 import dogecode.brainfuck, dogecode.network, dogecode.translation
26 usage = "usage: %prog [options] source_address"
27 parser = OptionParser(usage=usage)
28 parser.add_option("-r", "--rpc-host", dest="host", default="localhost",
29 help="the Dogeparty json-rpc host, probably localhost")
30 parser.add_option("-p", "--rpc-port", dest="port", default="5000",
31 help="the Dogeparty json-rpc port")
32 parser.add_option("-u", "--rpc-user", dest="user", default="rpc",
33 help="the Dogeparty json-rpc username")
34 parser.add_option("-w", "--rpc-password", dest="password", default=None,
35 help="the Dogeparty json-rpc password")
36 parser.add_option("-d", "--dump-code",
37 action="store_true", dest="dump", default=False,
38 help="dump the program code to STDERR")
39 opts, args = parser.parse_args()
41 parser.error("must supply source_address")
45 (opts, args) = getopts()
47 #TODO: make sure address is valid
50 password = opts.password
52 print("Enter Dogeparty json-rpc password:")
53 password = sys.stdin.readline()
56 api = dogecode.network.DogepartyApi(user, password, host, port)
57 tokens = api.token_transactions_for_address(address)
58 pairs = dogecode.translation.json_token_amounts_to_pairs(tokens)
59 code = dogecode.translation.token_runs_to_code(pairs)
61 print(code, file=sys.stderr)
63 dogecode.brainfuck.evaluate(code)
64 except Exception as e:
65 print("Error evaluating program after fetching.", file=sys.stderr)
66 print("Program was: {}".format(code), file=sys.stderr)
67 print("Exception was: {}".format(e), file=sys.stderr)
69 if __name__ == "__main__":