Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extract atomic swap data pushes #2203

Merged
merged 8 commits into from
Dec 11, 2023
4 changes: 2 additions & 2 deletions app/appmessage/domainconverters.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externa
Outputs: outputs,
LockTime: rpcTransaction.LockTime,
SubnetworkID: *subnetworkID,
Gas: rpcTransaction.LockTime,
Gas: rpcTransaction.Gas,
Payload: payload,
}, nil
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransactio
Outputs: outputs,
LockTime: transaction.LockTime,
SubnetworkID: subnetworkID,
Gas: transaction.LockTime,
Gas: transaction.Gas,
Payload: payload,
}
}
Expand Down
21 changes: 10 additions & 11 deletions domain/consensus/utils/txscript/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
return nil, err
}

if len(pops) != 20 {
if len(pops) != 19 {
return nil, nil
}
isAtomicSwap := pops[0].opcode.value == OpIf &&
Expand All @@ -403,23 +403,22 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
pops[10].opcode.value == OpElse &&
canonicalPush(pops[11]) &&
pops[12].opcode.value == OpCheckLockTimeVerify &&
pops[13].opcode.value == OpDrop &&
pops[14].opcode.value == OpDup &&
pops[15].opcode.value == OpBlake2b &&
pops[16].opcode.value == OpData32 &&
pops[17].opcode.value == OpEndIf &&
pops[18].opcode.value == OpEqualVerify &&
pops[19].opcode.value == OpCheckSig
pops[13].opcode.value == OpDup &&
pops[14].opcode.value == OpBlake2b &&
pops[15].opcode.value == OpData32 &&
pops[16].opcode.value == OpEndIf &&
pops[17].opcode.value == OpEqualVerify &&
pops[18].opcode.value == OpCheckSig
if !isAtomicSwap {
return nil, nil
}

pushes := new(AtomicSwapDataPushes)
copy(pushes.SecretHash[:], pops[5].data)
copy(pushes.RecipientBlake2b[:], pops[9].data)
copy(pushes.RefundBlake2b[:], pops[16].data)
copy(pushes.RefundBlake2b[:], pops[15].data)
if pops[2].data != nil {
locktime, err := makeScriptNum(pops[2].data, 5)
locktime, err := makeScriptNum(pops[2].data, 8)
if err != nil {
return nil, nil
}
Expand All @@ -430,7 +429,7 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
return nil, nil
}
if pops[11].data != nil {
locktime, err := makeScriptNum(pops[11].data, 5)
locktime, err := makeScriptNum(pops[11].data, 8)
if err != nil {
return nil, nil
}
Expand Down