mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
lnrpc: add DestOutput information to RPC GetTransactions
This commit is contained in:
parent
188b39268d
commit
48c773ec87
@ -141,3 +141,31 @@ func MarshalUtxos(utxos []*lnwallet.Utxo, activeNetParams *chaincfg.Params) (
|
|||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshallOutputType translates a txscript.ScriptClass into a
|
||||||
|
// lnrpc.OutputScriptType.
|
||||||
|
func MarshallOutputType(o txscript.ScriptClass) (ret OutputScriptType) {
|
||||||
|
// Translate txscript ScriptClass type to the proper gRPC proto
|
||||||
|
// output script type.
|
||||||
|
switch o {
|
||||||
|
case txscript.PubKeyHashTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_PUBKEY_HASH
|
||||||
|
case txscript.ScriptHashTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_SCRIPT_HASH
|
||||||
|
case txscript.WitnessV0PubKeyHashTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_WITNESS_V0_PUBKEY_HASH
|
||||||
|
case txscript.WitnessV0ScriptHashTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_WITNESS_V0_SCRIPT_HASH
|
||||||
|
case txscript.PubKeyTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_PUBKEY
|
||||||
|
case txscript.MultiSigTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_MULTISIG
|
||||||
|
case txscript.NullDataTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_NULLDATA
|
||||||
|
case txscript.NonStandardTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_NON_STANDARD
|
||||||
|
case txscript.WitnessUnknownTy:
|
||||||
|
ret = OutputScriptType_SCRIPT_TYPE_WITNESS_UNKNOWN
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -19,8 +19,30 @@ const (
|
|||||||
// RPCTransaction returns a rpc transaction.
|
// RPCTransaction returns a rpc transaction.
|
||||||
func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
||||||
var destAddresses []string
|
var destAddresses []string
|
||||||
for _, destAddress := range tx.DestAddresses {
|
// Re-package destination output information.
|
||||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
var outputDetails []*OutputDetail
|
||||||
|
for _, o := range tx.OutputDetails {
|
||||||
|
// Note: DestAddresses is deprecated but we keep
|
||||||
|
// populating it with addresses for backwards
|
||||||
|
// compatibility.
|
||||||
|
for _, a := range o.Addresses {
|
||||||
|
destAddresses = append(destAddresses,
|
||||||
|
a.EncodeAddress())
|
||||||
|
}
|
||||||
|
|
||||||
|
var address string
|
||||||
|
if len(o.Addresses) == 1 {
|
||||||
|
address = o.Addresses[0].EncodeAddress()
|
||||||
|
}
|
||||||
|
|
||||||
|
outputDetails = append(outputDetails, &OutputDetail{
|
||||||
|
OutputType: MarshallOutputType(o.OutputType),
|
||||||
|
Address: address,
|
||||||
|
PkScript: hex.EncodeToString(o.PkScript),
|
||||||
|
OutputIndex: int64(o.OutputIndex),
|
||||||
|
Amount: int64(o.Value),
|
||||||
|
IsOurAddress: o.IsOurAddress,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// We also get unconfirmed transactions, so BlockHash can be nil.
|
// We also get unconfirmed transactions, so BlockHash can be nil.
|
||||||
@ -38,6 +60,7 @@ func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
|||||||
TimeStamp: tx.Timestamp,
|
TimeStamp: tx.Timestamp,
|
||||||
TotalFees: tx.TotalFees,
|
TotalFees: tx.TotalFees,
|
||||||
DestAddresses: destAddresses,
|
DestAddresses: destAddresses,
|
||||||
|
OutputDetails: outputDetails,
|
||||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
RawTxHex: hex.EncodeToString(tx.RawTx),
|
||||||
Label: tx.Label,
|
Label: tx.Label,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user