RecoverAccounts
RecoverAccounts queries the auction server for this trader daemon's accounts in case we lost our local account database.
Source: poolrpc/trader.proto
gRPC
rpc RecoverAccounts (RecoverAccountsRequest) returns (RecoverAccountsResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/pool/accounts/recover |
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:12010'
const MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
const TLS_PATH = 'POOL_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('poolrpc/trader.proto', loaderOptions);
const poolrpc = grpc.loadPackageDefinition(packageDefinition).poolrpc;
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 poolrpc.Trader(GRPC_HOST, creds);
let request = {
full_client: <bool>,
account_target: <uint32>,
auctioneer_key: <string>,
height_hint: <uint32>,
bitcoin_host: <string>,
bitcoin_user: <string>,
bitcoin_password: <string>,
bitcoin_httppostmode: <bool>,
bitcoin_usetls: <bool>,
bitcoin_tlspath: <string>,
};
client.recoverAccounts(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "num_recovered_accounts": <uint32>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the poolrpc/trader.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import trader_pb2 as poolrpc, trader_pb2_grpc as traderstub
GRPC_HOST = 'localhost:12010'
MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
TLS_PATH = 'POOL_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 = traderstub.TraderStub(channel)
request = poolrpc.RecoverAccountsRequest(
full_client=<bool>,
account_target=<uint32>,
auctioneer_key=<string>,
height_hint=<uint32>,
bitcoin_host=<string>,
bitcoin_user=<string>,
bitcoin_password=<string>,
bitcoin_httppostmode=<bool>,
bitcoin_usetls=<bool>,
bitcoin_tlspath=<string>,
)
response = stub.RecoverAccounts(request)
print(response)
# {
# "num_recovered_accounts": <uint32>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8281'
const MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
let requestBody = {
full_client: <boolean>, // <bool>
account_target: <integer>, // <uint32>
auctioneer_key: <string>, // <string>
height_hint: <integer>, // <uint32>
bitcoin_host: <string>, // <string>
bitcoin_user: <string>, // <string>
bitcoin_password: <string>, // <string>
bitcoin_httppostmode: <boolean>, // <bool>
bitcoin_usetls: <boolean>, // <bool>
bitcoin_tlspath: <string>, // <string>
};
let options = {
url: `https://${REST_HOST}/v1/pool/accounts/recover`,
// 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:
// {
// "num_recovered_accounts": <integer>, // <uint32>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8281'
MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
TLS_PATH = 'POOL_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/pool/accounts/recover'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'full_client': <bool>,
'account_target': <uint32>,
'auctioneer_key': <string>,
'height_hint': <uint32>,
'bitcoin_host': <string>,
'bitcoin_user': <string>,
'bitcoin_password': <string>,
'bitcoin_httppostmode': <bool>,
'bitcoin_usetls': <bool>,
'bitcoin_tlspath': <string>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "num_recovered_accounts": <uint32>,
# }
$ pool accounts recover --help
NAME:
pool accounts recover - recover accounts after data loss with the help of the auctioneer
USAGE:
pool accounts recover [command options] [arguments...]
DESCRIPTION:
In case the data directory of the trader was corrupted or lost, this
command can be used to ask the auction server to send back its view of
the trader's accounts. This is possible as long as the connected lnd
node is running with the same seed as when the accounts to recover were
first created.
NOTE: This command should only be used after data loss as it will fail
if there already are open accounts in the trader's database.
All open or pending orders of any recovered account will be canceled on
the auctioneer's side and won't be restored in the trader's database.
OPTIONS:
--full_client fetch the latest account state from the server. If false, the full process willrun locally, but it could take hours.
--account_target value number of accounts that we are looking to recover, set higher if there were more than 50 accounts or attempts at creating accounts (default: 50)
--auctioneer_key full_client Auctioneer's public key. Only used during full_client recoveries
--height_hint full_client initial block height. Only used during full_client recoveries (default: 0)
--bitcoin_host full_client bitcoind/btcd instance address. Only used during full_client recoveries
--bitcoin_user full_client bitcoind/btcd user name. Only used during full_client recoveries
--bitcoin_password full_client bitcoind/btcd password. Only used during full_client recoveries
--bitcoin_httppostmode full_client Use HTTP POST mode? bitcoind only supports this mode. Only used during full_client recoveries
--bitcoin_usetls full_client Use TLS to connect? bitcoind only supports non-TLS connections. Only used during full_client recoveries
--bitcoin_tlspath full_client Path to btcd's TLS certificate, if TLS is enabled. Only used during full_client recoveries
Messages
poolrpc.RecoverAccountsRequest
Source: poolrpc/trader.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
full_client | bool | boolean | body |
account_target | uint32 | integer | body |
auctioneer_key | string | string | body |
height_hint | uint32 | integer | body |
bitcoin_host | string | string | body |
bitcoin_user | string | string | body |
bitcoin_password | string | string | body |
bitcoin_httppostmode | bool | boolean | body |
bitcoin_usetls | bool | boolean | body |
bitcoin_tlspath | string | string | body |
poolrpc.RecoverAccountsResponse
Source: poolrpc/trader.proto
Field | gRPC Type | REST Type |
---|---|---|
num_recovered_accounts | uint32 | integer |