mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 02:00:54 +02:00
multi: populate both string and byte TXID in lnrpc.Outpoint
This commit adds a a new `MarshalOutPoint` helper in the `lnrpc` package that can be used to convert a `wire.Outpoint` to an `lnrpc.Outpoint`. By using this helper, we are less likely to forget to populate both the string and byte form of the TXID.
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@ -106,11 +107,7 @@ func MarshalUtxos(utxos []*lnwallet.Utxo, activeNetParams *chaincfg.Params) (
|
||||
|
||||
// Now that we know we have a proper mapping to an address,
|
||||
// we'll convert the regular outpoint to an lnrpc variant.
|
||||
outpoint := &OutPoint{
|
||||
TxidBytes: utxo.OutPoint.Hash[:],
|
||||
TxidStr: utxo.OutPoint.Hash.String(),
|
||||
OutputIndex: utxo.OutPoint.Index,
|
||||
}
|
||||
outpoint := MarshalOutPoint(&utxo.OutPoint)
|
||||
|
||||
utxoResp := Utxo{
|
||||
AddressType: addrType,
|
||||
@ -173,3 +170,12 @@ func MarshallOutputType(o txscript.ScriptClass) OutputScriptType {
|
||||
return OutputScriptType_SCRIPT_TYPE_PUBKEY_HASH
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalOutPoint converts a wire.OutPoint to its proto counterpart.
|
||||
func MarshalOutPoint(op *wire.OutPoint) *OutPoint {
|
||||
return &OutPoint{
|
||||
TxidBytes: op.Hash[:],
|
||||
TxidStr: op.Hash.String(),
|
||||
OutputIndex: op.Index,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user