LoopOut
LoopOut initiates an loop out swap with the given parameters. The call returns after the swap has been set up with the swap server. From that point onwards, progress can be tracked via the SwapStatus stream that is returned from Monitor().
Source: looprpc/client.proto
gRPC
rpc LoopOut (LoopOutRequest) returns (SwapResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/loop/out |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:11010'
const MACAROON_PATH = 'LOOP_DIR/regtest/loop.macaroon'
const TLS_PATH = 'LOOP_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('looprpc/client.proto', loaderOptions);
const looprpc = grpc.loadPackageDefinition(packageDefinition).looprpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new looprpc.SwapClient(GRPC_HOST, creds);
let request = {
amt: <int64>,
dest: <string>,
max_swap_routing_fee: <int64>,
max_prepay_routing_fee: <int64>,
max_swap_fee: <int64>,
max_prepay_amt: <int64>,
max_miner_fee: <int64>,
loop_out_channel: <uint64>,
outgoing_chan_set: <uint64>,
sweep_conf_target: <int32>,
htlc_confirmations: <int32>,
swap_publication_deadline: <uint64>,
label: <string>,
initiator: <string>,
account: <string>,
account_addr_type: <AddressType>,
is_external_addr: <bool>,
reservation_ids: <bytes>,
payment_timeout: <uint32>,
};
client.loopOut(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "id": <string>,
// "id_bytes": <bytes>,
// "htlc_address": <string>,
// "htlc_address_p2wsh": <string>,
// "htlc_address_p2tr": <string>,
// "server_message": <string>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the looprpc/client.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import client_pb2 as looprpc, client_pb2_grpc as clientstub
GRPC_HOST = 'localhost:11010'
MACAROON_PATH = 'LOOP_DIR/regtest/loop.macaroon'
TLS_PATH = 'LOOP_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = clientstub.SwapClientStub(channel)
request = looprpc.LoopOutRequest(
amt=<int64>,
dest=<string>,
max_swap_routing_fee=<int64>,
max_prepay_routing_fee=<int64>,
max_swap_fee=<int64>,
max_prepay_amt=<int64>,
max_miner_fee=<int64>,
loop_out_channel=<uint64>,
outgoing_chan_set=<uint64>,
sweep_conf_target=<int32>,
htlc_confirmations=<int32>,
swap_publication_deadline=<uint64>,
label=<string>,
initiator=<string>,
account=<string>,
account_addr_type=<AddressType>,
is_external_addr=<bool>,
reservation_ids=<bytes>,
payment_timeout=<uint32>,
)
response = stub.LoopOut(request)
print(response)
# {
# "id": <string>,
# "id_bytes": <bytes>,
# "htlc_address": <string>,
# "htlc_address_p2wsh": <string>,
# "htlc_address_p2tr": <string>,
# "server_message": <string>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8081'
const MACAROON_PATH = 'LOOP_DIR/regtest/loop.macaroon'
let requestBody = {
amt: <string>, // <int64>
dest: <string>, // <string>
max_swap_routing_fee: <string>, // <int64>
max_prepay_routing_fee: <string>, // <int64>
max_swap_fee: <string>, // <int64>
max_prepay_amt: <string>, // <int64>
max_miner_fee: <string>, // <int64>
loop_out_channel: <string>, // <uint64>
outgoing_chan_set: <array>, // <uint64>
sweep_conf_target: <integer>, // <int32>
htlc_confirmations: <integer>, // <int32>
swap_publication_deadline: <string>, // <uint64>
label: <string>, // <string>
initiator: <string>, // <string>
account: <string>, // <string>
account_addr_type: <string>, // <AddressType>
is_external_addr: <boolean>, // <bool>
reservation_ids: <array>, // <bytes> (base64 encoded)
payment_timeout: <integer>, // <uint32>
};
let options = {
url: `https://${REST_HOST}/v1/loop/out`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
form: JSON.stringify(requestBody),
}
request.post(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "id": <string>, // <string>
// "id_bytes": <string>, // <bytes>
// "htlc_address": <string>, // <string>
// "htlc_address_p2wsh": <string>, // <string>
// "htlc_address_p2tr": <string>, // <string>
// "server_message": <string>, // <string>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8081'
MACAROON_PATH = 'LOOP_DIR/regtest/loop.macaroon'
TLS_PATH = 'LOOP_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/loop/out'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'amt': <int64>,
'dest': <string>,
'max_swap_routing_fee': <int64>,
'max_prepay_routing_fee': <int64>,
'max_swap_fee': <int64>,
'max_prepay_amt': <int64>,
'max_miner_fee': <int64>,
'loop_out_channel': <uint64>,
'outgoing_chan_set': <uint64>,
'sweep_conf_target': <int32>,
'htlc_confirmations': <int32>,
'swap_publication_deadline': <uint64>,
'label': <string>,
'initiator': <string>,
'account': <string>,
'account_addr_type': <AddressType>,
'is_external_addr': <bool>,
'reservation_ids': base64.b64encode(<bytes>),
'payment_timeout': <uint32>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "id": <string>,
# "id_bytes": <bytes>,
# "htlc_address": <string>,
# "htlc_address_p2wsh": <string>,
# "htlc_address_p2tr": <string>,
# "server_message": <string>,
# }
$ loop out --help
NAME:
loop out - perform an off-chain to on-chain swap (looping out)
USAGE:
loop out [command options] amt [addr]
DESCRIPTION:
Attempts to loop out the target amount into either the backing lnd's
wallet, or a targeted address.
The amount is to be specified in satoshis.
Optionally a BASE58/bech32 encoded bitcoin destination address may be
specified. If not specified, a new wallet address will be generated.
OPTIONS:
--addr value the optional address that the looped out funds should be sent to, if let blank the funds will go to lnd's wallet
--account value the name of the account to generate a new address from. You can list the names of valid accounts in your backing lnd instance with "lncli wallet accounts list"
--account_addr_type value the address type of the extended public key specified in account. Currently only pay-to-taproot-pubkey(p2tr) is supported (default: "p2tr")
--amt value the amount in satoshis to loop out. To check for the minimum and maximum amounts to loop out please consult "loop terms" (default: 0)
--htlc_confs value the number of confirmations (in blocks) that we require for the htlc extended by the server before we reveal the preimage (default: 1)
--conf_target value the number of blocks from the swap initiation height that the on-chain HTLC should be swept within (default: 9)
--max_swap_routing_fee value the max off-chain swap routing fee in satoshis, if not specified, a default max fee will be used (default: 0)
--fast indicate you want to swap immediately, paying potentially a higher fee. If not set the swap server might choose to wait up to 30 minutes before publishing the swap HTLC on-chain, to save on its chain fees. Not setting this flag therefore might result in a lower swap fee
--payment_timeout value the timeout for each individual off-chain payment attempt. If not set, the default timeout of 1 hour will be used. As the payment might be retried, the actual total time may be longer (default: 0s)
--force, -f Assumes yes during confirmation. Using this option will result in an immediate swap
--label value an optional label for this swap,limited to 500 characters. The label may not start with our reserved prefix: [reserved].
--verbose, -v show expanded details
--channel value the comma-separated list of short channel IDs of the channels to loop out
Messages
looprpc.LoopOutRequest
Source: looprpc/client.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
amt | int64 | string | body |
dest | string | string | body |
max_swap_routing_fee | int64 | string | body |
max_prepay_routing_fee | int64 | string | body |
max_swap_fee | int64 | string | body |
max_prepay_amt | int64 | string | body |
max_miner_fee | int64 | string | body |
loop_out_channel deprecated | uint64 | string | body |
outgoing_chan_set | uint64[] | array | body |
sweep_conf_target | int32 | integer | body |
htlc_confirmations | int32 | integer | body |
swap_publication_deadline | uint64 | string | body |
label | string | string | body |
initiator | string | string | body |
account | string | string | body |
account_addr_type | AddressType | string | body |
is_external_addr | bool | boolean | body |
reservation_ids | bytes[] | array | body |
payment_timeout | uint32 | integer | body |
looprpc.SwapResponse
Source: looprpc/client.proto
Field | gRPC Type | REST Type |
---|---|---|
id deprecated | string | string |
id_bytes | bytes | string |
htlc_address deprecated | string | string |
htlc_address_p2wsh | string | string |
htlc_address_p2tr | string | string |
server_message | string | string |
Enums
looprpc.AddressType
Name | Number |
---|---|
ADDRESS_TYPE_UNKNOWN | 0 |
TAPROOT_PUBKEY | 1 |