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

dex/networks,server/eth: decode swap data message blob #1320

Merged
merged 1 commit into from
Dec 8, 2021

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Dec 1, 2021

The msgjson.Init.Contract and server/asset.Contract.RedeemScript fields
contain an encoding of the ETH contract version concatenated with the
swap's secret hash that is the unique key for the swap.

This updates server/asset/eth's ValidateContract and Contract methods
to decode and check this data.

This also adds the dexeth.EncodeContractData and DecodeContractData functions.

@chappjc chappjc force-pushed the eth-server-contract-ver branch from cd2d8ab to 360e6d7 Compare December 7, 2021 02:55
@chappjc
Copy link
Member Author

chappjc commented Dec 7, 2021

Not quite ready, but rebased and slightly updated.

live_test.go needs the lgpl build flag now.

@chappjc chappjc force-pushed the eth-server-contract-ver branch from 360e6d7 to e7f2edc Compare December 7, 2021 16:50
client/asset/eth/eth.go Show resolved Hide resolved
client/asset/eth/eth.go Outdated Show resolved Hide resolved
Comment on lines -280 to -282
// Contract is the contract script.
// Contract is the unique swap contract data. This may be a redeem script
// for UTXO assets, or other information that uniquely identifies the swap
// for account-based assets e.g. a contract version and secret hash for ETH.
Contract dex.Bytes
// SecretHash is the contract's secret hash.
Copy link
Member Author

@chappjc chappjc Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting that these two fields were already redundant. The SecretHash field is basically a convenience, or possibly useful in a future asset if the Contract bytes is distinct, but I don't see that happening. Either way, I'm not inclined to remove it.

client/asset/interface.go Show resolved Hide resolved
client/core/trade.go Show resolved Hide resolved
client/webserver/live_test.go Show resolved Hide resolved
client/webserver/live_test.go Show resolved Hide resolved
dex/networks/eth/params.go Show resolved Hide resolved
client/asset/eth/eth.go Show resolved Hide resolved
@chappjc chappjc marked this pull request as ready for review December 7, 2021 17:02
// from redemption.Spends.Contract. Even for scriptable UTXO assets, the
// redeem script in this Contract field is redundant with the SecretHash
// field as ExtractSwapDetails can be applied to extract the hash.
ver, secretHash, err := dexeth.DecodeContractData(redemption.Spends.Contract)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that AuditContract is still in PR, but see also my comment: https://github.com/decred/dcrdex/pull/1319/files#r764101981

client/asset/eth/eth_test.go Outdated Show resolved Hide resolved
server/asset/eth/coiner.go Outdated Show resolved Hide resolved
@chappjc chappjc force-pushed the eth-server-contract-ver branch from 5dc6d61 to 8181c18 Compare December 8, 2021 14:59
The msgjson.Init.Contract and server/asset.Contract.RedeemScript fields
contain an encoding of the ETH contract version concatenated with the
swap's secret hash that is the unique key for the swap.

This updates server/asset/eth's ValidateContract and Contract methods
to decode and check this data.

This also adds the dexeth.EncodeSwapData and DecodeSwapData functions.

Arrayify swapReceipt.secretHash.
@chappjc chappjc force-pushed the eth-server-contract-ver branch from 8181c18 to 01d24bf Compare December 8, 2021 15:01
@chappjc chappjc merged commit 6c947e0 into decred:master Dec 8, 2021
@chappjc chappjc deleted the eth-server-contract-ver branch December 8, 2021 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants