Skip to content

Commit

Permalink
Merge pull request #5460 from ErikEk/lncli-add-command-for-publishtra…
Browse files Browse the repository at this point in the history
…nsaction

lncli: add command for publishtransaction
  • Loading branch information
Roasbeef authored Aug 6, 2021
2 parents 254d9be + ace615b commit 90db8de
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
65 changes: 65 additions & 0 deletions cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
Expand All @@ -11,6 +12,7 @@ import (
"sort"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/urfave/cli"
Expand Down Expand Up @@ -57,6 +59,7 @@ func walletCommands() []cli.Command {
bumpCloseFeeCommand,
listSweepsCommand,
labelTxCommand,
publishTxCommand,
releaseOutputCommand,
listLeasesCommand,
psbtCommand,
Expand Down Expand Up @@ -477,6 +480,68 @@ func labelTransaction(ctx *cli.Context) error {
return nil
}

var publishTxCommand = cli.Command{
Name: "publishtx",
Usage: "Attempts to publish the passed transaction to the network.",
ArgsUsage: "tx_hex",
Description: `
Publish a hex-encoded raw transaction to the on-chain network. The
wallet will continually attempt to re-broadcast the transaction on start up, until it
enters the chain. The label parameter is optional and limited to 500 characters. Note
that multi word labels must be contained in quotation marks ("").
`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "label",
Usage: "(optional) transaction label",
},
},
Action: actionDecorator(publishTransaction),
}

func publishTransaction(ctx *cli.Context) error {
ctxc := getContext()

// Display the command's help message if we do not have the expected
// number of arguments/flags.
if ctx.NArg() != 1 || ctx.NumFlags() > 1 {
return cli.ShowCommandHelp(ctx, "publishtx")
}

walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp()

tx, err := hex.DecodeString(ctx.Args().First())
if err != nil {
return err
}

// Deserialize the transaction to get the transaction hash.
msgTx := &wire.MsgTx{}
txReader := bytes.NewReader(tx)
if err := msgTx.Deserialize(txReader); err != nil {
return err
}

req := &walletrpc.Transaction{
TxHex: tx,
Label: ctx.String("label"),
}

_, err = walletClient.PublishTransaction(ctxc, req)
if err != nil {
return err
}

printJSON(&struct {
TXID string `json:"txid"`
}{
TXID: msgTx.TxHash().String(),
})

return nil
}

// utxoLease contains JSON annotations for a lease on an unspent output.
type utxoLease struct {
ID string `json:"id"`
Expand Down
3 changes: 3 additions & 0 deletions docs/release-notes/release-notes-0.14.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ If you use a strange system or changed group membership of the group running LND
you may want to check your system to see if it introduces additional risk for
you.

* [Makes publishtransaction, in the wallet sub-server, reachable through
lncli](https://github.com/lightningnetwork/lnd/pull/5460).

# Build System

* [A new pre-submit check has been
Expand Down

0 comments on commit 90db8de

Please sign in to comment.