def addinvoice(memo, rpcserver, amt, expiry): """ TODO (2019-??-??): check for [lncli] rpc error: code = Unknown desc = memo too large: 1192 bytes (maxsize=1024) """ cmd = [LNCLI_BIN] + _auth_args(rpcserver) + [ "addinvoice", "--memo", memo, "--amt", str(amt), "--expiry", str(expiry) ] # TODO: return_stderr_on_fail=True, and adjust all the call sites output = cli.run(cmd) print("Command finished, addinvoice json stdout: {}".format(output)) return output
def verifymessage(msg, sig, rpcserver, mock=False): """ NOTE: CLI retruns "pubkey" while API returns "idnetity_pubkey" """ if mock: return {"valid": True, "pubkey": "FAKE2"} cmd = [LNCLI_BIN] + _auth_args(rpcserver) + [ "verifymessage", "--msg", msg, "--sig", sig, ] # TODO: return_stderr_on_fail=True, and adjust all the call sites return cli.run(cmd, log_cmd=True)
def payinvoice(payreq, rpcserver, mock=False): if mock: return {"success": True, "stdouterr": ""} # TODO: add --json, note that this flag is not defined in older versions of lncli cmd = [LNCLI_BIN] + _auth_args(rpcserver) + [ "payinvoice", "-f", # force, no interactive prompt "--pay_req", payreq, ] return cli.run(cmd, log_cmd=True, return_stderr_on_fail=True, try_num=3, timeout=60) # 12x the default timeout!
def listinvoices(index_offset, rpcserver, max_invoices=100, mock=False): if mock: return { "first_index_offset": "0", "invoices": [], "last_index_offset": "0" } cmd = [LNCLI_BIN] + _auth_args(rpcserver) + [ "listinvoices", "--index_offset", str(index_offset), "--max_invoices", str(max_invoices), "--paginate-forwards", ] # TODO: return_stderr_on_fail=True, and adjust all the call sites return cli.run(cmd, log_cmd=False)
def decodepayreq(payreq, rpcserver, mock=False): if mock: return { "success": True, "stdouterr": json.dumps({ "num_satoshis": 123, "num_msat": 123000, "pubkey": "FAKE2" }) } cmd = [LNCLI_BIN] + _auth_args(rpcserver) + [ "decodepayreq", "--pay_req", payreq, ] return cli.run(cmd, log_cmd=True, return_stderr_on_fail=True)