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

eth: Add backend methods. #1154

Closed
24 of 27 tasks
JoeGruffins opened this issue Aug 6, 2021 · 33 comments · Fixed by #1363
Closed
24 of 27 tasks

eth: Add backend methods. #1154

JoeGruffins opened this issue Aug 6, 2021 · 33 comments · Fixed by #1363

Comments

@JoeGruffins
Copy link
Member

JoeGruffins commented Aug 6, 2021

This issue is meant to track adding functionality to eth swaps. Currently there is a bare bones implementation. Anyone who would like to work on adding a method, please comment here first so work is not duplicated.

As the dex was originally designed with UTXO based coins in mind, some methods may require far reaching changes.

server

  • TxData(coinID []byte) ([]byte, error)
  • InitTxSize() uint32
  • InitTxSizeBase() uint32
  • Contract(coinID []byte, redeemScript []byte) (*asset.Contract, error)
  • ValidateSecret(secret, contract []byte) bool
  • Redemption(redemptionID, contractID []byte) (asset.Coin, error)

- [ ] FundingCoin(ctx context.Context, coinID []byte, redeemScript []byte) (asset.FundingCoin, error)

  • ValidateCoinID(coinID []byte) (string, error)
  • ValidateContract(contract []byte) error

- [ ] VerifyUnspentCoin(ctx context.Context, coinID []byte)

  • run(ctx context.Context) // fix TODOs and refactor
  • ValidateSignature(addr string, pubkey, msg, sig []byte) error

client

  • Balance() (*asset.Balance, error) // fix TODO
  • MaxOrder(lotSize uint64, feeSuggestion uint64, nfo *dex.Asset) (*asset.SwapEstimate, error)
  • PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
  • PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
  • FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, error)
  • ReturnCoins(unspents asset.Coins) error
  • FundingCoins(ids []dex.Bytes) (asset.Coins, error)
  • Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
  • Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
  • SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)
  • AuditContract(coinID, contract, txData dex.Bytes) (*asset.AuditInfo, error)
  • LocktimeExpired(contract dex.Bytes) (bool, time.Time, error)
  • FindRedemption(ctx context.Context, coinID dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
  • Refund(coinID, contract dex.Bytes) (dex.Bytes, error) // fix TODOs
  • PayFee(address string, regFee uint64) (asset.Coin, error)
  • Withdraw(addr string, value uint64) (asset.Coin, error) // fix TODOs

- [ ] Confirmations(ctx context.Context, id dex.Bytes) (confs uint32, spent bool, err error)
- [ ] RefundAddress(contract dex.Bytes) (string, error)

  • checkForNewBlocks() // Needs logic to check for redemptions.
changelog
2021
08/06 - issue created
09/02 - check server InitTxSize() uint32 and InitTxSizeBase() uint32
10/05 - check client MaxOrder, PreSwap, and PreRedeem
10/18 - check server Contract and client SignMessage, FundingCoins, ReturnCoins, and FundOrder
10/21 - check server ValidateSecret and Redemption
11/05 - check server ValidateCoinID
11/11 - FundingCoin and VerifyUnspentCoin removed from server list
11/24 - check server TxData and ValidateContract
12/02 - check client Swap and Balance, add fix TODOs to Withdrawal, RefundAddress removed by #1312
12/16 - check server run and client Redeem, AuditContract, LocktimeExpired, FindRedemption, and checkForNewBlocks
12/17 - check server Refund and remove Confirmations, it looks like that was divided into SwapConfs and RegFeeConfs and those are done, add ValidateSignature to server
@JoeGruffins
Copy link
Member Author

JoeGruffins commented Aug 12, 2021

Will work on the server's TxData(coinID []byte) ([]byte, error)
That's right, this isn't used yet. Because I don't have a great idea of how it will be used atm, I'll go with the next server one InitTxSize() uint32

@JoeGruffins
Copy link
Member Author

JoeGruffins commented Aug 13, 2021

Included InitTxSizeBase() uint32 in the same pr as InitTxSize() uint32

Will do Contract(coinID []byte, redeemScript []byte) (*asset.Contract, error) for the server.

@martonp
Copy link
Contributor

martonp commented Aug 24, 2021

I'll work on the client MaxOrder(lotSize uint64, feeSuggestion uint64, nfo *dex.Asset) (*asset.SwapEstimate, error).

@martonp
Copy link
Contributor

martonp commented Sep 1, 2021

I'll do PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error) next.

@JoeGruffins
Copy link
Member Author

Contract is in the pipeline so moving to server's ValidateSecret(secret, contract []byte) bool

@JoeGruffins
Copy link
Member Author

#1089 will change/add some client methods

@JoeGruffins
Copy link
Member Author

Will do Redemption(redemptionID, contractID []byte) (asset.Coin, error) for the server.

@JoeGruffins
Copy link
Member Author

Also started on FundingCoin(ctx context.Context, coinID []byte, redeemScript []byte) (asset.FundingCoin, error) because Contract, Redemption, and FundingCoin all use the same asset.Coin interface to some extent.

@martonp
Copy link
Contributor

martonp commented Sep 17, 2021

I'll do PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error) next.

@martonp
Copy link
Contributor

martonp commented Sep 17, 2021

I'll do FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, error) next.

@martonp
Copy link
Contributor

martonp commented Sep 30, 2021

Will do Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error) next.

