Skip to main content

BuildOnion

BuildOnion attempts to build an onion packet for the specified route.

Source: switchrpc/switch.proto

gRPC​

rpc BuildOnion (BuildOnionRequest) returns (BuildOnionResponse);

REST​

HTTP MethodPath
POST /v2/switch/build

Code Samples​

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'switchrpc/switch.proto'], loaderOptions);
const switchrpc = grpc.loadPackageDefinition(packageDefinition).switchrpc;
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 switchrpc.Switch(GRPC_HOST, creds);
let request = {
route: <Route>,
payment_hash: <bytes>,
session_key: <bytes>,
};
client.buildOnion(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "onion_blob": <bytes>,
// "session_key": <bytes>,
// "hop_pubkeys": <bytes>,
// }

Messages​

switchrpc.BuildOnionRequest​

Source: switchrpc/switch.proto

FieldgRPC TypeREST TypeREST Placement
route
Routeobjectbody
payment_hash
bytesstringbody
session_key
bytesstringbody

switchrpc.BuildOnionResponse​

Source: switchrpc/switch.proto

FieldgRPC TypeREST Type
onion_blob
bytesstring
session_key
bytesstring
hop_pubkeys
bytes[]array

Nested Messages​

lnrpc.AMPRecord​

FieldgRPC TypeREST Type
root_share
bytesstring
set_id
bytesstring
child_index
uint32integer

lnrpc.Hop​

FieldgRPC TypeREST Type
chan_id
uint64string
chan_capacity
int64string
amt_to_forward
int64string
fee
int64string
expiry
uint32integer
amt_to_forward_msat
int64string
fee_msat
int64string
pub_key
stringstring
tlv_payload
boolboolean
mpp_record
MPPRecordobject
amp_record
AMPRecordobject
custom_records
CustomRecordsEntry[]object
metadata
bytesstring
blinding_point
bytesstring
encrypted_data
bytesstring
total_amt_msat
uint64string

lnrpc.Hop.CustomRecordsEntry​

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

lnrpc.MPPRecord​

FieldgRPC TypeREST Type
payment_addr
bytesstring
total_amt_msat
int64string

lnrpc.Route​

FieldgRPC TypeREST Type
total_time_lock
uint32integer
total_fees
int64string
total_amt
int64string
hops
Hop[]array
total_fees_msat
int64string
total_amt_msat
int64string
first_hop_amount_msat
int64string
custom_channel_data
bytesstring
source_pub_key
stringstring