rpc: add gettransaction endpoint to walletrpc sub-server
This commit is contained in:
1 parent
c32edbd732
commit
f0bc6d804c
14 files changed
+1130
-745
No files matched your search
@@ -1285,6 +1285,45 @@ func getPreviousOutpoints(wireTx *wire.MsgTx,
|
||||
return previousOutpoints
|
||||
}
|
||||
|
||||
// GetTransactionDetails returns details of a transaction given its
|
||||
// transaction hash.
|
||||
func (b *BtcWallet) GetTransactionDetails(
|
||||
txHash *chainhash.Hash) (*lnwallet.TransactionDetail, error) {
|
||||
|
||||
// Grab the best block the wallet knows of, we'll use this to calculate
|
||||
// # of confirmations shortly below.
|
||||
bestBlock := b.wallet.Manager.SyncedTo()
|
||||
currentHeight := bestBlock.Height
|
||||
tx, err := b.wallet.GetTransaction(*txHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// For both confirmed and unconfirmed transactions, create a
|
||||
// TransactionDetail which re-packages the data returned by the base
|
||||
// wallet.
|
||||
if tx.Confirmations > 0 {
|
||||
txDetails, err := minedTransactionsToDetails(
|
||||
currentHeight,
|
||||
base.Block{
|
||||
Transactions: []base.TransactionSummary{
|
||||
tx.Summary,
|
||||
},
|
||||
Hash: tx.BlockHash,
|
||||
Height: tx.Height,
|
||||
Timestamp: tx.Summary.Timestamp},
|
||||
b.netParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return txDetails[0], nil
|
||||
}
|
||||
|
||||
return unminedTransactionsToDetail(tx.Summary, b.netParams)
|
||||
}
|
||||
|
||||
// minedTransactionsToDetails is a helper function which converts a summary
|
||||
// information about mined transactions to a TransactionDetail.
|
||||
func minedTransactionsToDetails(
|
||||
|
||||
@@ -356,6 +356,11 @@ type WalletController interface {
|
||||
CreateSimpleTx(outputs []*wire.TxOut, feeRate chainfee.SatPerKWeight,
|
||||
minConfs int32, dryRun bool) (*txauthor.AuthoredTx, error)
|
||||
|
||||
// GetTransactionDetails returns a detailed description of a transaction
|
||||
// given its transaction hash.
|
||||
GetTransactionDetails(txHash *chainhash.Hash) (
|
||||
*TransactionDetail, error)
|
||||
|
||||
// ListUnspentWitness returns all unspent outputs which are version 0
|
||||
// witness programs. The 'minConfs' and 'maxConfs' parameters
|
||||
// indicate the minimum and maximum number of confirmations an output
|
||||
|
||||
@@ -243,6 +243,13 @@ func (w *mockWalletController) PublishTransaction(tx *wire.MsgTx,
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTransactionDetails currently does nothing.
|
||||
func (w *mockWalletController) GetTransactionDetails(*chainhash.Hash) (
|
||||
*TransactionDetail, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// LabelTransaction currently does nothing.
|
||||
func (w *mockWalletController) LabelTransaction(chainhash.Hash, string,
|
||||
bool) error {
|
||||
|
||||
Reference in new issue
Block a user