@JoeGruffins
Copy link
Member Author

Will work on server's ValidateCoinID.

@martonp
Copy link
Contributor

martonp commented Nov 3, 2021

Will do Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)

@JoeGruffins
Copy link
Member Author

Actually looks like ValidateCoinID was already done, doing ValidateContract

@buck54321
Copy link
Member

I'll do TxData

@buck54321
Copy link
Member

@JoeGruffins please remove the FundingCoin and VerifyUnspentCoin methods from the server list. We'll have to handle that a bit differently. I'll offer up something in a minute.

@JoeGruffins
Copy link
Member Author

@buck54321 #1243 exists

@buck54321
Copy link
Member

@buck54321 #1243 exists

I'm really sorry about that, @JoeGruffins. I should have taken a wider look at this stuff earlier.

@JoeGruffins
Copy link
Member Author

it's fine. I really didn't want to mess with the server as much as possible, but I'm confident your way is better. I was just going to shoehorn it in there.

@buck54321
Copy link
Member

buck54321 commented Nov 15, 2021

Here's what I'm looking at for required communications.

Message Required Currently Sending Recommended Action Field assignments
Limit / Market account address account address, amount, nonce drop nonce. 1 Trade.Coins = []Coin{[]byte(accountAddr)}
Init txid, secret hash txid, secret hash, contract address drop contract address. 2 txid = CoinID, secretHash = Contract
Redeem secret (maker) 3 n / a we'll send the secret secret = Secret

1 Leave amount encoded for internal use, but only send address in the actual Message.

2 I'm going to propose something different for contract address validation, but if we do want to validate the contract address, it'll need to be done earlier than this anyway, so let's not plan to send it here.

3 We may want to record the redemption transaction IDs too, but it seems less important for eth.

There's also Cancel, but that' straightforward once we get a signature algo figured out.

This was referenced Nov 17, 2021
@JoeGruffins
Copy link
Member Author

I'll look into the server run and what's up with eth reorgs. Not working in this area are you @buck54321 ?

@buck54321
Copy link
Member

Go for it, @JoeGruffins.

I'll claim Confirmations -> SwapConfirmations + RegFeeConfirmations

@chappjc
Copy link
Member

chappjc commented Nov 24, 2021

@buck54321 If you're working on SwapConfirmations, please consider how we can apply the "redeemable" check in that. If ETH's impl. calls (*rpcclient).isRedeemable in addition to the confirmation checks (perhaps just when >0 confs), the return from SwapConfirmations should reflect its findings. Off the top of my head, a couple options are 1) a new return bool, which would likely just be true for utxo assets, 2) force confs to 0 if isRedeemable says no, or 3) if confs are >0 but isRedeemable says no, maybe return an error since that would be the indicator of an exploit attempt.

Background for why call data + confirmations is not sufficient to determine redeemability: #1274 (comment)

@chappjc
Copy link
Member

chappjc commented Nov 24, 2021

Or, um, I guess isRedeemable can be used in Redeem just before actual broadcasting the secret key.

@martonp
Copy link
Contributor

martonp commented Nov 25, 2021

Regarding the CoinID to send during the Init request, I agree that we don't really need the Index field of the TxCoinID since we are also sending the secretHash in the Contract field, but I think it would be better to maintain a set of ETH coin IDs and actually use those when sending coin IDs. A coin ID should represent a specific amount of ETH, and without the Index field, the TxCoinID doesn't really do this. Even though it's a bit of extraneous information, it's still worth sending the entire coin ID over. Otherwise we'll have a set of coin ids, but the coin id that we are sending in a message doesn't deserialize to any of them, which is kind of confusing.

@martonp
Copy link
Contributor

martonp commented Nov 26, 2021

I'll do AuditContract next.

@martonp
Copy link
Contributor

martonp commented Dec 3, 2021

I'll do Refund next.

@JoeGruffins
Copy link
Member Author

I guess I'll take a whack at the Withdrawal TODOs since they are still there and probably not related to other's work.

@buck54321
Copy link
Member

buck54321 commented Dec 7, 2021

I'm working on (*Driver).Exists (#1332)

@buck54321
Copy link
Member

buck54321 commented Dec 7, 2021

I'll do LocktimeExpired (#1333)

@buck54321
Copy link
Member

buck54321 commented Dec 7, 2021

I'll work on FindRedemption. (#1334)

@JoeGruffins
Copy link
Member Author

I guess I'll do PayFee for completion.

@JoeGruffins
Copy link
Member Author

I guess I'll do the server's ValidateSignature.

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 a pull request may close this issue.

4 participants