AddInvoice
AddInvoice is a wrapper around lnd's lnrpc.AddInvoice method with asset specific parameters. It allows RPC users to create invoices that correspond to the specified asset amount.
Source: tapchannelrpc/tapchannel.proto
gRPC
rpc AddInvoice (AddInvoiceRequest) returns (AddInvoiceResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/taproot-assets/channels/invoice |
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:10029'
const MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
const TLS_PATH = 'TAPROOT-ASSETS_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('tapchannelrpc/tapchannel.proto', loaderOptions);
const tapchannelrpc = grpc.loadPackageDefinition(packageDefinition).tapchannelrpc;
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 tapchannelrpc.TaprootAssetChannels(GRPC_HOST, creds);
let request = {
asset_id: <bytes>,
asset_amount: <uint64>,
peer_pubkey: <bytes>,
invoice_request: <Invoice>,
hodl_invoice: <HodlInvoice>,
group_key: <bytes>,
};
client.addInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "accepted_buy_quote": <PeerAcceptedBuyQuote>,
// "invoice_result": <AddInvoiceResponse>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the tapchannelrpc/tapchannel.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import tapchannel_pb2 as tapchannelrpc, tapchannel_pb2_grpc as tapchannelstub
GRPC_HOST = 'localhost:10029'
MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
TLS_PATH = 'TAPROOT-ASSETS_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 = tapchannelstub.TaprootAssetChannelsStub(channel)
request = tapchannelrpc.AddInvoiceRequest(
asset_id=<bytes>,
asset_amount=<uint64>,
peer_pubkey=<bytes>,
invoice_request=<Invoice>,
hodl_invoice=<HodlInvoice>,
group_key=<bytes>,
)
response = stub.AddInvoice(request)
print(response)
# {
# "accepted_buy_quote": <PeerAcceptedBuyQuote>,
# "invoice_result": <AddInvoiceResponse>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8089'
const MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
let requestBody = {
asset_id: <string>, // <bytes> (base64 encoded)
asset_amount: <string>, // <uint64>
peer_pubkey: <string>, // <bytes> (base64 encoded)
invoice_request: <object>, // <Invoice>
hodl_invoice: <object>, // <HodlInvoice>
group_key: <string>, // <bytes> (base64 encoded)
};
let options = {
url: `https://${REST_HOST}/v1/taproot-assets/channels/invoice`,
// 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:
// {
// "accepted_buy_quote": <object>, // <PeerAcceptedBuyQuote>
// "invoice_result": <object>, // <AddInvoiceResponse>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8089'
MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
TLS_PATH = 'TAPROOT-ASSETS_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/taproot-assets/channels/invoice'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'asset_id': base64.b64encode(<bytes>),
'asset_amount': <uint64>,
'peer_pubkey': base64.b64encode(<bytes>),
'invoice_request': <Invoice>,
'hodl_invoice': <HodlInvoice>,
'group_key': base64.b64encode(<bytes>),
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "accepted_buy_quote": <PeerAcceptedBuyQuote>,
# "invoice_result": <AddInvoiceResponse>,
# }
$ litcli ln addinvoice --help
NAME:
litcli ln addinvoice - Add a new invoice to receive Taproot Assets.
USAGE:
litcli ln addinvoice [command options] [--asset_id=X | --group_key=X] --asset_amount=Y [--rfq_peer_pubkey=Z]
CATEGORY:
Invoices
DESCRIPTION:
Add a new invoice, expressing intent for a future payment, received in
Taproot Assets.
OPTIONS:
--memo value a description of the payment to attach along with the invoice (default="")
--preimage value the hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage. If not set, a random preimage will be created.
--amt value the amt of satoshis in this invoice (default: 0)
--amt_msat value the amt of millisatoshis in this invoice (default: 0)
--description_hash value SHA-256 hash of the description of the payment. Used if the purpose of payment cannot naturally fit within the memo. If provided this will be used instead of the description(memo) field in the encoded invoice.
--fallback_addr value fallback on-chain address that can be used in case the lightning payment fails
--expiry value the invoice's expiry time in seconds. If not specified, an expiry of 86400 seconds (24 hours) is implied. (default: 0)
--cltv_expiry_delta value The minimum CLTV delta to use for the final hop. If this is set to 0, the default value is used. The default value for cltv_expiry_delta is configured by the 'bitcoin.timelockdelta' option. (default: 0)
--private encode routing hints in the invoice with private channels in order to assist the payer in reaching you. If amt and amt_msat are zero, a large number of hints with these channels can be included, which might not be desirable.
--amp creates an AMP invoice. If true, preimage should not be set.
--blind creates an invoice that contains blinded paths. Note that invoices with blinded paths will be signed using a random ephemeral key so as not to reveal the real node ID of this node.
--min_real_blinded_hops --blind The minimum number of real hops to use in a blinded path. This option will only be used if --blind has also been set. (default: 0)
--num_blinded_hops --blind The number of hops to use for each blinded path included in the invoice. This option will only be used if --blind has also been set. Dummy hops will be used to pad paths shorter than this. (default: 0)
--max_blinded_paths --blind The maximum number of blinded paths to add to an invoice. This option will only be used if --blind has also been set. (default: 0)
--blinded_path_omit_node value The pub key (in hex) of a node not to use on a blinded path. The flag may be specified multiple times.
--asset_id value the asset ID of the asset to receive; cannot be used at the same time as --group_key
--group_key value the group key of the asset to receive; cannot be used at the same time as --asset_id
--asset_amount value the amount of assets to receive (default: 0)
--rfq_peer_pubkey value (optional) the public key of the peer to ask for a quote when converting from assets to sats for the invoice; must be set if there are multiple channels with the same asset ID present
Messages
tapchannelrpc.AddInvoiceRequest
Source: tapchannelrpc/tapchannel.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
asset_id | bytes | string | body |
asset_amount | uint64 | string | body |
peer_pubkey | bytes | string | body |
invoice_request | Invoice | object | body |
hodl_invoice | HodlInvoice | object | body |
group_key | bytes | string | body |
tapchannelrpc.AddInvoiceResponse
Source: tapchannelrpc/tapchannel.proto
Field | gRPC Type | REST Type |
---|---|---|
accepted_buy_quote | PeerAcceptedBuyQuote | object |
invoice_result | AddInvoiceResponse | object |
Nested Messages
rfqrpc.FixedPoint
Field | gRPC Type | REST Type |
---|---|---|
coefficient | string | string |
scale | uint32 | integer |
rfqrpc.PeerAcceptedBuyQuote
Field | gRPC Type | REST Type |
---|---|---|
peer | string | string |
id | bytes | string |
scid | uint64 | string |
asset_max_amount | uint64 | string |
ask_asset_rate | FixedPoint | object |
expiry | uint64 | string |
min_transportable_units | uint64 | string |
tapchannelrpc.HodlInvoice
Field | gRPC Type | REST Type |
---|---|---|
payment_hash | bytes | string |