Exemple #1
0
def initialise_clients():
    alice = py_rpc.Client(lnd_dir=ALICE_LND_DIR,
                          network=ALICE_NETWORK,
                          grpc_host=ALICE_RPC_HOST,
                          grpc_port=ALICE_RPC_PORT,
                          macaroon_path=ALICE_MACAROON_PATH)
    alice.pub_key = alice.get_info().identity_pubkey
    alice.lightning_address = py_rpc.Client.lightning_address(
            pubkey=alice.pub_key,
            host=ALICE_HOST_ADDR)

    bob = py_rpc.Client(lnd_dir=BOB_LND_DIR,
                        network=BOB_NETWORK,
                        grpc_host=BOB_RPC_HOST,
                        grpc_port=BOB_RPC_PORT,
                        macaroon_path=BOB_MACAROON_PATH)
    bob.pub_key = bob.get_info().identity_pubkey
    bob.lightning_address = py_rpc.Client.lightning_address(
            pubkey=bob.pub_key,
            host=BOB_HOST_ADDR)

    bitcoin_rpc = bitcoin.rpc.RawProxy(service_port=BITCOIN_SERVICE_PORT,
                                       btc_conf_file=BITCOIN_CONF_FILE)

    return alice, bob, bitcoin_rpc
Exemple #2
0
    def __init__(self):
        argument_parser = self.get_argument_parser()
        arguments = argument_parser.parse_args()

        self.rpc = lnd_grpc.Client(
            grpc_host=arguments.host,
            grpc_port=arguments.port,
            macaroon_path=arguments.macaroon,
            tls_cert_path=arguments.tls
        )

        first_hop_channel_id = vars(arguments)['from']
        to_channel = arguments.to

        channel_ratio = float(arguments.ratio) / 100

        if arguments.incoming is not None and not arguments.list_candidates:
            print(
                "--outgoing and --incoming only work in conjunction with --list-candidates")
            sys.exit()

        if arguments.list_candidates:
            incoming = arguments.incoming is None or arguments.incoming
            if incoming:
                self.list_incoming_candidates(channel_ratio)
            else:
                self.list_outgoing_candidates(channel_ratio)
            sys.exit()

        if to_channel is None:
            argument_parser.print_help()
            sys.exit()

        # the 'to' argument might be an index, or a channel ID
        if to_channel and to_channel < 10000:
            # here we are in the "channel index" case
            index = int(to_channel) - 1
            candidates = self.get_incoming_rebalance_candidates(channel_ratio)
            candidate = candidates[index]
            last_hop_channel = candidate
        else:
            # else the channel argument should be the channel ID
            last_hop_channel = self.get_channel_for_channel_id(to_channel)

        amount = self.get_amount(arguments, first_hop_channel_id,
                                 last_hop_channel)

        if amount == 0:
            print("Amount is 0, nothing to do")
            sys.exit()

        response = Logic(self.rpc, first_hop_channel_id, last_hop_channel, amount,
                         channel_ratio).rebalance()
        if response:
            print(response)
Exemple #3
0
def create_lnd_client(lnd_dir: str = None,
                      macaroon_path: str = None,
                      network: str = 'mainnet',
                      grpc_host: str = 'localhost',
                      grpc_port: str = '10009'):
    lncli = lnd_grpc.Client(lnd_dir=lnd_dir,
                            network=network,
                            grpc_host=grpc_host,
                            grpc_port=grpc_port,
                            macaroon_path=macaroon_path)

    return lncli
Exemple #4
0
 def init_app(self, app):
     app.config.setdefault('LND_DIR', get_lnd_dir())
     app.config.setdefault('LND_NETWORK', 'mainnet')
     # Do not use localhost as it is significantly slower on Windows
     app.config.setdefault('LND_GRPC_HOST', '127.0.0.1')
     app.config.setdefault('LND_GRPC_PORT', '10009')
     self.rpc = lnd_grpc.Client(
         lnd_dir=app.config['LND_DIR'],
         network=app.config['LND_NETWORK'],
         grpc_host=app.config['LND_GRPC_HOST'],
         grpc_port=app.config['LND_GRPC_PORT'],
     )
def create_lnd_client(
    lnd_dir: str = None,
    macaroon_path: str = None,
    network: str = "mainnet",
    grpc_host: str = "localhost",
    grpc_port: str = "10009",
):
    lncli = lnd_grpc.Client(
        lnd_dir=lnd_dir,
        network=network,
        grpc_host=grpc_host,
        grpc_port=grpc_port,
        macaroon_path=macaroon_path,
    )

    return lncli
Exemple #6
0
    for word in seed:
        formatted_seed += "{}: {}\n".format(count, word)
        count += 1

    return formatted_seed.rstrip()


def format_seed_raw(seed):
    s = ""
    for word in seed:
        s += word + " "
    return s.rstrip()


# This is the main entry point for the program
if __name__ == "__main__":

    network = "mainnet"
    if os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled"):
        network = "testnet"

    # Generate the seed
    rpc = lnd_grpc.Client(
        lnd_dir="/home/bitcoin/.lnd/",
        macaroon_path="/home/bitcoin/.lnd/data/chain/bitcoin/{}/admin.macaroon"
        .format(network))

    # Get seed and print
    data = rpc.gen_seed()
    formatted_seed = format_seed_raw(data.cipher_seed_mnemonic)
    print(formatted_seed)
Exemple #7
0
def format_seed_numbered(seed):
    formatted_seed = ""
    count = 1
    for word in seed:
        formatted_seed += "{}: {}\n".format(count, word)
        count += 1

    return formatted_seed.rstrip()


def format_seed_raw(seed):
    s = ""
    for word in seed:
        s += word + " "
    return s.rstrip()


# This is the main entry point for the program
if __name__ == "__main__":

    # Generate the seed
    rpc = lnd_grpc.Client(
        lnd_dir="/home/bitcoin/.lnd/",
        macaroon_path=
        "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon")

    # Get seed and print
    data = rpc.gen_seed()
    formatted_seed = format_seed_raw(data.cipher_seed_mnemonic)
    print(formatted_seed)
Exemple #8
0
import lnd_grpc.lnd_grpc as py_rpc
import protos.rpc_pb2 as rpc_pb2

# raise Exception("Comment me out if you know what you're doing and want to test this on mainnet")

# create a Client stub
rpc = py_rpc.Client()
# initialize an address variable for test sends
address1 = None
address2 = None


# Wallet Unlocker stub tests
def test_gen_seed():
    response = rpc.gen_seed()
    assert isinstance(response, rpc_pb2.GenSeedResponse)


# I think these fail tests are not useful
# def gen_seed_fail():
#    gen_seed_fail = rpc.gen_seed(fail='hello')
#    assert not isinstance(gen_seed_fail, rpc_pb2.GenSeedResponse)


def test_init_wallet():
    response = rpc.init_wallet('wallet_password="AcceptablePassword')
    assert isinstance(response, rpc_pb2.InitWalletResponse)
    # TODO: add a test passing all params here. Delete .lnd dir first?


def test_unlock_wallet():