DecodeAssetPayReq
DecodeAssetPayReq is similar to lnd's lnrpc.DecodePayReq, but it accepts an asset ID and returns the invoice amount expressed in asset units along side the normal information.
Source: tapchannelrpc/tapchannel.proto
gRPC
rpc DecodeAssetPayReq (AssetPayReq) returns (AssetPayReqResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/taproot-assets/channels/invoice/decode |
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>,
pay_req_string: <string>,
};
client.decodeAssetPayReq(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "asset_amount": <uint64>,
// "decimal_display": <DecimalDisplay>,
// "asset_group": <AssetGroup>,
// "genesis_info": <GenesisInfo>,
// "pay_req": <PayReq>,
// }
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.AssetPayReq(
asset_id=<bytes>,
pay_req_string=<string>,
)
response = stub.DecodeAssetPayReq(request)
print(response)
# {
# "asset_amount": <uint64>,
# "decimal_display": <DecimalDisplay>,
# "asset_group": <AssetGroup>,
# "genesis_info": <GenesisInfo>,
# "pay_req": <PayReq>,
# }
- 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)
pay_req_string: <string>, // <string>
};
let options = {
url: `https://${REST_HOST}/v1/taproot-assets/channels/invoice/decode`,
// 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:
// {
// "asset_amount": <string>, // <uint64>
// "decimal_display": <object>, // <DecimalDisplay>
// "asset_group": <object>, // <AssetGroup>
// "genesis_info": <object>, // <GenesisInfo>
// "pay_req": <object>, // <PayReq>
// }
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/decode'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'asset_id': base64.b64encode(<bytes>),
'pay_req_string': <string>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "asset_amount": <uint64>,
# "decimal_display": <DecimalDisplay>,
# "asset_group": <AssetGroup>,
# "genesis_info": <GenesisInfo>,
# "pay_req": <PayReq>,
# }
# There is no CLI command for this RPC
Messages
tapchannelrpc.AssetPayReq
Source: tapchannelrpc/tapchannel.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
asset_id | bytes | string | body |
pay_req_string | string | string | body |
tapchannelrpc.AssetPayReqResponse
Source: tapchannelrpc/tapchannel.proto
Field | gRPC Type | REST Type |
---|---|---|
asset_amount | uint64 | string |
decimal_display | DecimalDisplay | object |
asset_group | AssetGroup | object |
genesis_info | GenesisInfo | object |
pay_req | PayReq | object |
Nested Messages
taprpc.AssetGroup
Field | gRPC Type | REST Type |
---|---|---|
raw_group_key | bytes | string |
tweaked_group_key | bytes | string |
asset_witness | bytes | string |
tapscript_root | bytes | string |
taprpc.DecimalDisplay
Field | gRPC Type | REST Type |
---|---|---|
decimal_display | uint32 | integer |
taprpc.GenesisInfo
Field | gRPC Type | REST Type |
---|---|---|
genesis_point | string | string |
name | string | string |
meta_hash | bytes | string |
asset_id | bytes | string |
asset_type | AssetType | string |
output_index | uint32 | integer |
Enums
taprpc.AssetType
Name | Number |
---|---|
NORMAL | 0 |
COLLECTIBLE | 1 |