@@ -3151,24 +3151,30 @@ func (a *AssetStore) PendingParcels(
31513151// QueryParcels returns the set of confirmed or unconfirmed parcels.
31523152func (a * AssetStore ) QueryParcels (ctx context.Context ,
31533153 anchorTxHash * chainhash.Hash ,
3154- pending bool ) ([]* tapfreighter.OutboundParcel , error ) {
3154+ unconfirmedTxOnly bool ) ([]* tapfreighter.OutboundParcel , error ) {
31553155
3156- var transfers []* tapfreighter.OutboundParcel
3156+ var (
3157+ outboundParcels []* tapfreighter.OutboundParcel
3158+ readOpts = NewAssetStoreReadTx ()
3159+ )
31573160
3158- readOpts := NewAssetStoreReadTx ()
31593161 dbErr := a .db .ExecTx (ctx , & readOpts , func (q ActiveAssetsStore ) error {
31603162 // Construct transfer query.
3161- transferQuery := TransferQuery {
3162- UnconfOnly : pending ,
3163+ //
3164+ // Serialise anchor tx hash as bytes if specified.
3165+ var anchorTxHashBytes []byte
3166+ if anchorTxHash != nil {
3167+ anchorTxHashBytes = anchorTxHash [:]
31633168 }
31643169
3165- // Include anchor tx hash if specified.
3166- if anchorTxHash != nil {
3167- transferQuery .AnchorTxHash = anchorTxHash [:]
3170+ transferQuery := TransferQuery {
3171+ // If we want unconfirmed transfers only, we set the
3172+ // UnconfOnly field to true.
3173+ UnconfOnly : unconfirmedTxOnly ,
3174+ AnchorTxHash : anchorTxHashBytes ,
31683175 }
31693176
3170- // If we want every unconfirmed transfer, then we only pass in
3171- // the UnconfOnly field.
3177+ // Query for asset transfers.
31723178 dbTransfers , err := q .QueryAssetTransfers (ctx , transferQuery )
31733179 if err != nil {
31743180 return err
@@ -3177,6 +3183,7 @@ func (a *AssetStore) QueryParcels(ctx context.Context,
31773183 for idx := range dbTransfers {
31783184 dbT := dbTransfers [idx ]
31793185
3186+ // Fetch the inputs and outputs for the transfer.
31803187 inputs , err := fetchAssetTransferInputs (ctx , q , dbT .ID )
31813188 if err != nil {
31823189 return fmt .Errorf ("unable to fetch transfer " +
@@ -3192,7 +3199,8 @@ func (a *AssetStore) QueryParcels(ctx context.Context,
31923199 }
31933200
31943201 // We know that the anchor transaction is the same for
3195- // each output, we can just fetch the first.
3202+ // each output. Therefore, we use the first output to
3203+ // fetch the transfer's anchor transaction.
31963204 if len (outputs ) == 0 {
31973205 return fmt .Errorf ("no outputs for transfer" )
31983206 }
@@ -3213,15 +3221,15 @@ func (a *AssetStore) QueryParcels(ctx context.Context,
32133221 "anchor tx: %w" , err )
32143222 }
32153223
3216- transfer := & tapfreighter.OutboundParcel {
3224+ parcel := & tapfreighter.OutboundParcel {
32173225 AnchorTx : anchorTx ,
32183226 AnchorTxHeightHint : uint32 (dbT .HeightHint ),
32193227 TransferTime : dbT .TransferTimeUnix .UTC (),
32203228 ChainFees : dbAnchorTx .ChainFees ,
32213229 Inputs : inputs ,
32223230 Outputs : outputs ,
32233231 }
3224- transfers = append (transfers , transfer )
3232+ outboundParcels = append (outboundParcels , parcel )
32253233 }
32263234
32273235 return nil
@@ -3230,7 +3238,7 @@ func (a *AssetStore) QueryParcels(ctx context.Context,
32303238 return nil , dbErr
32313239 }
32323240
3233- return transfers , nil
3241+ return outboundParcels , nil
32343242}
32353243
32363244// ErrAssetMetaNotFound is returned when an asset meta is not found in the
0 commit comments