コード例 #1
0
ファイル: daemonping.py プロジェクト: solartune/monero-python
def get_daemon():
    argsparser = argparse.ArgumentParser(description="Display daemon info")
    argsparser.add_argument('daemon_rpc_url',
                            nargs='?',
                            type=url_data,
                            default='127.0.0.1:18081',
                            help="Daemon RPC URL [host[:port]]")
    argsparser.add_argument('-t',
                            dest='timeout',
                            type=int,
                            default=30,
                            help="Request timeout")
    argsparser.add_argument(
        '-v',
        dest='verbosity',
        action='count',
        default=0,
        help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG")
    args = argsparser.parse_args()
    level = logging.WARNING
    if args.verbosity == 1:
        level = logging.INFO
    elif args.verbosity > 1:
        level = logging.DEBUG
    logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
    return Daemon(JSONRPCDaemon(timeout=args.timeout, **args.daemon_rpc_url))
コード例 #2
0
    def test_transaction_not_pruned(self):
        daemon_no_prune = Daemon(JSONRPCDaemon(prune_transactions=False))
        responses.add(responses.POST,
                      self.transactions_url,
                      json=self._read('test_transactions_single.json'),
                      status=200)

        tx = daemon_no_prune.transactions(
            'bbc10f5944cc3e88be576d2ab9f4f5ab5a2b46d95a7cab1027bc15c17393102c'
        )[0]
        self.assertIsNotNone(tx.blob)
        self.assertIs(type(tx.blob), bytes)
コード例 #3
0
class MoneroAdapter(Adapter):
    chain = Blockchain.MONERO
    credentials = database.find_credentials(Blockchain.MONERO)
    wallet = Wallet(
        JSONRPCWallet(protocol='http', host='127.0.0.1', port=28088))
    # wallet = Wallet(JSONRPCWallet(protocol=’http’, host=’127.0.0.1’, port=18088, path=’/json_rpc’, user=”,password=”, timeout=30, verify_ssl_certs=True))
    daemon = Daemon(JSONRPCDaemon(port=28081))
    address = credentials['address']
    key = credentials['key']

    # ---STORE---
    @classmethod
    def create_transaction(cls, text):
        p1 = PaymentID(cls.to_hex(text))
        if p1.is_short():
            sender = cls.wallet.addresses()[0]
            sender = sender.with_payment_id(p1)
            transaction = cls.wallet.transfer(sender,
                                              Decimal('0.000000000001'))
            return transaction

    @classmethod
    def get_transaction_count(cls):
        return len(w.outgoing())

    @staticmethod
    def to_hex(text):
        s = text.encode('utf-8')
        return s.hex()

    @classmethod
    def send_raw_transaction(cls, transaction):
        transaction_hash = daemon.send_transaction(transaction)
        return transaction_hash

    @classmethod
    def sign_transaction(cls, transaction):
        return transaction

    @staticmethod
    def add_transaction_to_database(transaction_hash):
        database.add_transaction(transaction_hash, Blockchain.MONERO)

    # ---RETRIEVE---
    @classmethod
    def get_transaction(cls, transaction_hash):
        for item in cls.wallet.outgoing():
            if transaction_hash in str(item):
                return item
コード例 #4
0
def cache_blocks(last=None, end=None):
    daemon = Daemon(JSONRPCDaemon(host='127.0.0.1', port=18081))
    new = []
    if not end:
        end = daemon.height() - 1
    if not last:
        last = int(get_csv("blocks")[-1][1])
    while end > last:
        last += 1
        data = daemon.block(height=last)
        new.append([data.timestamp,data.height,data.difficulty,float(data.reward), \
            data.num_txes,float(data.fee),data.size,data.nonce,data.version[0],data.version[1]])
    if new:
        cache(new, "blocks")
        return True
    else:
        return False
コード例 #5
0
ファイル: cryptonode.py プロジェクト: project-ecc/ecchat
    def __init__(self, symbol, rpc_address, rpc_daemon, rpc_user, rpc_pass):

        super().__init__(symbol, rpc_address, rpc_user, rpc_pass)

        (host, port) = tuple(rpc_address.split(':'))

        try:

            self.wallet = Wallet(host=host,
                                 port=port,
                                 user=rpc_user,
                                 password=rpc_pass)

        except monero.backends.jsonrpc.exceptions.Unauthorized:

            raise cryptoNodeException(
                'Failed to connect - error in rpcuser or rpcpassword for {} wallet'
                .format(self.symbol))

        except requests.exceptions.ConnectTimeout:

            raise cryptoNodeException(
                'Failed to connect - check that {} wallet is running'.format(
                    self.symbol))

        (host, port) = tuple(rpc_daemon.split(':'))

        try:

            self.daemon = Daemon(host=host, port=port)

        except monero.backends.jsonrpc.exceptions.Unauthorized:

            raise cryptoNodeException(
                'Failed to connect - error in rpcuser or rpcpassword for {} daemon'
                .format(self.symbol))

        except requests.exceptions.ConnectTimeout:

            raise cryptoNodeException(
                'Failed to connect - check that {} daemon is running'.format(
                    self.symbol))
コード例 #6
0
    def __init__(self):
        self.host = settings.DAEMON_HOST
        self.port = settings.DAEMON_PORT
        self.username = settings.DAEMON_USER
        self.password = settings.DAEMON_PASS
        self.daemon = Daemon(
            JSONRPCDaemon(host=self.host,
                          port=self.port,
                          user=self.username,
                          password=self.password,
                          timeout=5))

        try:
            status = self.daemon.info()['status']
            if status == 'OK':
                self.connected = True
            else:
                self.connected = False
        except:
            self.connected = False
コード例 #7
0
def get_daemon():
    argsparser = argparse.ArgumentParser(description="Display daemon info")
    argsparser.add_argument(
        "daemon_rpc_url",
        nargs="?",
        type=url_data,
        default="127.0.0.1:18081",
        help="Daemon RPC URL [user[:password]@]host[:port]",
    )
    argsparser.add_argument("-p",
                            dest="proxy_url",
                            nargs="?",
                            type=str,
                            default=None,
                            help="Proxy URL")
    argsparser.add_argument("-t",
                            dest="timeout",
                            type=int,
                            default=30,
                            help="Request timeout")
    argsparser.add_argument(
        "-v",
        dest="verbosity",
        action="count",
        default=0,
        help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG",
    )
    args = argsparser.parse_args()
    level = logging.WARNING
    if args.verbosity == 1:
        level = logging.INFO
    elif args.verbosity > 1:
        level = logging.DEBUG
    logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
    return Daemon(
        JSONRPCDaemon(timeout=args.timeout,
                      proxy_url=args.proxy_url,
                      **args.daemon_rpc_url))
コード例 #8
0
 def setUp(self):
     self.daemon = Daemon(JSONRPCDaemon())
コード例 #9
0
    dest='relay',
    action='store_false',
    help=
    "Do not relay the transaction (it will stay at the node unless mined or expired)"
)
args = argsparser.parse_args()
level = logging.WARNING
if args.verbosity == 1:
    level = logging.INFO
