@@ -2401,20 +2401,50 @@ func insertAssetTransferOutput(ctx context.Context, q ActiveAssetsStore,
24012401 return fmt .Errorf ("unable to insert script key: %w" , err )
24022402 }
24032403
2404+ // Now we will mark the output proof as undelivered if it is intended
2405+ // for a counterpart.
2406+ //
2407+ // If the transfer output proof is not intended for a counterpart the
2408+ // `proofDeliveryComplete` field will be left as NULL. Otherwise, we set
2409+ // it to false to indicate that the proof has not been delivered yet.
2410+ shouldDeliverProof , err := output .ShouldDeliverProof ()
2411+ if err != nil {
2412+ return fmt .Errorf ("unable to determine if proof should be " +
2413+ "delivery for given transfer output: %w" , err )
2414+ }
2415+
2416+ var proofDeliveryComplete sql.NullBool
2417+ if shouldDeliverProof {
2418+ proofDeliveryComplete = sql.NullBool {
2419+ Bool : false ,
2420+ Valid : true ,
2421+ }
2422+ }
2423+
2424+ // Check if position value can be stored in a 32-bit integer. Type cast
2425+ // if possible, otherwise return an error.
2426+ if output .Position > math .MaxInt32 {
2427+ return fmt .Errorf ("position value %d is too large for db " +
2428+ "storage" , output .Position )
2429+ }
2430+ position := int32 (output .Position )
2431+
24042432 dbOutput := NewTransferOutput {
2405- TransferID : transferID ,
2406- AnchorUtxo : newUtxoID ,
2407- ScriptKey : scriptKeyID ,
2408- ScriptKeyLocal : output .ScriptKeyLocal ,
2409- Amount : int64 (output .Amount ),
2410- LockTime : sqlInt32 (output .LockTime ),
2411- RelativeLockTime : sqlInt32 (output .RelativeLockTime ),
2412- AssetVersion : int32 (output .AssetVersion ),
2413- SerializedWitnesses : witnessBuf .Bytes (),
2414- ProofSuffix : output .ProofSuffix ,
2415- NumPassiveAssets : int32 (output .Anchor .NumPassiveAssets ),
2416- OutputType : int16 (output .Type ),
2417- ProofCourierAddr : output .ProofCourierAddr ,
2433+ TransferID : transferID ,
2434+ AnchorUtxo : newUtxoID ,
2435+ ScriptKey : scriptKeyID ,
2436+ ScriptKeyLocal : output .ScriptKeyLocal ,
2437+ Amount : int64 (output .Amount ),
2438+ LockTime : sqlInt32 (output .LockTime ),
2439+ RelativeLockTime : sqlInt32 (output .RelativeLockTime ),
2440+ AssetVersion : int32 (output .AssetVersion ),
2441+ SerializedWitnesses : witnessBuf .Bytes (),
2442+ ProofSuffix : output .ProofSuffix ,
2443+ NumPassiveAssets : int32 (output .Anchor .NumPassiveAssets ),
2444+ OutputType : int16 (output .Type ),
2445+ ProofCourierAddr : output .ProofCourierAddr ,
2446+ ProofDeliveryComplete : proofDeliveryComplete ,
2447+ Position : position ,
24182448 }
24192449
24202450 // There might not have been a split, so we can't rely on the split root
@@ -2526,6 +2556,22 @@ func fetchAssetTransferOutputs(ctx context.Context, q ActiveAssetsStore,
25262556 outputAnchor .CommitmentVersion = fn .Ptr (dbRootVersion )
25272557 }
25282558
2559+ // Parse the proof deliver complete flag from the database.
2560+ var proofDeliveryComplete fn.Option [bool ]
2561+ if dbOut .ProofDeliveryComplete .Valid {
2562+ proofDeliveryComplete = fn .Some (
2563+ dbOut .ProofDeliveryComplete .Bool ,
2564+ )
2565+ }
2566+
2567+ vOutputType := tappsbt .VOutputType (dbOut .OutputType )
2568+
2569+ // Ensure the position value is valid.
2570+ if dbOut .Position < 0 {
2571+ return nil , fmt .Errorf ("invalid position value in " +
2572+ "db: %d" , dbOut .Position )
2573+ }
2574+
25292575 outputs [idx ] = tapfreighter.TransferOutput {
25302576 Anchor : outputAnchor ,
25312577 Amount : uint64 (dbOut .Amount ),
@@ -2549,9 +2595,11 @@ func fetchAssetTransferOutputs(ctx context.Context, q ActiveAssetsStore,
25492595 splitRootHash ,
25502596 uint64 (dbOut .SplitCommitmentRootValue .Int64 ),
25512597 ),
2552- ProofSuffix : dbOut .ProofSuffix ,
2553- Type : tappsbt .VOutputType (dbOut .OutputType ),
2554- ProofCourierAddr : dbOut .ProofCourierAddr ,
2598+ ProofSuffix : dbOut .ProofSuffix ,
2599+ Type : vOutputType ,
2600+ ProofCourierAddr : dbOut .ProofCourierAddr ,
2601+ ProofDeliveryComplete : proofDeliveryComplete ,
2602+ Position : uint64 (dbOut .Position ),
25552603 }
25562604
25572605 err = readOutPoint (
@@ -2794,10 +2842,10 @@ func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context,
27942842 ! out .ScriptKeyLocal && ! isKnown
27952843
27962844 log .Tracef ("Skip asset creation for " +
2797- "output %d?: %v, scriptKey=%x, " +
2845+ "output %d?: %v, position=%v, scriptKey=%x, " +
27982846 "isTombstone=%v, isBurn=%v, " +
27992847 "scriptKeyLocal=%v, scriptKeyKnown=%v" ,
2800- idx , skipAssetCreation ,
2848+ idx , skipAssetCreation , out . Position ,
28012849 scriptPubKey .SerializeCompressed (),
28022850 isTombstone , isBurn , out .ScriptKeyLocal ,
28032851 isKnown )
0 commit comments