Skip to content

Commit

Permalink
arrayify swapReceipt.secretHash
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Dec 7, 2021
1 parent e7f2edc commit 5dc6d61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func (eth *ExchangeWallet) unlockFunds(coins asset.Coins) error {
// swapReceipt implements the asset.Receipt interface for ETH.
type swapReceipt struct {
txHash common.Hash
secretHash []byte
secretHash [dexeth.SecretHashSize]byte
// expiration and value can be determined with a blockchain
// lookup, but we cache these values to avoid this.
expiration time.Time
Expand All @@ -594,9 +594,7 @@ func (r *swapReceipt) Coin() asset.Coin {
// Contract returns the swap's identifying data, which the concatenation of the
// contract version and the secret hash.
func (r *swapReceipt) Contract() dex.Bytes {
var secretHash [32]byte
copy(secretHash[:], r.secretHash)
return dexeth.EncodeContractData(r.ver, secretHash)
return dexeth.EncodeContractData(r.ver, r.secretHash)
}

// String returns a string representation of the swapReceipt.
Expand Down Expand Up @@ -653,12 +651,14 @@ func (eth *ExchangeWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin

txHash := tx.Hash()
for _, swap := range swaps.Contracts {
var secretHash [dexeth.SecretHashSize]byte
copy(secretHash[:], swap.SecretHash)
receipts = append(receipts,
&swapReceipt{
expiration: encode.UnixTimeMilli(int64(swap.LockTime)),
value: swap.Value,
txHash: txHash,
secretHash: swap.SecretHash,
secretHash: secretHash,
ver: swaps.AssetVersion,
})
}
Expand Down
2 changes: 1 addition & 1 deletion client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func TestSwap(t *testing.T) {
if swaps.AssetVersion != ver {
t.Fatal("wrong contract version")
}
if !bytes.Equal(contractData[4:], secretHash[:]) {
if !bytes.Equal(contract.SecretHash, secretHash[:]) {
t.Fatalf("%v, contract: %x != secret hash in input: %x",
testName, receipt.Contract(), secretHash)
}
Expand Down

0 comments on commit 5dc6d61

Please sign in to comment.