elif args.verbosity > 1:
    level = logging.DEBUG
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
if args.tx_filenames:
    blobs = [(f, open(f, 'r').read()) for f in args.tx_filenames]
else:
    blobs = [('transaction', sys.stdin.read())]
d = Daemon(JSONRPCDaemon(**args.daemon_rpc_url))
for name, blob in blobs:
    logging.debug("Sending {}".format(name))
    tx = Transaction(blob=blob)
    try:
        res = d.send_transaction(tx, relay=args.relay)
    except exceptions.TransactionBroadcastError as e:
        print("{} not sent, reason: {}".format(name, e.details['reason']))
        logging.debug(e.details)
        continue
    if res['not_relayed']:
        print("{} not relayed".format(name))
    else:
        print("{} successfully sent".format(name))
コード例 #10
0
ファイル: pushtx.py プロジェクト: successor1/wownero-python
    "Do not relay the transaction (it will stay at the node unless mined or expired)"
)
args = argsparser.parse_args()
level = logging.WARNING
if args.verbosity == 1:
    level = logging.INFO
elif args.verbosity > 1:
    level = logging.DEBUG
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
if args.tx_filenames:
    blobs = [(f, open(f, 'rb').read()) for f in args.tx_filenames]
else:
    blobs = [('transaction',
              sys.stdin.buffer.read() if six.PY3 else sys.stdin.read())]
d = Daemon(
    JSONRPCDaemon(timeout=args.timeout,
                  proxy_url=args.proxy_url,
                  **args.daemon_rpc_url))
for name, blob in blobs:
    logging.debug("Sending {}".format(name))
    tx = Transaction(blob=blob)
    try:
        res = d.send_transaction(tx, relay=args.relay)
    except exceptions.TransactionBroadcastError as e:
        print("{} not sent, reason: {}".format(name, e.details['reason']))
        logging.debug(e.details)
        continue
    if res['not_relayed']:
        print("{} not relayed".format(name))
    else:
        print("{} successfully sent".format(name))
