Skip to content

Commit cf222cf

Browse files
committed
move connectorsIndex validation to validateVtxoTree
1 parent 4f35ca7 commit cf222cf

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

pkg/client-sdk/covenantless_client.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ func (a *covenantlessArkClient) handleRoundFinalization(
19421942
boardingUtxos []types.Utxo,
19431943
receivers []client.Output,
19441944
) ([]string, string, error) {
1945-
if err := a.validateVtxoTree(event, receivers, len(vtxos) > 0); err != nil {
1945+
if err := a.validateVtxoTree(event, receivers, vtxos); err != nil {
19461946
return nil, "", fmt.Errorf("failed to verify vtxo tree: %s", err)
19471947
}
19481948

@@ -2031,7 +2031,7 @@ func (a *covenantlessArkClient) handleRoundFinalization(
20312031
}
20322032

20332033
func (a *covenantlessArkClient) validateVtxoTree(
2034-
event client.RoundFinalizationEvent, receivers []client.Output, needConnector bool,
2034+
event client.RoundFinalizationEvent, receivers []client.Output, vtxosInput []client.TapscriptsVtxo,
20352035
) error {
20362036
roundTx := event.Tx
20372037
ptx, err := psbt.NewFromRawBytes(strings.NewReader(roundTx), true)
@@ -2053,7 +2053,7 @@ func (a *covenantlessArkClient) validateVtxoTree(
20532053
return err
20542054
}
20552055

2056-
if needConnector {
2056+
if len(vtxosInput) > 0 {
20572057
root, err := event.Connectors.Root()
20582058
if err != nil {
20592059
return err
@@ -2072,7 +2072,19 @@ func (a *covenantlessArkClient) validateVtxoTree(
20722072
return fmt.Errorf("root's parent txid is not the same as the round txid: %s != %s", root.ParentTxid, getTxID(roundTx))
20732073
}
20742074

2075-
return event.Connectors.Validate(getTxID)
2075+
if err := event.Connectors.Validate(getTxID); err != nil {
2076+
return err
2077+
}
2078+
2079+
if len(event.ConnectorsIndex) == 0 {
2080+
return fmt.Errorf("empty connectors index")
2081+
}
2082+
2083+
for _, vtxo := range vtxosInput {
2084+
if _, ok := event.ConnectorsIndex[vtxo.Outpoint.String()]; !ok {
2085+
return fmt.Errorf("missing connector index for vtxo %s", vtxo.String())
2086+
}
2087+
}
20762088
}
20772089

20782090
return nil
@@ -2205,10 +2217,7 @@ func (a *covenantlessArkClient) createAndSignForfeits(
22052217
signedForfeits := make([]string, 0, len(vtxosToSign))
22062218

22072219
for _, vtxo := range vtxosToSign {
2208-
connectorOutpoint, ok := connectorsIndex[vtxo.Outpoint.String()]
2209-
if !ok {
2210-
return nil, fmt.Errorf("connector index not found for vtxo %s", vtxo.Outpoint.String())
2211-
}
2220+
connectorOutpoint := connectorsIndex[vtxo.Outpoint.String()]
22122221

22132222
var connector *wire.TxOut
22142223
for _, node := range connectorsTxs {

0 commit comments

Comments
 (0)