Skip to main content

RegisterSpendNtfn

RegisterSpendNtfn is a synchronous response-streaming RPC that registers an intent for a client to be notification once a spend request has been spent by a transaction that has confirmed on-chain.

A client can specify whether the spend request should be for a particular outpoint or for an output script by specifying a zero outpoint.

Source: chainrpc/chainnotifier.proto

gRPC

info

This is a server-streaming RPC

rpc RegisterSpendNtfn (SpendRequest) returns (stream SpendEvent);

REST

HTTP MethodPath
POST /v2/chainnotifier/register/spends

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', 'chainrpc/chainnotifier.proto'], loaderOptions);
const chainrpc = grpc.loadPackageDefinition(packageDefinition).chainrpc;
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 chainrpc.ChainNotifier(GRPC_HOST, creds);
let request = {
outpoint: <Outpoint>,
script: <bytes>,
height_hint: <uint32>,
};
let call = client.registerSpendNtfn(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "spend": <SpendDetails>,
// "reorg": <Reorg>,
// }

Messages

chainrpc.SpendRequest

Source: chainrpc/chainnotifier.proto

FieldgRPC TypeREST TypeREST Placement
outpoint
Outpointobjectbody
script
bytesstringbody
height_hint
uint32integerbody

chainrpc.SpendEvent

Source: chainrpc/chainnotifier.proto

FieldgRPC TypeREST Type
spend
SpendDetailsobject
reorg
Reorgobject

Nested Messages

chainrpc.Outpoint

FieldgRPC TypeREST Type
hash
bytesstring
index
uint32integer

chainrpc.SpendDetails

FieldgRPC TypeREST Type
spending_outpoint
Outpointobject
raw_spending_tx
bytesstring
spending_tx_hash
bytesstring
spending_input_index
uint32integer
spending_height
uint32integer

chainrpc.Reorg

note

This response has no parameters.