コード例 #11
0
 def test_multiple_outputs(self):
     daemon = Daemon(JSONRPCDaemon(host="127.0.0.1", port=38081))
     responses.add(responses.POST,
                   self.wallet_jsonrpc_url,
                   json=self._read(
                       "test_multiple_outputs-wallet-00-get_accounts.json"),
                   status=200)
     responses.add(
         responses.POST,
         self.wallet_jsonrpc_url,
         json=self._read("test_multiple_outputs-wallet-01-query_key.json"),
         status=200)
     responses.add(
         responses.POST,
         self.wallet_jsonrpc_url,
         json=self._read(
             "test_multiple_outputs-wallet-02-addresses-account-0.json"),
         status=200)
     responses.add(
         responses.POST,
         self.wallet_jsonrpc_url,
         json=self._read(
             "test_multiple_outputs-wallet-02-addresses-account-1.json"),
         status=200)
     wallet = Wallet(JSONRPCWallet(host="127.0.0.1", port=38083))
     responses.add(
         responses.POST,
         self.daemon_transactions_url,
         json=self._read(
             "test_multiple_outputs-daemon-00-get_transactions.json"),
         status=200)
     tx = daemon.transactions(
         "f79a10256859058b3961254a35a97a3d4d5d40e080c6275a3f9779acde73ca8d"
     )[0]
     outs = tx.outputs(wallet=wallet)
     self.assertEqual(len(outs), 5)
     self.assertEqual(
         outs[0].stealth_address,
         "d3eb42322566c1d48685ee0d1ad7aed2ba6210291a785ec051d8b13ae797d202")
     self.assertEqual(
         outs[1].stealth_address,
         "5bda44d7953e27b84022399850b59ed87408facdf00bbd1a2d4fda4bf9ebf72f")
     self.assertEqual(
         outs[2].stealth_address,
         "4c79c14d5d78696e72959a28a734ec192059ebabb931040b5a0714c67b507e76")
     self.assertEqual(
         outs[3].stealth_address,
         "64de2b358cdf96d498a9688edafcc0e25c60179e813304747524c876655a8e55")
     self.assertEqual(
         outs[4].stealth_address,
         "966240954892294091a48c599c6db2b028e265c67677ed113d2263a7538f9a43")
     self.assertIsNotNone(outs[0].payment)
     self.assertIsNone(
         outs[1].payment)  # FIXME: isn't that change we should recognize?
     self.assertIsNotNone(outs[2].payment)
     self.assertIsNotNone(outs[3].payment)
     self.assertIsNotNone(outs[4].payment)
     self.assertEqual(outs[0].amount, outs[0].payment.amount)
     self.assertEqual(outs[2].amount, outs[2].payment.amount)
     self.assertEqual(outs[3].amount, outs[3].payment.amount)
     self.assertEqual(outs[4].amount, outs[4].payment.amount)
     self.assertEqual(outs[0].amount, Decimal(4))
     self.assertIsNone(outs[1].amount)
     self.assertEqual(outs[2].amount, Decimal(1))
     self.assertEqual(outs[3].amount, Decimal(2))
     self.assertEqual(outs[4].amount, Decimal(8))
     self.assertEqual(
         outs[0].payment.local_address,
         "76Qt2xMZ3m7b2tagubEgkvG81pwf9P3JYdxR65H2BEv8c79A9pCBTacEFv87tfdcqXRemBsZLFVGHTWbqBpkoBJENBoJJS9"
     )
     self.assertEqual(
         outs[2].payment.local_address,
         "78zGgzb45TEL8uvRFjCayUjHS98RFry1f7P4PE4LU7oeLh42s9AtP8fYXVzWqUW4r3Nz4g3V64w9RSiV7o3zUbPZVs5DVaU"
     )
     self.assertEqual(
         outs[3].payment.local_address,
         "73ndji4W2bu4WED87rJDVALMvUsZLLYstZsigbcGfb5YG9SuNyCSYk7Qbttez2mXciKtWRzRN9aYGJbF9TPBidNQNZppnFw"
     )
     self.assertEqual(
         outs[4].payment.local_address,
         "7BJxHKTa4p5USJ9Z5GY15ZARXL6Qe84qT3FnWkMbSJSoEj9ugGjnpQ1N9H1jqkjsTzLiN5VTbCP8f4MYYVPAcXhr36bHXzP"
     )
     self.assertEqual(
         repr(outs[0]),
         "d3eb42322566c1d48685ee0d1ad7aed2ba6210291a785ec051d8b13ae797d202, 4.000000000000 "
         "to [76Qt2x]")
コード例 #12
0
    def test_init_default_backend(self):
        daemon1 = Daemon(host='localhost')
        daemon2 = Daemon()

        with self.assertRaises(ValueError):
            daemon3 = Daemon(backend=JSONRPCDaemon(), port=18089)
コード例 #13
0
    def setUp(self):
        self.daemon = Daemon(JSONRPCDaemon())

        # this is disabled b/c raw_request logs errors
        logging.getLogger('monero.backends.jsonrpc.daemon').disabled = True
コード例 #14
0
    dest='relay',
    action='store_false',
    help=
    "Do not relay the transaction (it will stay at the node unless mined or expired)"
)
args = argsparser.parse_args()
level = logging.WARNING
if args.verbosity == 1:
    level = logging.INFO
elif args.verbosity > 1:
    level = logging.DEBUG
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
if args.tx_filenames:
    blobs = [(f, open(f, 'r').read()) for f in args.tx_filenames]
else:
    blobs = [('transaction', sys.stdin.read())]
d = Daemon(JSONRPCDaemon(timeout=args.timeout, **args.daemon_rpc_url))
for name, blob in blobs:
    logging.debug("Sending {}".format(name))
    tx = Transaction(blob=blob)
    try:
        res = d.send_transaction(tx, relay=args.relay)
    except exceptions.TransactionBroadcastError as e:
        print("{} not sent, reason: {}".format(name, e.details['reason']))
        logging.debug(e.details)
        continue
    if res['not_relayed']:
        print("{} not relayed".format(name))
    else:
        print("{} successfully sent".format(name))