mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +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
|
||||
}
|
||||
|
||||
// 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.
|
||||
func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
||||
var destAddresses []string
|
||||
for _, destAddress := range tx.DestAddresses {
|
||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
||||
// Re-package destination output information.
|
||||
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.
|
||||
@ -38,6 +60,7 @@ func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
||||
TimeStamp: tx.Timestamp,
|
||||
TotalFees: tx.TotalFees,
|
||||
DestAddresses: destAddresses,
|
||||
OutputDetails: outputDetails,
|
||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
||||
Label: tx.Label,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user