mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-09 22:28:04 -05:00
XMR taker is relayer of last resort for the maker (#366)
Co-authored-by: noot <36753753+noot@users.noreply.github.com>
This commit is contained in:
@@ -11,9 +11,12 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/athanorlabs/atomic-swap/common"
|
||||
"github.com/athanorlabs/atomic-swap/common/types"
|
||||
mcrypto "github.com/athanorlabs/atomic-swap/crypto/monero"
|
||||
)
|
||||
|
||||
@@ -52,6 +55,75 @@ func StageToString(stage byte) string {
|
||||
}
|
||||
}
|
||||
|
||||
// SwapID calculates and returns the same hashed swap identifier that newSwap
|
||||
// emits and that is used to track the on-chain stage of a swap.
|
||||
func (sfs *SwapFactorySwap) SwapID() types.Hash {
|
||||
uint256Ty, err := abi.NewType("uint256", "", nil)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create uint256 type: %s", err))
|
||||
}
|
||||
|
||||
bytes32Ty, err := abi.NewType("bytes32", "", nil)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create bytes32 type: %s", err))
|
||||
}
|
||||
|
||||
addressTy, err := abi.NewType("address", "", nil)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create address type: %s", err))
|
||||
}
|
||||
|
||||
arguments := abi.Arguments{
|
||||
{
|
||||
Type: addressTy,
|
||||
},
|
||||
{
|
||||
Type: addressTy,
|
||||
},
|
||||
{
|
||||
Type: bytes32Ty,
|
||||
},
|
||||
{
|
||||
Type: bytes32Ty,
|
||||
},
|
||||
{
|
||||
Type: uint256Ty,
|
||||
},
|
||||
{
|
||||
Type: uint256Ty,
|
||||
},
|
||||
{
|
||||
Type: addressTy,
|
||||
},
|
||||
{
|
||||
Type: uint256Ty,
|
||||
},
|
||||
{
|
||||
Type: uint256Ty,
|
||||
},
|
||||
}
|
||||
|
||||
args, err := arguments.Pack(
|
||||
sfs.Owner,
|
||||
sfs.Claimer,
|
||||
sfs.PubKeyClaim,
|
||||
sfs.PubKeyRefund,
|
||||
sfs.Timeout0,
|
||||
sfs.Timeout1,
|
||||
sfs.Asset,
|
||||
sfs.Value,
|
||||
sfs.Nonce,
|
||||
)
|
||||
if err != nil {
|
||||
// As long as none of the *big.Int fields are nil, this cannot fail.
|
||||
// When receiving SwapFactorySwap objects from the database or peers in
|
||||
// JSON, all *big.Int values are pre-validated to be non-nil.
|
||||
panic(fmt.Sprintf("failed to pack arguments: %s", err))
|
||||
}
|
||||
|
||||
return crypto.Keccak256Hash(args)
|
||||
}
|
||||
|
||||
// GetSecretFromLog returns the secret from a Claimed or Refunded log
|
||||
func GetSecretFromLog(log *ethtypes.Log, eventTopic [32]byte) (*mcrypto.PrivateSpendKey, error) {
|
||||
if eventTopic != claimedTopic && eventTopic != refundedTopic {
|
||||
|
||||
Reference in New Issue
Block a user